@rebasepro/rls-check 0.25.1 → 0.26.0

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.
@@ -0,0 +1,51 @@
1
+ import type { DbSnapshot, Finding } from "./types.js";
2
+ /**
3
+ * Where the decisive change belongs.
4
+ *
5
+ * - `sql`: run {@link Remediation.sql}, as a migration, after filling in its
6
+ * placeholders.
7
+ * - `rebase-config`: the object is compiled by Rebase from a collection's
8
+ * `securityRules` and re-made on every boot, so SQL would be undone. Edit
9
+ * the rule ({@link RebaseEquivalent.snippet}) and run `rebase db push`.
10
+ * - `manual`: no statement can be written without a decision only a person
11
+ * can make. {@link Remediation.summary} says what to decide.
12
+ */
13
+ export type RemediationApply = "sql" | "rebase-config" | "manual";
14
+ /** A token in `sql` or in the Rebase rules that must be replaced before use. */
15
+ export interface Placeholder {
16
+ /** Exactly as it appears in the text, e.g. `<owner_column>`. */
17
+ token: string;
18
+ /** What to put there, and how to find it out. */
19
+ meaning: string;
20
+ }
21
+ /** Another valid fix, for when the intent behind the object is ambiguous. */
22
+ export interface AlternativeFix {
23
+ summary: string;
24
+ sql: string;
25
+ }
26
+ /** The same fix, said the Rebase way. */
27
+ export interface RebaseEquivalent {
28
+ /** False when `securityRules` cannot express this fix; `note` says why. */
29
+ applicable: boolean;
30
+ /** The `securityRules` array, as TypeScript source. Null when not applicable. */
31
+ securityRules: string | null;
32
+ /** A `defineCollection({ … })` excerpt showing where the rules go. */
33
+ snippet: string | null;
34
+ note: string;
35
+ }
36
+ export interface Remediation {
37
+ /** One sentence: what the fix does. */
38
+ summary: string;
39
+ apply: RemediationApply;
40
+ /** Statements, each ending in `;`. Null when SQL is the wrong place. */
41
+ sql: string | null;
42
+ placeholders: Placeholder[];
43
+ alternatives: AlternativeFix[];
44
+ /** What applying the fix changes besides clearing the finding. */
45
+ caveats: string[];
46
+ rebase: RebaseEquivalent;
47
+ }
48
+ /** One builder per check id. A check without one is caught by `remediation.test.ts`. */
49
+ export declare const REMEDIATIONS: Record<string, (snapshot: DbSnapshot, finding: Finding) => Remediation>;
50
+ /** The remediation for one finding, computed against the snapshot it came from. */
51
+ export declare function remediationFor(snapshot: DbSnapshot, finding: Finding): Remediation;
@@ -0,0 +1,69 @@
1
+ import { type Remediation } from "./remediation.js";
2
+ import type { DbSnapshot, Finding, ScanResult, Severity } from "./types.js";
3
+ /** Bumped when a key is renamed or removed; adding one does not bump it. */
4
+ export declare const AGENT_FORMAT_VERSION = 1;
5
+ export interface AgentFinding {
6
+ /**
7
+ * Stable across runs: `<checkId>:<schema>.<object>[:<policy>][:<column>]`.
8
+ * The same finding on the next scan has the same key.
9
+ */
10
+ key: string;
11
+ /** One of the ids `--list-checks` prints. */
12
+ checkId: string;
13
+ severity: Severity;
14
+ confidence: Finding["confidence"];
15
+ /** At or above `--fail-on`: this finding alone makes the run exit 1. */
16
+ failsRun: boolean;
17
+ target: {
18
+ schema: string;
19
+ table: string | null;
20
+ policy: string | null;
21
+ view: string | null;
22
+ routine: string | null;
23
+ column: string | null;
24
+ };
25
+ title: string;
26
+ detail: string;
27
+ impact: string;
28
+ docs: string | null;
29
+ remediation: Remediation;
30
+ }
31
+ export interface AgentReport {
32
+ tool: "@rebasepro/rls-check";
33
+ format: "agent";
34
+ formatVersion: number;
35
+ version: string;
36
+ /** How to use `findings[].remediation`, in one paragraph. */
37
+ howToApply: string;
38
+ scannedAt: string;
39
+ database: ScanResult["database"];
40
+ serverVersion: string;
41
+ platform: ScanResult["platform"];
42
+ exposedRoles: string[];
43
+ verdict: {
44
+ exitCode: number;
45
+ reason: string;
46
+ failOn: Severity | "none";
47
+ };
48
+ /** False when a catalogue read or a check failed: no finding is not "clean". */
49
+ complete: boolean;
50
+ /** Facts that change how far the findings can be trusted, in sentences. */
51
+ notes: string[];
52
+ diagnostics: ScanResult["diagnostics"];
53
+ summary: {
54
+ findings: number;
55
+ failing: number;
56
+ bySeverity: Record<Severity, number>;
57
+ };
58
+ findings: AgentFinding[];
59
+ }
60
+ export interface AgentRenderOptions {
61
+ failOn: Severity | "none";
62
+ version: string;
63
+ }
64
+ export declare function findingKey(finding: Finding): string;
65
+ /**
66
+ * The agent document. Needs the snapshot as well as the result: a remediation
67
+ * names columns, grants and policy expressions that the result does not carry.
68
+ */
69
+ export declare function renderAgentReport(result: ScanResult, snapshot: DbSnapshot, options: AgentRenderOptions): string;
package/dist/report.d.ts CHANGED
@@ -62,6 +62,8 @@ export declare function clampWidth(columns: number | undefined): number;
62
62
  * grep these out of CI logs.
63
63
  */
64
64
  export declare function formatTarget(target: Finding["target"]): string;
65
+ /** Sort key: worst first, then a stable schema/table/id ordering. */
66
+ export declare function compareFindings(a: Finding, b: Finding): number;
65
67
  export interface RenderOptions {
66
68
  color: boolean;
67
69
  /** Findings only: no banner, no summary. The privilege caveat still prints. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rebasepro/rls-check",
3
- "version": "0.25.1",
3
+ "version": "0.26.0",
4
4
  "description": "Audit Row-Level Security on any PostgreSQL database — finds tables served without RLS, permissive tautologies, unqualified columns in policy subqueries, RLS-bypassing views and unprotected junction tables. Read-only.",
5
5
  "keywords": [
6
6
  "postgres",