@rebasepro/rls-check 0.30.1 → 0.31.0-canary.g59cd6fd
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/README.md +8 -8
- package/dist/checks/util.d.ts +4 -4
- package/dist/cli.d.ts +1 -1
- package/dist/index.es.js +38 -39
- package/dist/index.es.js.map +1 -1
- package/dist/remediation.d.ts +7 -6
- package/dist/report-agent.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -180,7 +180,7 @@ npx @rebasepro/rls-check [connection-string] [options]
|
|
|
180
180
|
--format <name> text (default), json (the same as --json) or agent: one JSON
|
|
181
181
|
document for a coding agent, where every finding carries the
|
|
182
182
|
failing table and policy, the SQL that fixes it and the
|
|
183
|
-
equivalent Rebase
|
|
183
|
+
equivalent rules for a Rebase table's rls. See "Agent output" below.
|
|
184
184
|
--html <path> Also write a self-contained HTML report to <path>. One file,
|
|
185
185
|
no network requests, safe to attach to a ticket.
|
|
186
186
|
--schema <name> Restrict the scan to a schema. Repeatable or comma-separated.
|
|
@@ -258,7 +258,7 @@ To keep the machine-readable result as an artifact:
|
|
|
258
258
|
|
|
259
259
|
### On a Rebase database, change the rule, not the policy
|
|
260
260
|
|
|
261
|
-
Every policy on a Rebase deployment is compiled from a
|
|
261
|
+
Every policy on a Rebase deployment is compiled from a table's `rls` (a `defineTable` in `backend/schema/`), and the runtime re-applies them on every boot — it drops each generated policy and creates it again from the definition. SQL run against one of them survives exactly until the next restart, so `rls-check` recognises those policies (a `<table>_<operation>_<hash>` name, or a call to `rebase.uid()` / `rebase.roles()` in the expression) and prescribes the rule instead: edit the table's `rls` under `backend/schema/`, or `defaultRls` in `backend/schema/index.ts` when the table says `rls: "inherit"`, then redeploy. A policy you wrote by hand in a migration is untouched by this, and its fix is still the SQL.
|
|
262
262
|
|
|
263
263
|
A stock Rebase scaffold reports three `policy-always-true` criticals on its first scan — `posts`, `authors` and `tags` inherit a `{ operation: "select", access: "public" }` rule — so decide whether to replace those rules or to `--skip policy-always-true` before you make this a gate.
|
|
264
264
|
|
|
@@ -368,9 +368,9 @@ Every finding names the check id (one of the fifteen `--list-checks` prints) and
|
|
|
368
368
|
"caveats": ["With row-level security on, every role that neither owns the table nor holds BYPASSRLS sees only the rows a policy admits — …"],
|
|
369
369
|
"rebase": {
|
|
370
370
|
"applicable": true,
|
|
371
|
-
"
|
|
372
|
-
"snippet": "
|
|
373
|
-
"note": "Rebase enables row-level security on every
|
|
371
|
+
"rls": "[\n { operation: \"all\", ownerField: \"user_id\" }\n]",
|
|
372
|
+
"snippet": "defineTable(\"todos\", {\n // …columns, relations and the rest stay as they are…\n rls: [ … ]\n});",
|
|
373
|
+
"note": "Rebase enables row-level security on every table it declares and compiles each rule into a policy … `ownerField` compiles to `<column>::text = rebase.uid()` …"
|
|
374
374
|
}
|
|
375
375
|
}
|
|
376
376
|
}
|
|
@@ -378,13 +378,13 @@ Every finding names the check id (one of the fifteen `--list-checks` prints) and
|
|
|
378
378
|
|
|
379
379
|
What the fields promise:
|
|
380
380
|
|
|
381
|
-
- **`apply`** says where the fix belongs. `sql`: run `remediation.sql` as a migration. `rebase-config`: the policy is compiled by Rebase from a
|
|
381
|
+
- **`apply`** says where the fix belongs. `sql`: run `remediation.sql` as a migration. `rebase-config`: the policy is compiled by Rebase from a table's `rls` and re-made on every boot, so `sql` is `null` and the rule in `rebase.snippet` is what to change. `manual`: no statement can be written without a decision only a person can make, and `summary` names it.
|
|
382
382
|
- **`sql`** is statements only — no comments to interpret — and is written per check: the table's own owner column (compared as uuid or text, whichever its type allows), the grants that actually reach the exposed roles, the policy's own expression with only the flagged clause rewritten. Applying it clears the finding it is attached to; the test suite holds every check to that against a real PostgreSQL.
|
|
383
383
|
- **`placeholders`** lists the tokens the catalog cannot fill — `<owner_column>` on a table with no column that looks like an owner, `<app_role>` for the role your application connects as. Replace them before running `sql`.
|
|
384
384
|
- **`alternatives`** are fixes for a different intent ("nobody should reach this table at all"), not a second step.
|
|
385
|
-
- **`rebase`** is the same fix as `
|
|
385
|
+
- **`rebase`** is the same fix as `defineTable("todos", { rls: [...] })` in `backend/schema/`. The rules are type-checked against `SecurityRule` from `@rebasepro/types` in this package's tests. Where `rls` cannot express the fix — grants, views, functions, `FORCE` — `applicable` is `false`, the rules are `null`, and `note` says what Rebase does instead.
|
|
386
386
|
|
|
387
|
-
Around the findings, the document carries the verdict (`exitCode`, `reason`, `failOn`), `complete` (false when a catalogue read or a check failed), `notes` (the same caveats the text report prints, such as a role to name with `--role`), `diagnostics` and `howToApply`, a paragraph an agent can read as instructions. Every key is always present, with `null` for an absent object, and `formatVersion` changes only when a key is renamed or removed. `--json` is unchanged.
|
|
387
|
+
Around the findings, the document carries the verdict (`exitCode`, `reason`, `failOn`), `complete` (false when a catalogue read or a check failed), `notes` (the same caveats the text report prints, such as a role to name with `--role`), `diagnostics` and `howToApply`, a paragraph an agent can read as instructions. Every key is always present, with `null` for an absent object, and `formatVersion` changes only when a key is renamed or removed (2 since `rebase.securityRules` became `rebase.rls`). `--json` is unchanged.
|
|
388
388
|
|
|
389
389
|
## What this tool does not do
|
|
390
390
|
|
package/dist/checks/util.d.ts
CHANGED
|
@@ -135,12 +135,12 @@ export declare const listAnd: (items: string[]) => string;
|
|
|
135
135
|
*/
|
|
136
136
|
export declare function callerIdCall(snapshot: DbSnapshot): string;
|
|
137
137
|
/**
|
|
138
|
-
* Is this policy one Rebase derives from a
|
|
139
|
-
*
|
|
138
|
+
* Is this policy one Rebase derives from a table's `rls` and re-applies at
|
|
139
|
+
* every boot?
|
|
140
140
|
*
|
|
141
141
|
* It matters because the ordinary remediation — edit the policy in the database
|
|
142
142
|
* — is *silently undone* on such a policy: boot drops and recreates every
|
|
143
|
-
* generated policy from the
|
|
143
|
+
* generated policy from the table definitions, so a fix applied with SQL
|
|
144
144
|
* survives exactly until the next restart. Prescribing it is worse than
|
|
145
145
|
* prescribing nothing, because the operator watches the finding disappear and
|
|
146
146
|
* files it as done.
|
|
@@ -151,7 +151,7 @@ export declare function callerIdCall(snapshot: DbSnapshot): string;
|
|
|
151
151
|
*/
|
|
152
152
|
export declare function isRebaseManagedPolicy(snapshot: DbSnapshot, policy: DbPolicy): boolean;
|
|
153
153
|
/** Where the rule that produces a managed policy is documented. */
|
|
154
|
-
export declare const
|
|
154
|
+
export declare const RLS_DOCS = "https://rebase.pro/docs/collections/security-rules";
|
|
155
155
|
/**
|
|
156
156
|
* The remediation for a Rebase-managed policy: change the rule it is compiled
|
|
157
157
|
* from. `intent` is one clause saying what to change the rule to, in the
|
package/dist/cli.d.ts
CHANGED
|
@@ -93,7 +93,7 @@ export declare function buildScanResult(snapshot: DbSnapshot, findings: Finding[
|
|
|
93
93
|
/**
|
|
94
94
|
* What stdout carries. `text` is the report for a person; `json` is the
|
|
95
95
|
* {@link ScanResult} contract; `agent` is one JSON document with a remediation —
|
|
96
|
-
* SQL and the Rebase `
|
|
96
|
+
* SQL and the Rebase `rls` equivalent — on every finding, for a
|
|
97
97
|
* coding agent to apply.
|
|
98
98
|
*/
|
|
99
99
|
export declare const OUTPUT_FORMATS: readonly ["text", "json", "agent"];
|
package/dist/index.es.js
CHANGED
|
@@ -752,8 +752,8 @@ function callerIdCall(snapshot) {
|
|
|
752
752
|
/**
|
|
753
753
|
* The helper functions a Rebase deployment creates in its `rebase` schema, as
|
|
754
754
|
* they appear inside a policy expression. A call to one of these is the
|
|
755
|
-
* strongest single signal that the policy was compiled from a
|
|
756
|
-
*
|
|
755
|
+
* strongest single signal that the policy was compiled from a table's `rls`
|
|
756
|
+
* rather than written by hand.
|
|
757
757
|
*/
|
|
758
758
|
var REBASE_HELPER_CALL = /\brebase\.(uid|roles|jwt|is_anonymous)\s*\(/i;
|
|
759
759
|
/**
|
|
@@ -773,12 +773,12 @@ function hasGeneratedPolicyName(policy) {
|
|
|
773
773
|
return new RegExp(`^${table}_(select|insert|update|delete|all)_[0-9a-f]{7}(_\\d+)?$`).test(policy.name);
|
|
774
774
|
}
|
|
775
775
|
/**
|
|
776
|
-
* Is this policy one Rebase derives from a
|
|
777
|
-
*
|
|
776
|
+
* Is this policy one Rebase derives from a table's `rls` and re-applies at
|
|
777
|
+
* every boot?
|
|
778
778
|
*
|
|
779
779
|
* It matters because the ordinary remediation — edit the policy in the database
|
|
780
780
|
* — is *silently undone* on such a policy: boot drops and recreates every
|
|
781
|
-
* generated policy from the
|
|
781
|
+
* generated policy from the table definitions, so a fix applied with SQL
|
|
782
782
|
* survives exactly until the next restart. Prescribing it is worse than
|
|
783
783
|
* prescribing nothing, because the operator watches the finding disappear and
|
|
784
784
|
* files it as done.
|
|
@@ -794,7 +794,7 @@ function isRebaseManagedPolicy(snapshot, policy) {
|
|
|
794
794
|
return hasGeneratedPolicyName(policy);
|
|
795
795
|
}
|
|
796
796
|
/** Where the rule that produces a managed policy is documented. */
|
|
797
|
-
var
|
|
797
|
+
var RLS_DOCS = "https://rebase.pro/docs/collections/security-rules";
|
|
798
798
|
/**
|
|
799
799
|
* The remediation for a Rebase-managed policy: change the rule it is compiled
|
|
800
800
|
* from. `intent` is one clause saying what to change the rule to, in the
|
|
@@ -805,11 +805,11 @@ var SECURITY_RULES_DOCS = "https://rebase.pro/docs/collections/security-rules";
|
|
|
805
805
|
* on the next deploy teaches the wrong model of where access control lives.
|
|
806
806
|
*/
|
|
807
807
|
function managedPolicyFix(policy, intent) {
|
|
808
|
-
return `This policy is not hand-written: Rebase compiles it from the
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
1. find the
|
|
808
|
+
return `This policy is not hand-written: Rebase compiles it from the table's \`rls\`
|
|
809
|
+
and re-applies it (drop, then create) on every boot, so a change made to the
|
|
810
|
+
policy in the database is undone the next time the runtime starts. Change the
|
|
811
|
+
rule instead:
|
|
812
|
+
1. find the defineTable for ${qrel(policy.schema, policy.table)} — in a scaffold,\n under backend/schema/;\n 2. ${intent};\n 3. a table that says \`rls: "inherit"\` takes \`defaultRls\` from\n backend/schema/index.ts — a stock scaffold's unfiltered read rule lives\n there, not on the table;\n 4. redeploy (boot re-applies the policies), or run \`rebase db push\`.\n${RLS_DOCS}`;
|
|
813
813
|
}
|
|
814
814
|
//#endregion
|
|
815
815
|
//#region src/checks/anonymous-write-allowed.ts
|
|
@@ -4442,7 +4442,7 @@ function renderCheckCatalog(checks, options) {
|
|
|
4442
4442
|
//#region src/remediation.ts
|
|
4443
4443
|
/**
|
|
4444
4444
|
* Remediations for `--format agent`: for every finding, the SQL that fixes it
|
|
4445
|
-
* and the Rebase `
|
|
4445
|
+
* and the Rebase `rls` rules that say the same thing.
|
|
4446
4446
|
*
|
|
4447
4447
|
* The `fix` a check writes is for a person reading a terminal — prose, options
|
|
4448
4448
|
* and commented-out examples. A coding agent needs something else: one
|
|
@@ -4465,11 +4465,11 @@ function renderCheckCatalog(checks, options) {
|
|
|
4465
4465
|
*
|
|
4466
4466
|
* 3. The Rebase rules mean what the SQL means. `ownerField` compiles to
|
|
4467
4467
|
* `<column>::text = rebase.uid()`; a raw rule carries the corrected
|
|
4468
|
-
* expression. Where `
|
|
4468
|
+
* expression. Where a table's `rls` cannot express the fix at all — grants,
|
|
4469
4469
|
* views, functions, FORCE — `rebase.applicable` is false and the note says
|
|
4470
4470
|
* what Rebase does instead, rather than inventing a rule.
|
|
4471
4471
|
*
|
|
4472
|
-
* The TypeScript in `rebase.
|
|
4472
|
+
* The TypeScript in `rebase.rls` is type-checked against
|
|
4473
4473
|
* `SecurityRule` from `@rebasepro/types` by `remediation.test.ts`. This package
|
|
4474
4474
|
* cannot import that type — it ships with `pg` and nothing else — so the shapes
|
|
4475
4475
|
* written here are held to it by the test instead.
|
|
@@ -4492,29 +4492,28 @@ function ruleSource(rule) {
|
|
|
4492
4492
|
function rulesSource(rules, indent = "") {
|
|
4493
4493
|
return `[\n${rules.map((r) => `${indent} ${ruleSource(r)}`).join(",\n")}\n${indent}]`;
|
|
4494
4494
|
}
|
|
4495
|
-
function
|
|
4495
|
+
function tableSnippet(schema, table, rules) {
|
|
4496
4496
|
return [
|
|
4497
|
-
`// The
|
|
4498
|
-
`
|
|
4499
|
-
` // …
|
|
4500
|
-
` table: ${JSON.stringify(table)},`,
|
|
4497
|
+
`// The table definition for ${schema}.${table} (backend/schema/ in a Rebase project)`,
|
|
4498
|
+
`defineTable(${JSON.stringify(table)}, {`,
|
|
4499
|
+
` // …columns, relations and the rest stay as they are…`,
|
|
4501
4500
|
...schema === "public" ? [] : [` schema: ${JSON.stringify(schema)},`],
|
|
4502
|
-
`
|
|
4501
|
+
` rls: ${rulesSource(rules, " ")}`,
|
|
4503
4502
|
`});`
|
|
4504
4503
|
].join("\n");
|
|
4505
4504
|
}
|
|
4506
4505
|
function rebaseRules(schema, table, rules, note) {
|
|
4507
4506
|
return {
|
|
4508
4507
|
applicable: true,
|
|
4509
|
-
|
|
4510
|
-
snippet:
|
|
4511
|
-
note: `${note} ${
|
|
4508
|
+
rls: rulesSource(rules),
|
|
4509
|
+
snippet: tableSnippet(schema, table, rules),
|
|
4510
|
+
note: `${note} ${RLS_DOCS}`
|
|
4512
4511
|
};
|
|
4513
4512
|
}
|
|
4514
4513
|
function noRebaseRule(note) {
|
|
4515
4514
|
return {
|
|
4516
4515
|
applicable: false,
|
|
4517
|
-
|
|
4516
|
+
rls: null,
|
|
4518
4517
|
snippet: null,
|
|
4519
4518
|
note
|
|
4520
4519
|
};
|
|
@@ -4548,7 +4547,7 @@ function ownerRule(snapshot, policy, operation, ownerField) {
|
|
|
4548
4547
|
ownerField
|
|
4549
4548
|
};
|
|
4550
4549
|
}
|
|
4551
|
-
var OWNER_FIELD_NOTE = "Rebase enables row-level security on every
|
|
4550
|
+
var OWNER_FIELD_NOTE = "Rebase enables row-level security on every table it declares and compiles each rule into a policy at boot and on `rebase db push`; `ownerField` compiles to `<column>::text = rebase.uid()`, so a row is visible and writable only to the user whose id it holds.";
|
|
4552
4551
|
var RAW_RULE_NOTE = "A raw rule keeps the expression as SQL; Rebase writes it into the policy as is, with `{column}` standing for the row being checked.";
|
|
4553
4552
|
/**
|
|
4554
4553
|
* Raw expressions copied from a database Rebase did not create may call
|
|
@@ -4640,7 +4639,7 @@ function callerCaveats(snapshot, scope) {
|
|
|
4640
4639
|
}
|
|
4641
4640
|
var RLS_FILTERS_EVERYONE = "With row-level security on, every role that neither owns the table nor holds BYPASSRLS sees only the rows a policy admits — a backend job connecting as such a role is filtered too.";
|
|
4642
4641
|
function managedCaveat(policy) {
|
|
4643
|
-
return `Policy "${policy.name}" is compiled by Rebase from a
|
|
4642
|
+
return `Policy "${policy.name}" is compiled by Rebase from a table's \`rls\` and dropped and re-created on every boot, so an ALTER POLICY would be undone at the next restart. Change the rule, then redeploy or run \`rebase db push\`. A table that says \`rls: "inherit"\` takes \`defaultRls\` from backend/schema/index.ts — a stock scaffold's unfiltered read rule lives there.`;
|
|
4644
4643
|
}
|
|
4645
4644
|
function policyAt(snapshot, finding) {
|
|
4646
4645
|
const { schema, table, policy } = finding.target;
|
|
@@ -4771,7 +4770,7 @@ function rlsDisabled(snapshot, finding) {
|
|
|
4771
4770
|
placeholders: [],
|
|
4772
4771
|
alternatives: [],
|
|
4773
4772
|
caveats: ["Callers that need this data must then reach it through a function or view that checks the caller, kept in a schema your API does not expose."],
|
|
4774
|
-
rebase: noRebaseRule("Not expressible: a foreign table cannot have row-level security, and
|
|
4773
|
+
rebase: noRebaseRule("Not expressible: a foreign table cannot have row-level security, and `rls` rules compile to policies. Keep it out of the tables a Rebase backend declares.")
|
|
4775
4774
|
};
|
|
4776
4775
|
const scope = ownerScope(snapshot, rel);
|
|
4777
4776
|
const existing = policiesFor(snapshot, rel.schema, rel.name);
|
|
@@ -4780,7 +4779,7 @@ function rlsDisabled(snapshot, finding) {
|
|
|
4780
4779
|
const rebase = rebaseRules(rel.schema, rel.name, [{
|
|
4781
4780
|
operation: "all",
|
|
4782
4781
|
ownerField: scope.ownerField
|
|
4783
|
-
}], `${OWNER_FIELD_NOTE} Declare the table
|
|
4782
|
+
}], `${OWNER_FIELD_NOTE} Declare the table with defineTable in backend/schema/, or add the rule to the definition that maps it.`);
|
|
4784
4783
|
const revokeAlternative = revokes.length > 0 ? [{
|
|
4785
4784
|
summary: "If API callers should not reach this table at all, revoke their privileges instead.",
|
|
4786
4785
|
sql: revokes.join("\n")
|
|
@@ -4843,7 +4842,7 @@ function rlsEnabledNotForced(snapshot, finding) {
|
|
|
4843
4842
|
const revokes = members.map((role) => `REVOKE ${qi(rel.owner)} FROM ${qi(role)};`);
|
|
4844
4843
|
const force = `ALTER TABLE ${qrel(rel.schema, rel.name)} FORCE ROW LEVEL SECURITY;`;
|
|
4845
4844
|
const membershipCaveat = members.length > 0 ? [`If ${members.join(", ")} holds ${rel.owner} through another role rather than directly, the REVOKE is a no-op: revoke the intermediate membership instead.`] : [];
|
|
4846
|
-
const rebase = noRebaseRule("Not
|
|
4845
|
+
const rebase = noRebaseRule("Not an `rls` setting. Rebase never sets FORCE: it runs every API request as rebase_user, which does not own the tables it declares, so the owner's exemption never reaches a caller.");
|
|
4847
4846
|
if (snapshot.platform === "rebase") return {
|
|
4848
4847
|
summary: `Do not FORCE row-level security on ${rel.schema}.${rel.name}: Rebase's privileged writes run as the owner ${rel.owner} and depend on its exemption. Make sure nothing untrusted connects as, or is a member of, that role.`,
|
|
4849
4848
|
apply: revokes.length > 0 ? "sql" : "manual",
|
|
@@ -4891,7 +4890,7 @@ function junctionTableUnprotected(snapshot, finding) {
|
|
|
4891
4890
|
name,
|
|
4892
4891
|
operation: "select",
|
|
4893
4892
|
using: linked((column) => `{${column}}`)
|
|
4894
|
-
}], `If this is the junction of a many-to-many link, declare it as a \`
|
|
4893
|
+
}], `If this is the junction of a many-to-many link, declare it as a \`rel.manyToMany(...)\` relation instead: Rebase then creates the junction itself, with row-level security on and policies derived from both tables. The rule here is for a join table declared as its own table. ${RAW_RULE_NOTE}`)
|
|
4895
4894
|
};
|
|
4896
4895
|
}
|
|
4897
4896
|
function grantToPublic(snapshot, finding) {
|
|
@@ -4906,10 +4905,10 @@ function grantToPublic(snapshot, finding) {
|
|
|
4906
4905
|
placeholders: [],
|
|
4907
4906
|
alternatives: [],
|
|
4908
4907
|
caveats: [`Every role that read or wrote this table through PUBLIC loses access. Grant it back explicitly where it is needed: GRANT ${privileges.join(", ")} ON ${qrel(schema, table)} TO "<role>";`],
|
|
4909
|
-
rebase: noRebaseRule("Not
|
|
4908
|
+
rebase: noRebaseRule("Not an `rls` setting: Rebase grants table privileges to its own request role, and the rules decide which rows each request reaches.")
|
|
4910
4909
|
};
|
|
4911
4910
|
}
|
|
4912
|
-
var VIEW_NOTE = "Not
|
|
4911
|
+
var VIEW_NOTE = "Not an `rls` setting: rules attach to a table. Serve this data through the base table's definition, whose rules then apply to every read, rather than through a view.";
|
|
4913
4912
|
function viewBypassesRls(snapshot, finding) {
|
|
4914
4913
|
const { schema } = finding.target;
|
|
4915
4914
|
const name = finding.target.view ?? finding.target.table;
|
|
@@ -4966,7 +4965,7 @@ function securityDefinerMutableSearchPath(snapshot, finding) {
|
|
|
4966
4965
|
placeholders: [],
|
|
4967
4966
|
alternatives: [],
|
|
4968
4967
|
caveats: ["Only pg_catalog is on the path afterwards: schema-qualify every table and function the body uses (public.orders, not orders), or the routine fails at its next call."],
|
|
4969
|
-
rebase: noRebaseRule("Not
|
|
4968
|
+
rebase: noRebaseRule("Not an `rls` setting: it concerns a function, not a table's rows.")
|
|
4970
4969
|
};
|
|
4971
4970
|
}
|
|
4972
4971
|
var escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
@@ -5010,7 +5009,7 @@ function unqualifiedColumnInSubquery(snapshot, finding) {
|
|
|
5010
5009
|
const column = finding.target.column ?? hits[0].hit.column;
|
|
5011
5010
|
const inner = hits[0].hit.inner;
|
|
5012
5011
|
const confirm = `This assumes ${policy.table}.${column} — the row being checked — was meant, not ${inner}.${column}. Confirm before applying: it changes which rows the policy admits.`;
|
|
5013
|
-
const rebase = ruleClauses ? rebaseRules(policy.schema, policy.table, [rawRule(snapshot, policy, ruleClauses.USING ?? policy.using, ruleClauses["WITH CHECK"] ?? policy.withCheck)], `${rawRuleNote(snapshot, policy.using, policy.withCheck)} The structured form, \`policy.existsIn({
|
|
5012
|
+
const rebase = ruleClauses ? rebaseRules(policy.schema, policy.table, [rawRule(snapshot, policy, ruleClauses.USING ?? policy.using, ruleClauses["WITH CHECK"] ?? policy.withCheck)], `${rawRuleNote(snapshot, policy.using, policy.withCheck)} The structured form, \`policy.existsIn({ table, where })\` with \`policy.outerField("…")\` for the outer row, makes the binding explicit and is checked by the type system.`) : noRebaseRule("The comparison could not be located in the expression exactly once, so no rule was derived.");
|
|
5014
5013
|
if (!sqlClauses) return {
|
|
5015
5014
|
summary: `In ${where(finding)}, qualify \`${column}\` inside the subquery over ${inner} as ${policy.table}.${column} if it is meant to name the row being checked.`,
|
|
5016
5015
|
apply: "manual",
|
|
@@ -5150,8 +5149,8 @@ function remediationFor(snapshot, finding) {
|
|
|
5150
5149
|
* - No ANSI, no prose outside string values, nothing on stdout but the document.
|
|
5151
5150
|
*/
|
|
5152
5151
|
/** Bumped when a key is renamed or removed; adding one does not bump it. */
|
|
5153
|
-
var AGENT_FORMAT_VERSION =
|
|
5154
|
-
var HOW_TO_APPLY = "For each finding, read remediation.apply. \"sql\": replace every token listed in remediation.placeholders, then run remediation.sql as a migration. \"rebase-config\": the object is generated by Rebase from a
|
|
5152
|
+
var AGENT_FORMAT_VERSION = 2;
|
|
5153
|
+
var HOW_TO_APPLY = "For each finding, read remediation.apply. \"sql\": replace every token listed in remediation.placeholders, then run remediation.sql as a migration. \"rebase-config\": the object is generated by Rebase from a table's rls (a defineTable in backend/schema/) and would be re-made on the next boot, so edit the rules as remediation.rebase.snippet shows and run `rebase db push`. \"manual\": remediation.summary names the decision to make. Read remediation.caveats before applying; remediation.alternatives are fixes for a different intent. Re-run rls-check afterwards: a fixed finding's key is gone.";
|
|
5155
5154
|
function findingKey(finding) {
|
|
5156
5155
|
const { schema, table, view, routine, policy, column } = finding.target;
|
|
5157
5156
|
const object = view ?? table ?? (routine ? `${routine}()` : "");
|
|
@@ -5211,7 +5210,7 @@ function renderAgentReport(result, snapshot, options) {
|
|
|
5211
5210
|
const report = {
|
|
5212
5211
|
tool: "@rebasepro/rls-check",
|
|
5213
5212
|
format: "agent",
|
|
5214
|
-
formatVersion:
|
|
5213
|
+
formatVersion: 2,
|
|
5215
5214
|
version: options.version,
|
|
5216
5215
|
howToApply: HOW_TO_APPLY,
|
|
5217
5216
|
scannedAt: result.scannedAt,
|
|
@@ -5636,7 +5635,7 @@ function buildScanResult(snapshot, findings, meta) {
|
|
|
5636
5635
|
/**
|
|
5637
5636
|
* What stdout carries. `text` is the report for a person; `json` is the
|
|
5638
5637
|
* {@link ScanResult} contract; `agent` is one JSON document with a remediation —
|
|
5639
|
-
* SQL and the Rebase `
|
|
5638
|
+
* SQL and the Rebase `rls` equivalent — on every finding, for a
|
|
5640
5639
|
* coding agent to apply.
|
|
5641
5640
|
*/
|
|
5642
5641
|
var OUTPUT_FORMATS = [
|
|
@@ -6004,7 +6003,7 @@ Options
|
|
|
6004
6003
|
--format <name> text (default), json (the same as --json) or agent: one JSON
|
|
6005
6004
|
document for a coding agent, where every finding carries the
|
|
6006
6005
|
failing table and policy, the SQL that fixes it and the
|
|
6007
|
-
equivalent Rebase
|
|
6006
|
+
equivalent rules for a Rebase table's rls.
|
|
6008
6007
|
--html <path> Also write a self-contained HTML report to <path>. One file,
|
|
6009
6008
|
no network requests, safe to attach to a ticket.
|
|
6010
6009
|
--schema <name> Restrict the scan to a schema. Repeatable or comma-separated.
|