@flytedesk/app-kit 12.8.0 → 12.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/sql-guard/errors.d.ts +2 -0
- package/dist/sql-guard/errors.js +4 -0
- package/dist/sql-guard/errors.js.map +1 -1
- package/dist/sql-guard/guard.js +17 -3
- package/dist/sql-guard/guard.js.map +1 -1
- package/dist/sql-guard/index.d.ts +12 -3
- package/dist/sql-guard/index.js +12 -3
- package/dist/sql-guard/index.js.map +1 -1
- package/dist/sql-guard/mysql.js +62 -25
- package/dist/sql-guard/mysql.js.map +1 -1
- package/dist/sql-guard/postgres.js +65 -12
- package/dist/sql-guard/postgres.js.map +1 -1
- package/dist/sql-guard/run.d.ts +10 -3
- package/dist/sql-guard/run.js +24 -7
- package/dist/sql-guard/run.js.map +1 -1
- package/dist/sql-guard/walk.d.ts +1 -0
- package/dist/sql-guard/walk.js +3 -0
- package/dist/sql-guard/walk.js.map +1 -1
- package/package.json +1 -1
|
@@ -4,3 +4,5 @@ export declare class SqlRefusedError extends Error {
|
|
|
4
4
|
readonly reason: SqlRefusalReason;
|
|
5
5
|
constructor(reason: SqlRefusalReason, message: string);
|
|
6
6
|
}
|
|
7
|
+
/** A table reference whose shape the guard does not understand: it cannot be checked against the allowlist, so the statement is refused. */
|
|
8
|
+
export declare function unresolvableTable(dialectName: string, detail: string): SqlRefusedError;
|
package/dist/sql-guard/errors.js
CHANGED
|
@@ -6,4 +6,8 @@ export class SqlRefusedError extends Error {
|
|
|
6
6
|
this.name = "SqlRefusedError";
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
+
/** A table reference whose shape the guard does not understand: it cannot be checked against the allowlist, so the statement is refused. */
|
|
10
|
+
export function unresolvableTable(dialectName, detail) {
|
|
11
|
+
return new SqlRefusedError("unparseable", `Refused: the statement has a ${dialectName} table reference the guard cannot resolve (${detail})`);
|
|
12
|
+
}
|
|
9
13
|
//# sourceMappingURL=errors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/sql-guard/errors.ts"],"names":[],"mappings":"AAWA,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAE7B;IADX,YACW,MAAwB,EACjC,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAC;QAHN,WAAM,GAAN,MAAM,CAAkB;QAIjC,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF"}
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/sql-guard/errors.ts"],"names":[],"mappings":"AAWA,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAE7B;IADX,YACW,MAAwB,EACjC,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAC;QAHN,WAAM,GAAN,MAAM,CAAkB;QAIjC,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AAED,4IAA4I;AAC5I,MAAM,UAAU,iBAAiB,CAAC,WAAmB,EAAE,MAAc;IACnE,OAAO,IAAI,eAAe,CACxB,aAAa,EACb,gCAAgC,WAAW,8CAA8C,MAAM,GAAG,CACnG,CAAC;AACJ,CAAC"}
|
package/dist/sql-guard/guard.js
CHANGED
|
@@ -34,13 +34,27 @@ export class GuardedSql {
|
|
|
34
34
|
}
|
|
35
35
|
// MySQL and MariaDB run the body of a slash-star-bang comment (and the MariaDB M-bang form) as SQL, while a parser reads it as a comment.
|
|
36
36
|
const EXECUTABLE_COMMENT = /\/\*\s*M?!/i;
|
|
37
|
+
/**
|
|
38
|
+
* Fail closed: an analysis that throws anything but a refusal (a parser output of a shape its walk
|
|
39
|
+
* did not expect) is a statement the guard could not verify, so it is refused, never allowed.
|
|
40
|
+
*/
|
|
41
|
+
function analyze(sql, options) {
|
|
42
|
+
try {
|
|
43
|
+
return options.dialect === "mysql"
|
|
44
|
+
? analyzeMysql(sql, options.defaultSchema)
|
|
45
|
+
: analyzePostgres(sql, options.defaultSchema);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
if (error instanceof SqlRefusedError)
|
|
49
|
+
throw error;
|
|
50
|
+
throw new SqlRefusedError("unparseable", `Refused: the guard could not analyse the statement (${error instanceof Error ? error.message.split("\n")[0] : String(error)})`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
37
53
|
export function guardSql(sql, options) {
|
|
38
54
|
if (options.dialect === "mysql" && EXECUTABLE_COMMENT.test(sql)) {
|
|
39
55
|
throw new SqlRefusedError("executable_comment", "Refused: a /*! ... */ comment is executed by MySQL, so it can hide a statement from the guard");
|
|
40
56
|
}
|
|
41
|
-
const { tables } = options
|
|
42
|
-
? analyzeMysql(sql, options.defaultSchema)
|
|
43
|
-
: analyzePostgres(sql, options.defaultSchema);
|
|
57
|
+
const { tables } = analyze(sql, options);
|
|
44
58
|
const unique = [...new Set(tables)].sort();
|
|
45
59
|
const disallowed = unique.filter((name) => !options.allowedTables.has(name));
|
|
46
60
|
if (disallowed.length > 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guard.js","sourceRoot":"","sources":["../../src/sql-guard/guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAkBhD;;;GAGG;AACH,MAAM,OAAO,UAAU;IAGV;IACA;IACA;IAJF,SAAS,GAAG,IAAI,CAAC;IAC1B,YACW,GAAW,EACX,OAAmB,EACnB,MAAyB;QAFzB,QAAG,GAAH,GAAG,CAAQ;QACX,YAAO,GAAP,OAAO,CAAY;QACnB,WAAM,GAAN,MAAM,CAAmB;IACjC,CAAC;IACJ,MAAM,CAAC,MAAM,CAAC,GAAW,EAAE,OAAmB,EAAE,MAAyB;QACvE,OAAO,IAAI,UAAU,CA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
17
17
|
* MySQL is the same with `dialect: "mysql"`, `defaultSchema` the database name, and
|
|
18
18
|
* `runReadOnlyMysql(mysql2Connection, ...)`.
|
|
19
19
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
20
|
+
* Every table named anywhere in the statement (nested and parenthesised joins, derived tables, CTEs,
|
|
21
|
+
* subqueries in any clause, UNION branches, function arguments) is checked against `allowedTables`
|
|
22
|
+
* exactly as written, system schemas included; a table reference of a shape the guard cannot resolve
|
|
23
|
+
* is refused.
|
|
24
|
+
*
|
|
25
|
+
* Limits: the guard refuses what its parsers cannot read (Postgres `TABLESAMPLE`, `INTERSECT`,
|
|
26
|
+
* `SELECT ... INTO` and parenthesised joins are among them), and a connection should also be a
|
|
27
|
+
* database role that can only read; the read-only transaction is a second layer, not a substitute.
|
|
28
|
+
* Unqualified names resolve in `defaultSchema`, so the connection's search_path (Postgres) or default
|
|
29
|
+
* database (MySQL) must be that schema. A Postgres function outside `pg_catalog` is refused when
|
|
30
|
+
* schema-qualified; an unqualified user-defined function is not resolved, so the role must not be
|
|
31
|
+
* able to run one that reads tables outside the allowlist.
|
|
23
32
|
*/
|
|
24
33
|
export { guardSql, GuardedSql } from "./guard.js";
|
|
25
34
|
export type { GuardSqlOptions, SqlDialect } from "./guard.js";
|
package/dist/sql-guard/index.js
CHANGED
|
@@ -17,9 +17,18 @@
|
|
|
17
17
|
* MySQL is the same with `dialect: "mysql"`, `defaultSchema` the database name, and
|
|
18
18
|
* `runReadOnlyMysql(mysql2Connection, ...)`.
|
|
19
19
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
20
|
+
* Every table named anywhere in the statement (nested and parenthesised joins, derived tables, CTEs,
|
|
21
|
+
* subqueries in any clause, UNION branches, function arguments) is checked against `allowedTables`
|
|
22
|
+
* exactly as written, system schemas included; a table reference of a shape the guard cannot resolve
|
|
23
|
+
* is refused.
|
|
24
|
+
*
|
|
25
|
+
* Limits: the guard refuses what its parsers cannot read (Postgres `TABLESAMPLE`, `INTERSECT`,
|
|
26
|
+
* `SELECT ... INTO` and parenthesised joins are among them), and a connection should also be a
|
|
27
|
+
* database role that can only read; the read-only transaction is a second layer, not a substitute.
|
|
28
|
+
* Unqualified names resolve in `defaultSchema`, so the connection's search_path (Postgres) or default
|
|
29
|
+
* database (MySQL) must be that schema. A Postgres function outside `pg_catalog` is refused when
|
|
30
|
+
* schema-qualified; an unqualified user-defined function is not resolved, so the role must not be
|
|
31
|
+
* able to run one that reads tables outside the allowlist.
|
|
23
32
|
*/
|
|
24
33
|
export { guardSql, GuardedSql } from "./guard.js";
|
|
25
34
|
export { SqlRefusedError } from "./errors.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sql-guard/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sql-guard/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/sql-guard/mysql.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
// node-sql-parser is a CommonJS bundle: Node ESM exposes only its default (module.exports), never `Parser` by name.
|
|
2
|
+
import nodeSqlParser from "node-sql-parser";
|
|
3
|
+
import { SqlRefusedError, unresolvableTable } from "./errors.js";
|
|
4
|
+
import { isRecord, walkNodes } from "./walk.js";
|
|
5
|
+
const parser = new nodeSqlParser.Parser();
|
|
5
6
|
/** Functions that sleep, read the server's files, take locks or run commands. */
|
|
6
7
|
const FORBIDDEN_FUNCTION = new Set([
|
|
7
8
|
"sleep",
|
|
@@ -90,39 +91,75 @@ export function analyzeMysql(sql, defaultSchema) {
|
|
|
90
91
|
});
|
|
91
92
|
return { tables };
|
|
92
93
|
}
|
|
93
|
-
/**
|
|
94
|
+
/**
|
|
95
|
+
* Collects every real table under `node`, wherever the parser put it: a FROM list, a parenthesised
|
|
96
|
+
* (nested) join, a derived table, a CTE body, or a subquery in any clause. A `WITH` name hides a
|
|
97
|
+
* table of the same name only inside what it scopes: a CTE body sees the CTEs defined before it
|
|
98
|
+
* (itself too when RECURSIVE), the main query sees them all.
|
|
99
|
+
*
|
|
100
|
+
* AK-57: it walks the whole AST rather than named keys, because a parenthesised join nests its
|
|
101
|
+
* tables under `expr` arrays. A FROM item of a shape it does not know throws, so an unforeseen
|
|
102
|
+
* parser output is refused, never waved through.
|
|
103
|
+
*/
|
|
94
104
|
function collectTables(node, ctes, defaultSchema, out) {
|
|
95
105
|
if (Array.isArray(node)) {
|
|
96
106
|
for (const item of node)
|
|
97
107
|
collectTables(item, ctes, defaultSchema, out);
|
|
98
108
|
return;
|
|
99
109
|
}
|
|
100
|
-
if (
|
|
110
|
+
if (!isRecord(node))
|
|
101
111
|
return;
|
|
102
|
-
const record = node;
|
|
103
112
|
let visible = ctes;
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
defined
|
|
113
|
+
const isSelect = node.type === "select";
|
|
114
|
+
if (isSelect) {
|
|
115
|
+
assertResolvableFrom(node.from);
|
|
116
|
+
if (Array.isArray(node.with)) {
|
|
117
|
+
const recursive = node.with.some((cte) => cte.recursive === true);
|
|
118
|
+
const defined = new Set(ctes);
|
|
119
|
+
for (const cte of node.with) {
|
|
120
|
+
collectTables(cte.stmt, recursive ? new Set([...defined, cte.name.value]) : defined, defaultSchema, out);
|
|
121
|
+
defined.add(cte.name.value);
|
|
122
|
+
}
|
|
123
|
+
visible = defined;
|
|
110
124
|
}
|
|
111
|
-
visible = defined;
|
|
112
125
|
}
|
|
113
|
-
|
|
114
|
-
|
|
126
|
+
if (typeof node.table === "string" && node.type === undefined) {
|
|
127
|
+
const db = node.db ?? null;
|
|
128
|
+
if (db !== null && typeof db !== "string")
|
|
129
|
+
throw unresolvableTable("MySQL", "its database name is not a plain name");
|
|
130
|
+
if (db !== null || !visible.has(node.table))
|
|
131
|
+
out.push(`${db ?? defaultSchema}.${node.table}`);
|
|
132
|
+
}
|
|
133
|
+
else if (node.table != null && typeof node.table !== "string" && node.type !== "column_ref") {
|
|
134
|
+
throw unresolvableTable("MySQL", "its table name is not a plain name");
|
|
135
|
+
}
|
|
136
|
+
for (const [key, value] of Object.entries(node)) {
|
|
137
|
+
if (isSelect && key === "with" && Array.isArray(value))
|
|
115
138
|
continue;
|
|
116
|
-
if (key === "from" && Array.isArray(value)) {
|
|
117
|
-
for (const item of value) {
|
|
118
|
-
if (typeof item.table === "string") {
|
|
119
|
-
if (item.db != null || !visible.has(item.table)) {
|
|
120
|
-
out.push(`${item.db ?? defaultSchema}.${item.table}`);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
139
|
collectTables(value, visible, defaultSchema, out);
|
|
126
140
|
}
|
|
127
141
|
}
|
|
142
|
+
/** A FROM clause is a list of items, or one parenthesised group; each item is a table, DUAL, a derived table, or a nested group of items. */
|
|
143
|
+
function assertResolvableFrom(from) {
|
|
144
|
+
if (from === null || from === undefined)
|
|
145
|
+
return;
|
|
146
|
+
for (const item of Array.isArray(from) ? from : [from])
|
|
147
|
+
assertResolvableFromItem(item);
|
|
148
|
+
}
|
|
149
|
+
function assertResolvableFromItem(item) {
|
|
150
|
+
if (!isRecord(item))
|
|
151
|
+
throw unresolvableTable("MySQL", "a FROM item is not an object");
|
|
152
|
+
if (typeof item.table === "string" && item.type === undefined)
|
|
153
|
+
return;
|
|
154
|
+
if (item.type === "dual")
|
|
155
|
+
return;
|
|
156
|
+
if (Array.isArray(item.expr)) {
|
|
157
|
+
for (const nested of item.expr)
|
|
158
|
+
assertResolvableFromItem(nested);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (isRecord(item.expr) && (isRecord(item.expr.ast) || item.expr.type === "values"))
|
|
162
|
+
return;
|
|
163
|
+
throw unresolvableTable("MySQL", "an unknown FROM item shape");
|
|
164
|
+
}
|
|
128
165
|
//# sourceMappingURL=mysql.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mysql.js","sourceRoot":"","sources":["../../src/sql-guard/mysql.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"mysql.js","sourceRoot":"","sources":["../../src/sql-guard/mysql.ts"],"names":[],"mappings":"AAAA,oHAAoH;AACpH,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEjE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEhD,MAAM,MAAM,GAAG,IAAI,aAAa,CAAC,MAAM,EAAE,CAAC;AAE1C,iFAAiF;AACjF,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC;IACjC,OAAO;IACP,WAAW;IACX,WAAW;IACX,UAAU;IACV,cAAc;IACd,mBAAmB;IACnB,iBAAiB;IACjB,iBAAiB;IACjB,4BAA4B;IAC5B,mCAAmC;IACnC,UAAU;IACV,UAAU;IACV,SAAS;IACT,SAAS;IACT,aAAa;CACd,CAAC,CAAC;AAEH,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC;IAC5B,QAAQ;IACR,SAAS;IACT,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,MAAM;IACN,OAAO;IACP,UAAU;IACV,QAAQ;IACR,KAAK;IACL,MAAM;IACN,KAAK;IACL,MAAM;IACN,QAAQ;IACR,MAAM;IACN,OAAO;IACP,WAAW;IACX,aAAa;IACb,MAAM;IACN,SAAS;IACT,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,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAAE,wBAAwB,CAAC,IAAI,CAAC,CAAC;AACzF,CAAC;AAED,SAAS,wBAAwB,CAAC,IAAa;IAC7C,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;QAAE,MAAM,iBAAiB,CAAC,OAAO,EAAE,8BAA8B,CAAC,CAAC;IACtF,IAAI,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS;QAAE,OAAO;IACtE,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM;QAAE,OAAO;IACjC,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAC7B,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,IAAI;YAAE,wBAAwB,CAAC,MAAM,CAAC,CAAC;QACjE,OAAO;IACT,CAAC;IACD,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC;QAAE,OAAO;IAC5F,MAAM,iBAAiB,CAAC,OAAO,EAAE,4BAA4B,CAAC,CAAC;AACjE,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { parse } from "pgsql-ast-parser";
|
|
2
|
-
import { SqlRefusedError } from "./errors.js";
|
|
3
|
-
import { walkNodes } from "./walk.js";
|
|
2
|
+
import { SqlRefusedError, unresolvableTable } from "./errors.js";
|
|
3
|
+
import { isRecord, walkNodes } from "./walk.js";
|
|
4
4
|
const READ_TOP_LEVEL = new Set(["select", "union", "union all", "with", "with recursive"]);
|
|
5
|
+
const FROM_ITEM_TYPES = new Set(["table", "statement", "call"]);
|
|
5
6
|
/** Statement kinds that write or change state; one anywhere (a `WITH d AS (DELETE ...)`) is refused. */
|
|
6
7
|
const WRITING_NODES = new Set([
|
|
7
8
|
"insert",
|
|
@@ -43,8 +44,18 @@ const WRITING_NODES = new Set([
|
|
|
43
44
|
"raise",
|
|
44
45
|
"refresh materialized view",
|
|
45
46
|
]);
|
|
46
|
-
/**
|
|
47
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Functions that sleep, read the server's files, take locks, change settings or sequences, run SQL
|
|
49
|
+
* text the guard cannot see, or take a table by name (a string the guard cannot tie to the allowlist).
|
|
50
|
+
*/
|
|
51
|
+
const FORBIDDEN_FUNCTION = /^(lo_|dblink|set_config|nextval|setval|currval|lastval|query_to_xml|cursor_to_xml|table_to_xml|schema_to_xml|database_to_xml|ts_debug|ts_stat|xmlquery|to_reg|has_(any_column|column|database|foreign_data_wrapper|function|language|parameter|schema|sequence|server|table|tablespace|type)_privilege|obj_description|col_description|shobj_description|_pg_)/;
|
|
52
|
+
/**
|
|
53
|
+
* Every `pg_*` function is a system function (sleep, file reads, locks, size and definition of a
|
|
54
|
+
* relation given by name, backend control), so each is refused except these, which read only their argument.
|
|
55
|
+
*/
|
|
56
|
+
const SAFE_PG_FUNCTION = new Set(["pg_typeof", "pg_size_pretty", "pg_column_size"]);
|
|
57
|
+
/** Casts to these types resolve a table, function or role by the name in a string. */
|
|
58
|
+
const NAME_RESOLVING_TYPE = /^reg(class|proc|procedure|oper|operator|type|namespace|role|config|dictionary|collation)$/;
|
|
48
59
|
function unsupportedParse(error) {
|
|
49
60
|
const firstLine = error instanceof Error ? error.message.split("\n")[0] : String(error);
|
|
50
61
|
return new SqlRefusedError("unparseable", `Refused: not a PostgreSQL SELECT the guard can verify (${firstLine})`);
|
|
@@ -77,9 +88,15 @@ export function analyzePostgres(sql, defaultSchema) {
|
|
|
77
88
|
if (type === "call") {
|
|
78
89
|
const fn = node.function;
|
|
79
90
|
const name = (fn?.name ?? "").toLowerCase();
|
|
80
|
-
if (FORBIDDEN_FUNCTION.test(name)) {
|
|
91
|
+
if (FORBIDDEN_FUNCTION.test(name) || (name.startsWith("pg_") && !SAFE_PG_FUNCTION.has(name))) {
|
|
81
92
|
throw new SqlRefusedError("forbidden_function", `Refused: the function ${name}() is not allowed`);
|
|
82
93
|
}
|
|
94
|
+
if (fn?.schema !== undefined && fn.schema.toLowerCase() !== "pg_catalog") {
|
|
95
|
+
throw new SqlRefusedError("forbidden_function", `Refused: ${fn.schema}.${name}() is a function outside pg_catalog, and the guard cannot see which tables it reads`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (type === "cast" && NAME_RESOLVING_TYPE.test(castTypeName(node.to))) {
|
|
99
|
+
throw new SqlRefusedError("forbidden_function", `Refused: a cast to ${castTypeName(node.to)} looks a name up in the catalogs`);
|
|
83
100
|
}
|
|
84
101
|
});
|
|
85
102
|
return { tables };
|
|
@@ -97,25 +114,61 @@ function collectTables(node, ctes, defaultSchema, out) {
|
|
|
97
114
|
if (typeof node !== "object" || node === null)
|
|
98
115
|
return;
|
|
99
116
|
const record = node;
|
|
100
|
-
if (record.type === "with"
|
|
101
|
-
|
|
117
|
+
if (record.type === "with") {
|
|
118
|
+
if (!Array.isArray(record.bind))
|
|
119
|
+
throw unresolvableTable("PostgreSQL", "a WITH list that is not a list");
|
|
102
120
|
const visible = new Set(ctes);
|
|
103
121
|
for (const bind of record.bind) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
visible.add(name);
|
|
122
|
+
collectTables(bind.statement, visible, defaultSchema, out);
|
|
123
|
+
visible.add(bind.alias.name);
|
|
107
124
|
}
|
|
108
125
|
collectTables(record.in, visible, defaultSchema, out);
|
|
109
126
|
return;
|
|
110
127
|
}
|
|
128
|
+
if (record.type === "with recursive") {
|
|
129
|
+
// The parser reads one recursive CTE, whose name is visible in its own body and in the main query.
|
|
130
|
+
const alias = record.alias;
|
|
131
|
+
if (!isRecord(alias) || typeof alias.name !== "string")
|
|
132
|
+
throw unresolvableTable("PostgreSQL", "a recursive CTE without a name");
|
|
133
|
+
const visible = new Set([...ctes, alias.name]);
|
|
134
|
+
collectTables(record.bind, visible, defaultSchema, out);
|
|
135
|
+
collectTables(record.in, visible, defaultSchema, out);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
111
138
|
if (record.type === "table") {
|
|
112
139
|
const name = record.name;
|
|
140
|
+
if (!isRecord(name) || typeof name.name !== "string" || (name.schema !== undefined && typeof name.schema !== "string")) {
|
|
141
|
+
throw unresolvableTable("PostgreSQL", "its name is not a plain, optionally schema-qualified name");
|
|
142
|
+
}
|
|
113
143
|
if (name.schema !== undefined || !ctes.has(name.name)) {
|
|
114
144
|
out.push(`${name.schema ?? defaultSchema}.${name.name}`);
|
|
115
145
|
}
|
|
116
|
-
return;
|
|
117
146
|
}
|
|
118
|
-
|
|
147
|
+
if (record.type === "select")
|
|
148
|
+
assertResolvableFrom(record.from);
|
|
149
|
+
// A FROM item that is a table still carries its `join` (ON and USING hold subqueries), so it is walked on.
|
|
150
|
+
for (const [key, value] of Object.entries(record)) {
|
|
151
|
+
if (record.type === "table" && key === "name")
|
|
152
|
+
continue;
|
|
119
153
|
collectTables(value, ctes, defaultSchema, out);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/** Each FROM item is a table, a derived table (a parenthesised statement) or a function call; anything else is a shape the guard cannot check. */
|
|
157
|
+
function assertResolvableFrom(from) {
|
|
158
|
+
if (from === undefined || from === null)
|
|
159
|
+
return;
|
|
160
|
+
if (!Array.isArray(from))
|
|
161
|
+
throw unresolvableTable("PostgreSQL", "a FROM clause that is not a list");
|
|
162
|
+
for (const item of from) {
|
|
163
|
+
if (!isRecord(item) || !FROM_ITEM_TYPES.has(String(item.type))) {
|
|
164
|
+
throw unresolvableTable("PostgreSQL", `an unknown FROM item ${isRecord(item) ? String(item.type) : "shape"}`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
function castTypeName(to) {
|
|
169
|
+
let type = to;
|
|
170
|
+
while (isRecord(type) && type.kind === "array")
|
|
171
|
+
type = type.arrayOf;
|
|
172
|
+
return isRecord(type) && typeof type.name === "string" ? type.name.toLowerCase() : "";
|
|
120
173
|
}
|
|
121
174
|
//# sourceMappingURL=postgres.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres.js","sourceRoot":"","sources":["../../src/sql-guard/postgres.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"postgres.js","sourceRoot":"","sources":["../../src/sql-guard/postgres.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEjE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEhD,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC;AAE3F,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;AAEhE,wGAAwG;AACxG,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC;IAC5B,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,UAAU;IACV,cAAc;IACd,cAAc;IACd,aAAa;IACb,0BAA0B;IAC1B,kBAAkB;IAClB,iBAAiB;IACjB,eAAe;IACf,aAAa;IACb,uBAAuB;IACvB,iBAAiB;IACjB,YAAY;IACZ,YAAY;IACZ,eAAe;IACf,WAAW;IACX,WAAW;IACX,eAAe;IACf,gBAAgB;IAChB,aAAa;IACb,aAAa;IACb,gBAAgB;IAChB,KAAK;IACL,MAAM;IACN,OAAO;IACP,QAAQ;IACR,UAAU;I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EAAW;IAC/B,IAAI,IAAI,GAAG,EAAE,CAAC;IACd,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO;QAAE,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC;IACpE,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AACxF,CAAC"}
|
package/dist/sql-guard/run.d.ts
CHANGED
|
@@ -25,14 +25,21 @@ export interface MysqlConnectionLike {
|
|
|
25
25
|
query(sql: string): Promise<[unknown, unknown]>;
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
|
-
* Postgres: `BEGIN READ ONLY`, `SET LOCAL statement_timeout`, then the
|
|
29
|
-
* cursor from which `maxRows + 1` rows are fetched, so the cap needs no rewrite
|
|
30
|
-
* Always rolled back.
|
|
28
|
+
* Postgres: `BEGIN READ ONLY`, `SET LOCAL statement_timeout` and `standard_conforming_strings`, then the
|
|
29
|
+
* statement as a `NO SCROLL` cursor from which `maxRows + 1` rows are fetched, so the cap needs no rewrite
|
|
30
|
+
* of the SQL. Always rolled back.
|
|
31
|
+
*
|
|
32
|
+
* AK-57: `standard_conforming_strings = on` is pinned because the guard's parser reads a quote closed by a
|
|
33
|
+
* backslash as a complete string; a server with it off reads a backslash as an escape and sees a different statement.
|
|
31
34
|
*/
|
|
32
35
|
export declare function runReadOnlyPostgres<Row = Record<string, unknown>>(client: PostgresClientLike, statement: GuardedSql, options: ReadOnlyRunOptions): Promise<ReadOnlyResult<Row>>;
|
|
33
36
|
/**
|
|
34
37
|
* MySQL: `START TRANSACTION READ ONLY` with the session's `max_execution_time` and
|
|
35
38
|
* `sql_select_limit` (the row cap, `maxRows + 1`, applied by the server to the top-level SELECT)
|
|
36
39
|
* set for the call and put back after it. Always rolled back.
|
|
40
|
+
*
|
|
41
|
+
* AK-57: the session's `sql_mode` is held without NO_BACKSLASH_ESCAPES and ANSI_QUOTES for the call,
|
|
42
|
+
* because the guard's parser reads a backslash as an escape and a double quote as a string; a server
|
|
43
|
+
* in either mode would read the same text as a different statement.
|
|
37
44
|
*/
|
|
38
45
|
export declare function runReadOnlyMysql<Row = Record<string, unknown>>(connection: MysqlConnectionLike, statement: GuardedSql, options: ReadOnlyRunOptions): Promise<ReadOnlyResult<Row>>;
|
package/dist/sql-guard/run.js
CHANGED
|
@@ -20,9 +20,12 @@ function requireGuarded(statement, dialect) {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
|
-
* Postgres: `BEGIN READ ONLY`, `SET LOCAL statement_timeout`, then the
|
|
24
|
-
* cursor from which `maxRows + 1` rows are fetched, so the cap needs no rewrite
|
|
25
|
-
* Always rolled back.
|
|
23
|
+
* Postgres: `BEGIN READ ONLY`, `SET LOCAL statement_timeout` and `standard_conforming_strings`, then the
|
|
24
|
+
* statement as a `NO SCROLL` cursor from which `maxRows + 1` rows are fetched, so the cap needs no rewrite
|
|
25
|
+
* of the SQL. Always rolled back.
|
|
26
|
+
*
|
|
27
|
+
* AK-57: `standard_conforming_strings = on` is pinned because the guard's parser reads a quote closed by a
|
|
28
|
+
* backslash as a complete string; a server with it off reads a backslash as an escape and sees a different statement.
|
|
26
29
|
*/
|
|
27
30
|
export async function runReadOnlyPostgres(client, statement, options) {
|
|
28
31
|
requireGuarded(statement, "postgres");
|
|
@@ -30,6 +33,7 @@ export async function runReadOnlyPostgres(client, statement, options) {
|
|
|
30
33
|
await client.query("BEGIN READ ONLY");
|
|
31
34
|
try {
|
|
32
35
|
await client.query(`SET LOCAL statement_timeout = ${options.timeoutMs}`);
|
|
36
|
+
await client.query("SET LOCAL standard_conforming_strings = on");
|
|
33
37
|
await client.query(`DECLARE guarded_rows NO SCROLL CURSOR FOR ${statement.sql}\n`);
|
|
34
38
|
const fetched = await client.query(`FETCH FORWARD ${options.maxRows + 1} FROM guarded_rows`);
|
|
35
39
|
return capped(fetched.rows, options.maxRows);
|
|
@@ -42,13 +46,21 @@ export async function runReadOnlyPostgres(client, statement, options) {
|
|
|
42
46
|
* MySQL: `START TRANSACTION READ ONLY` with the session's `max_execution_time` and
|
|
43
47
|
* `sql_select_limit` (the row cap, `maxRows + 1`, applied by the server to the top-level SELECT)
|
|
44
48
|
* set for the call and put back after it. Always rolled back.
|
|
49
|
+
*
|
|
50
|
+
* AK-57: the session's `sql_mode` is held without NO_BACKSLASH_ESCAPES and ANSI_QUOTES for the call,
|
|
51
|
+
* because the guard's parser reads a backslash as an escape and a double quote as a string; a server
|
|
52
|
+
* in either mode would read the same text as a different statement.
|
|
45
53
|
*/
|
|
46
54
|
export async function runReadOnlyMysql(connection, statement, options) {
|
|
47
55
|
requireGuarded(statement, "mysql");
|
|
48
56
|
validate(options);
|
|
49
|
-
const [before] = await connection.query("SELECT CAST(@@session.max_execution_time AS CHAR) AS t, CAST(@@session.sql_select_limit AS CHAR) AS l");
|
|
50
|
-
const { t, l } = before[0];
|
|
51
|
-
|
|
57
|
+
const [before] = await connection.query("SELECT CAST(@@session.max_execution_time AS CHAR) AS t, CAST(@@session.sql_select_limit AS CHAR) AS l, CAST(@@session.sql_mode AS CHAR) AS m");
|
|
58
|
+
const { t, l, m } = before[0];
|
|
59
|
+
const pinnedMode = m
|
|
60
|
+
.split(",")
|
|
61
|
+
.filter((mode) => !PARSER_DISAGREEING_SQL_MODES.has(mode.toUpperCase()))
|
|
62
|
+
.join(",");
|
|
63
|
+
await connection.query(`SET SESSION max_execution_time = ${options.timeoutMs}, sql_select_limit = ${options.maxRows + 1}, sql_mode = ${sqlString(pinnedMode)}`);
|
|
52
64
|
let outcome;
|
|
53
65
|
try {
|
|
54
66
|
await connection.query("START TRANSACTION READ ONLY");
|
|
@@ -64,12 +76,17 @@ export async function runReadOnlyMysql(connection, statement, options) {
|
|
|
64
76
|
await connection.query("ROLLBACK");
|
|
65
77
|
}
|
|
66
78
|
finally {
|
|
67
|
-
await connection.query(`SET SESSION max_execution_time = ${t}, sql_select_limit = ${l}`);
|
|
79
|
+
await connection.query(`SET SESSION max_execution_time = ${t}, sql_select_limit = ${l}, sql_mode = ${sqlString(m)}`);
|
|
68
80
|
}
|
|
69
81
|
if ("error" in outcome)
|
|
70
82
|
throw outcome.error;
|
|
71
83
|
return capped(outcome.rows, options.maxRows);
|
|
72
84
|
}
|
|
85
|
+
const PARSER_DISAGREEING_SQL_MODES = new Set(["NO_BACKSLASH_ESCAPES", "ANSI_QUOTES", "ANSI"]);
|
|
86
|
+
/** A server-reported value (a list of upper-case words) as a SQL string literal. */
|
|
87
|
+
function sqlString(value) {
|
|
88
|
+
return `'${value.replaceAll("'", "''")}'`;
|
|
89
|
+
}
|
|
73
90
|
function capped(rows, maxRows) {
|
|
74
91
|
return rows.length > maxRows
|
|
75
92
|
? { rows: rows.slice(0, maxRows), truncated: true }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.js","sourceRoot":"","sources":["../../src/sql-guard/run.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAuBxC,SAAS,QAAQ,CAAC,EAAE,SAAS,EAAE,OAAO,EAAsB;IAC1D,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,SAAS,CAAC,EAAE,CAAC,SAAS,EAAE,OAAO,CAAC,CAAU,EAAE,CAAC;QACtF,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;YAC/C,MAAM,IAAI,UAAU,CAAC,GAAG,IAAI,oCAAoC,KAAK,EAAE,CAAC,CAAC;QAC3E,CAAC;IACH,CAAC;AACH,CAAC;AAED,SAAS,cAAc,CAAC,SAAqB,EAAE,OAA8B;IAC3E,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC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AI,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE;QACnD,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;AACjC,CAAC"}
|
package/dist/sql-guard/walk.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
/** Calls `visit` on every plain object reachable from a parsed AST (arrays and nested objects included). */
|
|
2
2
|
export declare function walkNodes(root: unknown, visit: (node: Record<string, unknown>) => void): void;
|
|
3
|
+
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
package/dist/sql-guard/walk.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"walk.js","sourceRoot":"","sources":["../../src/sql-guard/walk.ts"],"names":[],"mappings":"AAAA,4GAA4G;AAC5G,MAAM,UAAU,SAAS,CAAC,IAAa,EAAE,KAA8C;IACrF,MAAM,KAAK,GAAc,CAAC,IAAI,CAAC,CAAC;IAChC,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC;QAC1B,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC;QACvB,CAAC;aAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YACvD,MAAM,IAAI,GAAG,KAAgC,CAAC;YAC9C,KAAK,CAAC,IAAI,CAAC,CAAC;YACZ,KAAK,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;QACrC,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
1
|
+
{"version":3,"file":"walk.js","sourceRoot":"","sources":["../../src/sql-guard/walk.ts"],"names":[],"mappings":"AAAA,4GAA4G;AAC5G,MAAM,UAAU,S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