@lintsure/core 0.3.3 → 0.3.4
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 +1 -1
- package/dist/src/assessment.js +11 -9
- package/dist/src/guidance.d.ts +1 -1
- package/dist/src/guidance.js +9 -3
- package/dist/src/index.d.ts +5 -2
- package/dist/src/index.js +49 -16
- package/dist/src/knowledge/{soc2.d.ts → cra.d.ts} +1 -1
- package/dist/src/knowledge/cra.js +87 -0
- package/dist/src/knowledge/gdpr.js +5 -2
- package/dist/src/knowledge/index.js +3 -3
- package/dist/src/knowledge/more.d.ts +3 -0
- package/dist/src/knowledge/more.js +66 -0
- package/dist/src/knowledge/owasp-top10.js +7 -7
- package/dist/src/knowledge/types.d.ts +12 -0
- package/dist/src/packs.d.ts +14 -0
- package/dist/src/packs.js +43 -0
- package/dist/src/rules/cra.d.ts +6 -0
- package/dist/src/rules/cra.js +82 -0
- package/dist/src/rules/index.d.ts +1 -0
- package/dist/src/rules/index.js +49 -35
- package/dist/src/rules/owasp.js +17 -6
- package/dist/src/rules/stack.d.ts +4 -0
- package/dist/src/rules/stack.js +69 -0
- package/dist/src/rules/standards.d.ts +4 -0
- package/dist/src/rules/standards.js +72 -0
- package/dist/src/types.d.ts +14 -2
- package/package.json +2 -4
- package/dist/src/knowledge/iso-27001.d.ts +0 -2
- package/dist/src/knowledge/iso-27001.js +0 -63
- package/dist/src/knowledge/soc2.js +0 -65
|
@@ -19,6 +19,18 @@ export interface Profile {
|
|
|
19
19
|
b2bCustomers?: boolean;
|
|
20
20
|
/** Do customers or partners ask specifically for an ISO certificate? */
|
|
21
21
|
wantsCertification?: boolean;
|
|
22
|
+
/** Do you supply software, an app or a connected device in the EU as a business? */
|
|
23
|
+
digitalProductEU?: boolean;
|
|
24
|
+
/** Is there a mobile app (iOS, Android, React Native, Expo)? */
|
|
25
|
+
mobileApp?: boolean;
|
|
26
|
+
/** Do you handle health information for US patients, as a covered entity or business associate? */
|
|
27
|
+
healthDataUS?: boolean;
|
|
28
|
+
/** Do you sell software to US government agencies or their suppliers? */
|
|
29
|
+
governmentCustomers?: boolean;
|
|
30
|
+
/** Do you sell to consumers in the EU (shops, banking, travel, e-books, communication services)? */
|
|
31
|
+
euConsumers?: boolean;
|
|
32
|
+
/** Do you take card payments (used by the PCI DSS pack)? */
|
|
33
|
+
cardPayments?: boolean;
|
|
22
34
|
/** Are you based in, or mainly selling to, the US? */
|
|
23
35
|
usMarket?: boolean;
|
|
24
36
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type FrameworkKnowledge } from "./knowledge/index.js";
|
|
2
|
+
import type { Control, Rule } from "./types.js";
|
|
3
|
+
export interface Pack {
|
|
4
|
+
/** Package name, for example "@lintsure/pack-pci-dss". */
|
|
5
|
+
id: string;
|
|
6
|
+
rules: Rule[];
|
|
7
|
+
knowledge: FrameworkKnowledge[];
|
|
8
|
+
/** Controls this pack adds to rules that already exist, by rule id. */
|
|
9
|
+
forExisting?: Record<string, Control[]>;
|
|
10
|
+
}
|
|
11
|
+
/** Adds a pack's frameworks, rules and mappings. Loading the same pack twice does nothing. */
|
|
12
|
+
export declare function registerPack(p: Pack): void;
|
|
13
|
+
/** Loads packs by name. Returns the names that couldn't be loaded (wrong name or not installed). */
|
|
14
|
+
export declare function loadPacks(names: string[]): Promise<string[]>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Rule packs: extra frameworks and rules installed next to Lintsure (for example the Lintsure platform's sector packs).
|
|
2
|
+
// Safety: a scanned repo must never be able to run code through Lintsure. So only packages named @lintsure/pack-*
|
|
3
|
+
// load, and they're resolved from where Lintsure itself is installed, never from the scanned repo's node_modules.
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
6
|
+
import { ALL_FRAMEWORKS } from "./index.js";
|
|
7
|
+
import { knowledge } from "./knowledge/index.js";
|
|
8
|
+
import { rules } from "./rules/index.js";
|
|
9
|
+
const PACK_NAME = /^@lintsure\/pack-[a-z0-9-]+$/;
|
|
10
|
+
const loaded = new Set();
|
|
11
|
+
/** Adds a pack's frameworks, rules and mappings. Loading the same pack twice does nothing. */
|
|
12
|
+
export function registerPack(p) {
|
|
13
|
+
if (loaded.has(p.id))
|
|
14
|
+
return;
|
|
15
|
+
loaded.add(p.id);
|
|
16
|
+
for (const [id, cs] of Object.entries(p.forExisting ?? {}))
|
|
17
|
+
rules.find((r) => r.id === id)?.controls.push(...cs);
|
|
18
|
+
rules.push(...p.rules);
|
|
19
|
+
for (const k of p.knowledge) {
|
|
20
|
+
knowledge.push(k);
|
|
21
|
+
if (!ALL_FRAMEWORKS.includes(k.id))
|
|
22
|
+
ALL_FRAMEWORKS.push(k.id);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/** Loads packs by name. Returns the names that couldn't be loaded (wrong name or not installed). */
|
|
26
|
+
export async function loadPacks(names) {
|
|
27
|
+
const failed = [];
|
|
28
|
+
const require = createRequire(import.meta.url);
|
|
29
|
+
for (const name of names) {
|
|
30
|
+
if (!PACK_NAME.test(name)) {
|
|
31
|
+
failed.push(name);
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
const mod = await import(pathToFileURL(require.resolve(name)).href);
|
|
36
|
+
registerPack((mod.default ?? mod.pack));
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
failed.push(name);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return failed;
|
|
43
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Control, Rule } from "../types.js";
|
|
2
|
+
/** CRA controls for rules that already exist. Merged by id in rules/index.ts. */
|
|
3
|
+
export declare const craForExisting: Record<string, Control[]>;
|
|
4
|
+
export declare const craRules: Rule[];
|
|
5
|
+
/** Lines in a GitHub Actions `run:` step that paste text an outsider controls. Pure. */
|
|
6
|
+
export declare function untrustedInRun(lines: string[]): number[];
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
const DRAFT = { mappedBy: "beta", reviewedAt: "pending" };
|
|
2
|
+
const P1 = (l, title) => ({ framework: "cra", id: `Annex I Part I (2)(${l})`, title });
|
|
3
|
+
const P2 = (n, title) => ({ framework: "cra", id: `Annex I Part II (${n})`, title });
|
|
4
|
+
const DEFAULTS = P1("b", "Secure by default configuration"), ACCESS = P1("d", "Protection from unauthorised access"), CONFIDENTIAL = P1("e", "Confidentiality of data"), INTEGRITY = P1("f", "Integrity of data and programs"), MINIMAL = P1("g", "Data minimisation"), SURFACE = P1("j", "Limited attack surface"), LOGGING = P1("l", "Security logging");
|
|
5
|
+
const COMPONENTS = P2("1", "Components identified, including an SBOM"), DISCLOSURE = P2("5", "Coordinated vulnerability disclosure policy"), UPDATES = P2("7", "Updates distributed securely");
|
|
6
|
+
const A03 = { framework: "owasp-top10", id: "A03:2025", title: "Software Supply Chain Failures" };
|
|
7
|
+
const A08 = { framework: "owasp-top10", id: "A08:2025", title: "Software or Data Integrity Failures" };
|
|
8
|
+
const tag = (c, ids) => Object.fromEntries(ids.map((id) => [id, [c]]));
|
|
9
|
+
/** CRA controls for rules that already exist. Merged by id in rules/index.ts. */
|
|
10
|
+
export const craForExisting = mergeTags(tag(DEFAULTS, ["config.debug-on", "config.allowed-hosts-any", "config.default-secret-key", "cors.any-origin", "build.sourcemaps-public", "csrf.disabled", "session.cookie-insecure"]), tag(ACCESS, ["auth.hardcoded-password", "jwt.unverified", "jwt.no-expiry", "supabase.rls-disabled", "supabase.policy-allows-all", "supabase.service-key-in-client", "cookie.trusted-role", "path.user-input", "fs.world-writable"]), tag(CONFIDENTIAL, ["transport.plain-http", "transport.tls-verify-off", "crypto.weak-cipher", "crypto.weak-password-hash", "crypto.weak-random-token", "secret.in-source", "secret.public-env"]), tag(INTEGRITY, ["sql.string-built", "cmd.shell-built", "code.eval", "deserialize.unsafe", "xss.raw-html", "template.user-string", "nosql.operator-input", "xml.external-entities", "mass-assignment", "html.script-no-sri"]), tag(MINIMAL, ["pii.logged", "pii.in-url", "pii.to-analytics"]), tag(SURFACE, ["ssrf.user-url", "redirect.open", "upload.unrestricted", "error.stack-to-client"]), tag(LOGGING, ["log.secret", "log.injection"]), tag(COMPONENTS, ["deps.unpinned-version", "deps.install-script"]), tag(UPDATES, ["ci.action-unpinned", "ci.prt-checkout-head"]));
|
|
11
|
+
function mergeTags(...maps) {
|
|
12
|
+
const out = {};
|
|
13
|
+
for (const m of maps)
|
|
14
|
+
for (const [id, cs] of Object.entries(m))
|
|
15
|
+
(out[id] ??= []).push(...cs);
|
|
16
|
+
return out;
|
|
17
|
+
}
|
|
18
|
+
// Where a security policy is usually kept; GitHub reads all three.
|
|
19
|
+
const POLICY = /^(\.github\/|docs\/)?security\.(md|txt|rst)$/i;
|
|
20
|
+
// SBOM files in CycloneDX or SPDX format, by common names.
|
|
21
|
+
const SBOM = /(^|\/)(sbom|bom)[\w.-]*\.(json|xml|spdx)$|\.(cdx|spdx)(\.json|\.xml)?$|\.spdx$/i;
|
|
22
|
+
const WORKFLOWS = /(^|\/)\.github\/workflows\//;
|
|
23
|
+
// Event fields anyone can set by opening an issue, pull request or comment, or naming a branch.
|
|
24
|
+
const UNTRUSTED = /\$\{\{\s*github\.(head_ref|event\.(issue|pull_request|comment|review|review_comment|discussion|head_commit|commits|workflow_run)[\w.*[\]]*\.(title|body|message|label|ref|email|name|head_branch))\b/;
|
|
25
|
+
const BINARY = /\.(exe|dll|so|dylib|jar|class|pyc|o|a|bin|msi|apk)$/i;
|
|
26
|
+
const UPDATER = /^\.github\/dependabot\.ya?ml$|(^|\/)(renovate\.json5?|\.renovaterc(\.json)?)$|^\.github\/renovate\.json5?$/;
|
|
27
|
+
const FIXES = P2("2", "Vulnerabilities fixed without delay");
|
|
28
|
+
export const craRules = [
|
|
29
|
+
{ id: "repo.no-security-policy", title: "No way for people to report a vulnerability", status: "partial", severity: "medium", controls: [DISCLOSURE],
|
|
30
|
+
fix: "Add a SECURITY.md to the repository root (or .github/) saying where to report a vulnerability, what to include and how soon you'll reply.",
|
|
31
|
+
note: "The Cyber Resilience Act expects a policy for coordinated vulnerability disclosure and a contact address for reports. Marked Partial: the policy may live on your website, or you scanned a subfolder of a larger repo.",
|
|
32
|
+
extensions: [], repoTest: (files) => (files.some((f) => POLICY.test(f)) ? null : "SECURITY.md"), ...DRAFT },
|
|
33
|
+
{ id: "repo.no-sbom", title: "No software bill of materials (SBOM)", status: "partial", severity: "low", controls: [COMPONENTS],
|
|
34
|
+
fix: "Generate an SBOM in CycloneDX or SPDX format at release, for example with `npx @cyclonedx/cyclonedx-npm` or `syft`, and keep it with each release.",
|
|
35
|
+
note: "The Cyber Resilience Act asks makers to list the components in their product, at least the top-level dependencies, in a machine-readable SBOM. Marked Partial: it may be generated in CI or at release instead of kept in the repo; if so, accept this finding with that reason.",
|
|
36
|
+
extensions: [], repoTest: (files) => (files.some((f) => SBOM.test(f)) ? null : "sbom.cdx.json"), ...DRAFT },
|
|
37
|
+
{ id: "update.unverified-download", title: "Downloaded script run without a check", status: "partial", severity: "medium", controls: [UPDATES, A03, A08],
|
|
38
|
+
fix: "Download the file first, check it against a published checksum or signature, then run it. Or install from a package manager that verifies packages.",
|
|
39
|
+
note: "Piping `curl` or `wget` straight into a shell runs whatever the server sends at that moment, with no check that it is the file you expect. Marked Partial: well-known installers over HTTPS are a common, accepted risk.",
|
|
40
|
+
extensions: [".sh", ".bash", ".yml", ".yaml", ""], fileName: /\.(sh|bash|ya?ml)$|^Dockerfile/i,
|
|
41
|
+
// Quoted text is dropped first: `echo "Install via: curl ... | bash"` tells a person what to run, it runs nothing (field test).
|
|
42
|
+
test: (l) => /\b(curl|wget)\b[^|#\n]*\|\s*(sudo\s+)?(-\S+\s+)*(ba|z|da)?sh\b/.test(l.replace(/"(?:\\.|[^"\\])*"|'[^']*'/g, '""')), ...DRAFT },
|
|
43
|
+
{ id: "ci.write-all-permissions", title: "Workflow gives its token write access to everything", status: "gap", severity: "medium", controls: [UPDATES, A03],
|
|
44
|
+
fix: "Replace `permissions: write-all` with only what the job needs, for example `permissions: contents: read`, and grant write access per job where it's really used.",
|
|
45
|
+
note: "With write-all, any step that is compromised, including a third-party action, can push code, change releases or edit issues with the workflow's token.",
|
|
46
|
+
extensions: [".yml", ".yaml"], pathMatch: WORKFLOWS, test: (l) => /^\s*permissions:\s*["']?write-all\b/.test(l), ...DRAFT },
|
|
47
|
+
{ id: "ci.script-injection", title: "Text from a pull request or issue pasted into a workflow command", status: "gap", severity: "high", controls: [UPDATES, A03, A08],
|
|
48
|
+
fix: "Pass the value through an environment variable instead, for example `env: TITLE: ${{ github.event.issue.title }}` and then use \"$TITLE\" in the script.",
|
|
49
|
+
note: "Anyone who opens an issue or pull request controls its title, body and branch name. Pasted into a `run:` step, that text becomes part of the shell command and can run anything with the workflow's secrets.",
|
|
50
|
+
extensions: [".yml", ".yaml"], pathMatch: WORKFLOWS, fileTest: untrustedInRun, ...DRAFT },
|
|
51
|
+
{ id: "repo.binary-committed", title: "Compiled program committed to the repository", status: "partial", severity: "low", controls: [COMPONENTS],
|
|
52
|
+
fix: "Remove the file and build it from source in CI, or download it at build time from a release with a checksum.",
|
|
53
|
+
note: "Nobody can review what a compiled file does, and it isn't covered by dependency checks. Marked Partial: some projects keep a reviewed binary on purpose.",
|
|
54
|
+
extensions: [], repoTest: (files) => files.find((f) => BINARY.test(f) && !/gradle-wrapper\.jar$/.test(f)) ?? null, ...DRAFT },
|
|
55
|
+
{ id: "repo.no-dependency-updates", title: "No automated dependency updates", status: "partial", severity: "low", controls: [FIXES],
|
|
56
|
+
fix: "Turn on Dependabot (add .github/dependabot.yml) or Renovate (renovate.json), so security fixes in your dependencies reach you as pull requests.",
|
|
57
|
+
note: "The Cyber Resilience Act expects vulnerabilities to be fixed without delay, including in the components you use. Marked Partial: updates may be handled another way, such as a hosted setting.",
|
|
58
|
+
extensions: [], repoTest: (files) => (files.some((f) => UPDATER.test(f)) ? null : ".github/dependabot.yml"), ...DRAFT },
|
|
59
|
+
];
|
|
60
|
+
/** Lines in a GitHub Actions `run:` step that paste text an outsider controls. Pure. */
|
|
61
|
+
export function untrustedInRun(lines) {
|
|
62
|
+
const out = [];
|
|
63
|
+
let runIndent = -1; // indent of the `run: |` key while inside its block
|
|
64
|
+
lines.forEach((l, i) => {
|
|
65
|
+
const indent = l.search(/\S/);
|
|
66
|
+
if (runIndent >= 0 && indent >= 0 && indent <= runIndent)
|
|
67
|
+
runIndent = -1;
|
|
68
|
+
const run = /^(\s*-?\s*)run:\s*(.*)$/.exec(l);
|
|
69
|
+
if (run) {
|
|
70
|
+
if (/^[|>][-+]?\s*$/.test(run[2])) {
|
|
71
|
+
runIndent = run[1].length;
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (UNTRUSTED.test(run[2]))
|
|
75
|
+
out.push(i + 1);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (runIndent >= 0 && UNTRUSTED.test(l))
|
|
79
|
+
out.push(i + 1);
|
|
80
|
+
});
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Rule } from "../types.js";
|
|
2
2
|
export declare const rules: Rule[];
|
|
3
|
+
export declare const isAiCall: (l: string) => boolean;
|
|
3
4
|
/** The first AI call in a file with no log or save between 10 lines above and 30 below (one finding per file). Pure. */
|
|
4
5
|
export declare const unloggedAiCalls: (lines: string[]) => number[];
|
|
5
6
|
/** AI calls in a file that names an image, voice or video model. Pure. */
|
package/dist/src/rules/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { owaspForExisting, owaspRules } from "./owasp.js";
|
|
2
|
+
import { stackRules } from "./stack.js";
|
|
3
|
+
import { craForExisting, craRules } from "./cra.js";
|
|
4
|
+
import { standardsForExisting, standardsRules } from "./standards.js";
|
|
2
5
|
const CODE = [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".py"];
|
|
3
|
-
// Beta: mapped by us
|
|
6
|
+
// Beta: mapped by us from our own reading of the public texts.
|
|
4
7
|
const DRAFT = { mappedBy: "beta", reviewedAt: "pending" };
|
|
5
8
|
const LOG_CALL = /\b(console\.(log|info|warn|error|debug)|logger\.\w+|log\.(info|warn|error|debug)|logging\.\w+|print)\s*\(/;
|
|
6
9
|
// Drops the text of string literals but keeps interpolations, so "email error" is ignored and `${user.email}` or f"{user.email}" is not.
|
|
@@ -23,6 +26,24 @@ function logArgs(l) {
|
|
|
23
26
|
// Values that usually come from a request or the user. SQL built from them is a Gap; from other values, Partial.
|
|
24
27
|
const USER_INPUT = /\b(req|request|params|query|body|input|args|form|ctx|event|payload|searchParams|user_input)\b/;
|
|
25
28
|
const SQL_PARTS = /\$\{([^}]*)\}|\bf["'][^"']*\{([^}]*)\}|["']\s*\+\s*([\w.[\]]+)|\.format\(([^)]*)\)|%s["']\s*%\s*([^\n]+)/g;
|
|
29
|
+
// Key formats with a fixed, documented prefix, so a match is almost never anything else. Written from each
|
|
30
|
+
// provider's published token format. Generic "key = random string" guessing is left out on purpose: too noisy.
|
|
31
|
+
const KEY_FORMATS = new RegExp([
|
|
32
|
+
"\\b[sr]k_live_[0-9a-zA-Z]{10,}", // Stripe secret and restricted keys
|
|
33
|
+
"\\b(AKIA|ASIA)[0-9A-Z]{16}\\b", // AWS access key ids
|
|
34
|
+
"\\bgh[pousr]_[0-9A-Za-z]{30,}", "\\bgithub_pat_[0-9A-Za-z_]{40,}", // GitHub tokens
|
|
35
|
+
"\\bglpat-[0-9A-Za-z_-]{20,}", // GitLab personal tokens
|
|
36
|
+
"\\bxox[baprs]-[0-9A-Za-z-]{10,}", "hooks\\.slack\\.com/services/T[0-9A-Z]+/B[0-9A-Z]+/[0-9A-Za-z]{20,}", // Slack
|
|
37
|
+
"\\bsk-ant-(api|admin)\\d{2}-[0-9A-Za-z_-]{20,}", // Anthropic
|
|
38
|
+
"\\bsk-(proj|svcacct|admin)-[0-9A-Za-z_-]{20,}", "\\bsk-[0-9A-Za-z]{20}T3BlbkFJ[0-9A-Za-z]{20}", // OpenAI
|
|
39
|
+
"\\bSG\\.[0-9A-Za-z_-]{22}\\.[0-9A-Za-z_-]{43}", // SendGrid
|
|
40
|
+
"\\bnpm_[0-9A-Za-z]{36}\\b", "\\bpypi-AgEIcHlwaS5vcmc[0-9A-Za-z_-]{20,}", // npm and PyPI publish tokens
|
|
41
|
+
"\\bhf_[A-Za-z]{34}\\b", // Hugging Face
|
|
42
|
+
"\\bshp(at|ss|ca|pa)_[0-9a-fA-F]{32}\\b", // Shopify
|
|
43
|
+
"-----BEGIN (RSA |EC |DSA |OPENSSH |ENCRYPTED )?PRIVATE KEY-----", "-----BEGIN PGP PRIVATE KEY BLOCK-----",
|
|
44
|
+
].join("|"));
|
|
45
|
+
// Example values from provider docs (AKIAIOSFODNN7EXAMPLE and the like) and obvious fill-ins.
|
|
46
|
+
const DOC_EXAMPLE = /EXAMPLE|X{6,}|x{6,}|0{12,}|1234567890abcdef/;
|
|
26
47
|
export const rules = [
|
|
27
48
|
{
|
|
28
49
|
id: "pii.logged",
|
|
@@ -30,13 +51,12 @@ export const rules = [
|
|
|
30
51
|
status: "gap", severity: "high",
|
|
31
52
|
controls: [
|
|
32
53
|
{ framework: "gdpr", id: "Art. 32", title: "Security of processing" },
|
|
33
|
-
{ framework: "soc2", id: "CC6.1", title: "Logical access security" },
|
|
34
|
-
{ framework: "iso-27001", id: "A.8.11", title: "Data masking" },
|
|
35
54
|
],
|
|
36
55
|
fix: "Mask or remove the personal field before logging, for example mask(user.email).",
|
|
37
56
|
note: "Logs are copied to many places and kept for a long time. Personal data in them is hard to find and delete.",
|
|
38
57
|
extensions: CODE,
|
|
39
|
-
|
|
58
|
+
// ::add-mask:: tells GitHub Actions to hide the value in its logs.
|
|
59
|
+
test: (l) => { const a = logArgs(l); return a !== null && !l.includes("::add-mask::") && PII.test(codeOnly(a)); },
|
|
40
60
|
...DRAFT,
|
|
41
61
|
},
|
|
42
62
|
{
|
|
@@ -44,14 +64,13 @@ export const rules = [
|
|
|
44
64
|
title: "Secret or private key committed to source",
|
|
45
65
|
status: "gap", severity: "high",
|
|
46
66
|
controls: [
|
|
47
|
-
{ framework: "soc2", id: "CC6.1", title: "Logical access security" },
|
|
48
|
-
{ framework: "iso-27001", id: "A.8.24", title: "Use of cryptography" },
|
|
49
67
|
{ framework: "gdpr", id: "Art. 32", title: "Security of processing" },
|
|
50
68
|
],
|
|
51
69
|
fix: "Move the secret to an environment variable or secrets manager, then rotate it: it is already in your git history.",
|
|
52
70
|
note: "Anyone with read access to the repo, or a leaked copy of it, can use this key.",
|
|
53
71
|
extensions: [...CODE, ".env", ".json", ".yaml", ".yml", ".toml"],
|
|
54
|
-
|
|
72
|
+
// A key header that ends right at a quote (or "...") is code looking for a key, e.g. key.includes('-----BEGIN PRIVATE KEY-----').
|
|
73
|
+
test: (l) => { const m = l.match(KEY_FORMATS); return !!m && !DOC_EXAMPLE.test(m[0]) && !/PRIVATE KEY( BLOCK)?-----(["'`]|\.\.\.)/.test(l); },
|
|
55
74
|
...DRAFT,
|
|
56
75
|
},
|
|
57
76
|
{
|
|
@@ -59,8 +78,6 @@ export const rules = [
|
|
|
59
78
|
title: "Data sent over plain HTTP",
|
|
60
79
|
status: "partial", severity: "medium",
|
|
61
80
|
controls: [
|
|
62
|
-
{ framework: "soc2", id: "CC6.7", title: "Transmission of data" },
|
|
63
|
-
{ framework: "iso-27001", id: "A.8.20", title: "Network security" },
|
|
64
81
|
{ framework: "gdpr", id: "Art. 32", title: "Security of processing" },
|
|
65
82
|
],
|
|
66
83
|
fix: "Use https:// for every external call.",
|
|
@@ -76,8 +93,6 @@ export const rules = [
|
|
|
76
93
|
controls: [
|
|
77
94
|
{ framework: "gdpr", id: "Art. 5(1)(c)", title: "Data minimisation" },
|
|
78
95
|
{ framework: "gdpr", id: "Art. 28", title: "Processors" },
|
|
79
|
-
{ framework: "soc2", id: "P6.1", title: "Disclosure to third parties" },
|
|
80
|
-
{ framework: "iso-27001", id: "A.5.34", title: "Privacy and protection of PII" },
|
|
81
96
|
],
|
|
82
97
|
fix: "Send an internal user ID instead of the email or name, and list the tool as a processor.",
|
|
83
98
|
note: "Analytics vendors keep what you send them. Personal data there needs a lawful basis and a processing agreement.",
|
|
@@ -91,8 +106,6 @@ export const rules = [
|
|
|
91
106
|
status: "partial", severity: "medium",
|
|
92
107
|
controls: [
|
|
93
108
|
{ framework: "gdpr", id: "Art. 32", title: "Security of processing" },
|
|
94
|
-
{ framework: "soc2", id: "CC6.1", title: "Logical access security" },
|
|
95
|
-
{ framework: "iso-27001", id: "A.8.11", title: "Data masking" },
|
|
96
109
|
],
|
|
97
110
|
fix: "Send it in the request body or a header instead of the query string.",
|
|
98
111
|
note: "URLs end up in server logs, browser history and referrer headers. Marked Partial: confirm the value is real personal data.",
|
|
@@ -106,13 +119,12 @@ export const rules = [
|
|
|
106
119
|
status: "gap", severity: "high",
|
|
107
120
|
controls: [
|
|
108
121
|
{ framework: "gdpr", id: "Art. 32", title: "Security of processing" },
|
|
109
|
-
{ framework: "soc2", id: "CC6.1", title: "Logical access security" },
|
|
110
|
-
{ framework: "iso-27001", id: "A.8.24", title: "Use of cryptography" },
|
|
111
122
|
],
|
|
112
123
|
fix: "Use a password hashing function made for it: argon2id, scrypt or bcrypt.",
|
|
113
124
|
note: "MD5 and SHA-1 are fast, so leaked hashes can be cracked quickly.",
|
|
114
125
|
extensions: CODE,
|
|
115
|
-
|
|
126
|
+
// Sentences in strings ("the server asked for an MD5 password hash") are messages, not hashing (field test).
|
|
127
|
+
test: (l) => { const c = l.replace(/(["'`])(?:(?!\1).)*\s(?:(?!\1).)*\1/g, '""'); return /\b(md5|sha1)\b/i.test(c) && /pass(word|wd)?/i.test(c); },
|
|
116
128
|
...DRAFT,
|
|
117
129
|
},
|
|
118
130
|
{
|
|
@@ -120,8 +132,6 @@ export const rules = [
|
|
|
120
132
|
title: "TLS certificate checks turned off",
|
|
121
133
|
status: "gap", severity: "high",
|
|
122
134
|
controls: [
|
|
123
|
-
{ framework: "soc2", id: "CC6.7", title: "Transmission of data" },
|
|
124
|
-
{ framework: "iso-27001", id: "A.8.20", title: "Network security" },
|
|
125
135
|
{ framework: "gdpr", id: "Art. 32", title: "Security of processing" },
|
|
126
136
|
],
|
|
127
137
|
fix: "Remove the override and trust a proper certificate. For self-signed certs in tests, scope it to the test only.",
|
|
@@ -135,8 +145,6 @@ export const rules = [
|
|
|
135
145
|
title: "SQL query built from strings",
|
|
136
146
|
status: "gap", severity: "high",
|
|
137
147
|
controls: [
|
|
138
|
-
{ framework: "soc2", id: "CC7.1", title: "Detect and fix vulnerabilities" },
|
|
139
|
-
{ framework: "iso-27001", id: "A.8.28", title: "Secure coding" },
|
|
140
148
|
{ framework: "gdpr", id: "Art. 32", title: "Security of processing" },
|
|
141
149
|
],
|
|
142
150
|
fix: "Use parameterized queries or your ORM's query builder. If the inserted value is fixed text from your own code, confirm it can never come from a user.",
|
|
@@ -144,23 +152,23 @@ export const rules = [
|
|
|
144
152
|
extensions: CODE,
|
|
145
153
|
test: (l) => {
|
|
146
154
|
// SQL keywords are written in UPPER or lower case; "Select a plan from..." in a sentence is not SQL.
|
|
147
|
-
|
|
155
|
+
// A keyword after a dot or before "(" is a method call (hash.update(...), select(Model) in SQLAlchemy), not SQL text.
|
|
156
|
+
if (!/(?<![.\w])(SELECT|INSERT|UPDATE|DELETE|select|insert|update|delete)\b(?!\s*\()[^"'`]*\b(FROM|INTO|SET|WHERE|from|into|set|where)\b/.test(l))
|
|
148
157
|
return false;
|
|
149
158
|
const parts = [...l.matchAll(SQL_PARTS)].map((m) => m.slice(1).find(Boolean) ?? "");
|
|
150
159
|
if (!parts.length)
|
|
151
160
|
return false;
|
|
152
161
|
return parts.some((p) => USER_INPUT.test(p)) ? true : "partial";
|
|
153
162
|
},
|
|
163
|
+
// Tagged templates from Postgres.js, Drizzle, Prisma and similar send ${} values as parameters, not as SQL text (field test).
|
|
164
|
+
unlessNear: /(?<![.\w])(sql|safeSql|tx|Prisma\.sql)(<[^>`]*>)?\s*`|\$queryRaw\s*`/,
|
|
154
165
|
...DRAFT,
|
|
155
166
|
},
|
|
156
167
|
{
|
|
157
168
|
id: "cors.any-origin",
|
|
158
169
|
title: "API open to requests from any website",
|
|
159
170
|
status: "partial", severity: "medium",
|
|
160
|
-
controls: [
|
|
161
|
-
{ framework: "soc2", id: "CC6.6", title: "Boundary protection" },
|
|
162
|
-
{ framework: "iso-27001", id: "A.8.20", title: "Network security" },
|
|
163
|
-
],
|
|
171
|
+
controls: [],
|
|
164
172
|
fix: "List the exact origins that may call the API.",
|
|
165
173
|
note: "Marked Partial: fine for a public, read-only API. Risky when the API uses cookies or returns user data.",
|
|
166
174
|
extensions: CODE,
|
|
@@ -171,24 +179,20 @@ export const rules = [
|
|
|
171
179
|
id: "session.cookie-insecure",
|
|
172
180
|
title: "Session cookie without Secure or HttpOnly",
|
|
173
181
|
status: "partial", severity: "medium",
|
|
174
|
-
controls: [
|
|
175
|
-
{ framework: "soc2", id: "CC6.1", title: "Logical access security" },
|
|
176
|
-
{ framework: "iso-27001", id: "A.8.5", title: "Secure authentication" },
|
|
177
|
-
],
|
|
182
|
+
controls: [],
|
|
178
183
|
fix: "Set secure: true and httpOnly: true on session cookies.",
|
|
179
184
|
note: "Without these flags a session cookie can be read by scripts or sent over plain HTTP. Marked Partial: confirm it is a session cookie.",
|
|
180
185
|
extensions: CODE,
|
|
181
186
|
test: (l) => /\b(httpOnly|secure)\s*:\s*false\b|SESSION_COOKIE_(SECURE|HTTPONLY)\s*=\s*False/.test(l),
|
|
187
|
+
// `secure: false` in an email (SMTP) transport is about TLS on that connection, not a cookie (field test).
|
|
188
|
+
unlessNear: /\b(smtp|createTransport|nodemailer|ignoreTLS|requireTLS)\b/i,
|
|
182
189
|
...DRAFT,
|
|
183
190
|
},
|
|
184
191
|
{
|
|
185
192
|
id: "config.debug-on",
|
|
186
193
|
title: "Debug mode switched on in code",
|
|
187
194
|
status: "partial", severity: "medium",
|
|
188
|
-
controls: [
|
|
189
|
-
{ framework: "soc2", id: "CC8.1", title: "Change management" },
|
|
190
|
-
{ framework: "iso-27001", id: "A.8.9", title: "Configuration management" },
|
|
191
|
-
],
|
|
195
|
+
controls: [],
|
|
192
196
|
fix: "Read debug from an environment variable that is off in production.",
|
|
193
197
|
note: "Debug pages can show stack traces, settings and secrets. Marked Partial: it may only run locally.",
|
|
194
198
|
extensions: CODE,
|
|
@@ -212,7 +216,7 @@ const AI_CALL = new RegExp([
|
|
|
212
216
|
/\b(fetch|axios(\.\w+)?|requests\.\w+|httpx\.\w+|ky(\.\w+)?)\s*\(\s*[`"'][^`"']*(api\.openai\.com\/v1\/(chat|responses|completions|images|audio)|api\.anthropic\.com\/v1\/messages|generativelanguage\.googleapis\.com|openrouter\.ai\/api|api\.groq\.com|api\.mistral\.ai|api\.deepseek\.com)/.source,
|
|
213
217
|
].join("|"), "i");
|
|
214
218
|
const NOT_AI = /\bfunctions\.invoke\s*\(/;
|
|
215
|
-
const isAiCall = (l) => AI_CALL.test(l) && !NOT_AI.test(l);
|
|
219
|
+
export const isAiCall = (l) => AI_CALL.test(l) && !NOT_AI.test(l);
|
|
216
220
|
/** The first AI call in a file with no log or save between 10 lines above and 30 below (one finding per file). Pure. */
|
|
217
221
|
export const unloggedAiCalls = (lines) => {
|
|
218
222
|
const i = lines.findIndex((l, i) => isAiCall(l) && !lines.slice(Math.max(0, i - 10), i + 31).some((x) => LOGGED.test(x)));
|
|
@@ -244,12 +248,13 @@ rules.push({
|
|
|
244
248
|
status: "partial", severity: "medium",
|
|
245
249
|
controls: [
|
|
246
250
|
{ framework: "eu-ai-act", id: "Art. 12", title: "Record-keeping" },
|
|
247
|
-
{ framework: "soc2", id: "CC7.2", title: "Monitoring of system components" },
|
|
248
251
|
],
|
|
249
252
|
fix: "Log each AI call: time, model and version, input reference and output, without raw personal data.",
|
|
250
253
|
note: "High-risk systems must keep logs that let you trace what the AI did. Marked Partial: logging may happen in a wrapper or another file.",
|
|
251
254
|
extensions: CODE,
|
|
252
255
|
fileTest: unloggedAiCalls,
|
|
256
|
+
// Examples, docs and the provider adapters inside AI libraries aren't where an app keeps its records (field test, 50 repos).
|
|
257
|
+
unlessPath: /(^|\/)(examples?|samples?|cookbooks?|docs?|libs)\/|(^|\/)(providers?|adapters?|llms?|model-runtime|integrations)\//i,
|
|
253
258
|
...DRAFT,
|
|
254
259
|
}, {
|
|
255
260
|
id: "ai.hides-being-ai",
|
|
@@ -292,3 +297,12 @@ rules.push({
|
|
|
292
297
|
for (const r of rules)
|
|
293
298
|
r.controls.push(...(owaspForExisting[r.id] ?? []));
|
|
294
299
|
rules.push(...owaspRules);
|
|
300
|
+
// Supabase, Next.js and Vite: open databases and secrets reaching the browser.
|
|
301
|
+
rules.push(...stackRules);
|
|
302
|
+
for (const r of rules)
|
|
303
|
+
r.controls.push(...(craForExisting[r.id] ?? []));
|
|
304
|
+
rules.push(...craRules);
|
|
305
|
+
rules.push(...standardsRules);
|
|
306
|
+
// After the push, so the new LLM rules also get their CWE tags.
|
|
307
|
+
for (const r of rules)
|
|
308
|
+
r.controls.push(...(standardsForExisting[r.id] ?? []));
|
package/dist/src/rules/owasp.js
CHANGED
|
@@ -88,7 +88,9 @@ export const owaspRules = [
|
|
|
88
88
|
rule({ id: "crypto.weak-cipher", title: "Weak or broken encryption", status: "gap", severity: "high", controls: [A04],
|
|
89
89
|
fix: "Use AES-256-GCM or ChaCha20-Poly1305 with a random nonce, through a maintained library. Replace createCipher with createCipheriv.",
|
|
90
90
|
note: "DES, RC4 and ECB mode can be broken or leak patterns in the data; createCipher derives a weak key and IV (CWE-327).", extensions: CODE,
|
|
91
|
-
|
|
91
|
+
// A quoted cipher name counts only on a line about encryption: "des" is also a German word (field test).
|
|
92
|
+
test: (l) => /\bcreateCipher\s*\(|\bMODE_ECB\b|\b(DES3?|ARC4|Blowfish)\.new\s*\(/i.test(l)
|
|
93
|
+
|| (/["'](des|des-ede3?|des-ede3-cbc|rc4|aes-\d{3}-ecb)["']/i.test(l) && /cipher|crypt|algorithm/i.test(l)) }),
|
|
92
94
|
rule({ id: "jwt.unverified", title: "JWT accepted without checking its signature", status: "gap", severity: "high", controls: [A04, A07],
|
|
93
95
|
fix: "Verify tokens with jwt.verify (Node) or jwt.decode with a key and an explicit algorithms list (Python). Never allow the 'none' algorithm.",
|
|
94
96
|
note: "Without signature checks anyone can write their own token and claim to be any user (CWE-347).", extensions: CODE,
|
|
@@ -105,12 +107,18 @@ export const owaspRules = [
|
|
|
105
107
|
rule({ id: "code.eval", title: "Code run from a string", status: "gap", severity: "high", controls: [A05],
|
|
106
108
|
fix: "Avoid eval and new Function. Parse data with JSON.parse or a real parser, and map names to functions with a lookup table.",
|
|
107
109
|
note: "If any part of the string comes from outside, it runs as your code (code injection, CWE-94). Partial when the input isn't visible on the line.", extensions: CODE,
|
|
108
|
-
|
|
109
|
-
|
|
110
|
+
// A method named eval is a definition, not a call (also TypeScript class methods, field test); $$eval is Playwright's;
|
|
111
|
+
// "eval" inside a string is text.
|
|
112
|
+
test: (l) => /\b(def|function|async)\s+eval\s*\(|^\s*((public|private|protected|static|override)\s+)*eval\s*\([^)]*\)\s*(:[^{=]+)?\{\s*$/.test(l) ? false
|
|
113
|
+
: /(^|[^.\w$])eval\s*\(|\bnew Function\s*\(/.test(l.replace(/(["'])(?:\\.|(?!\1).)*\1/g, '""')) ? byInput(l) : false }),
|
|
110
114
|
rule({ id: "xss.raw-html", title: "HTML inserted without escaping", status: "partial", severity: "high", controls: [A05],
|
|
111
115
|
fix: "Set text with textContent, let your framework escape values, or sanitise with DOMPurify before inserting HTML.",
|
|
112
116
|
note: "If the HTML contains user input, attackers can run scripts in your users' browsers (cross-site scripting, CWE-79). Partial because fixed HTML from your own code is safe.", extensions: MARKUP,
|
|
113
|
-
|
|
117
|
+
// Clearing an element, DOMPurify-cleaned HTML and JSON-LD made with JSON.stringify are safe (field test).
|
|
118
|
+
test: (l) => /\.(innerHTML|outerHTML)\s*[+]?=|\bdocument\.write(ln)?\(|\bdangerouslySetInnerHTML\b|\bv-html=|\{@html\b|\|\s*safe\b|\bmark_safe\(|\bMarkup\(/.test(l)
|
|
119
|
+
&& !/innerHTML\s*=\s*(""|''|``)\s*;?\s*$|DOMPurify\.sanitize|\bsanitize(Html)?\(|__html:\s*JSON\.stringify\(/.test(l)
|
|
120
|
+
// Fixed markup written in the code, with nothing inserted, can't carry someone else's input.
|
|
121
|
+
&& !/innerHTML\s*=\s*("[^"$]*"|'[^'$]*'|`[^`$]*`)\s*;?\s*$/.test(l) }),
|
|
114
122
|
rule({ id: "template.user-string", title: "Template built from request data", status: "gap", severity: "high", controls: [A05],
|
|
115
123
|
fix: "Render a fixed template file and pass user values as variables, never as part of the template text.",
|
|
116
124
|
note: "Template syntax in user input runs on your server (server-side template injection, CWE-94).", extensions: CODE,
|
|
@@ -132,7 +140,10 @@ export const owaspRules = [
|
|
|
132
140
|
rule({ id: "auth.hardcoded-password", title: "Password written in the code", status: "partial", severity: "high", controls: [A07],
|
|
133
141
|
fix: "Load passwords from environment variables or a secret manager, and rotate any that were committed.",
|
|
134
142
|
note: "Anyone with the code has the password, and it can't be changed without a release (CWE-259, CWE-798).", extensions: CODE,
|
|
135
|
-
|
|
143
|
+
unlessPath: /(^|\/)(locales?|i18n|lang|langs|translations?)\//i, // the word "password" in other languages
|
|
144
|
+
test: (l) => /\b(password|passwd|pwd|db_pass)\s*[:=]\s*["'][^"'\s]{4,}["']/i.test(l) && !/(example|placeholder|changeme|your[_-]|xxx|\*\*\*|<|process\.env|os\.environ|getenv|type\s*[:=]|label|autocomplete)/i.test(l)
|
|
145
|
+
// Translations ("Парола", "Passwort") and obvious stand-ins ("new-password", "hashed-password", "hunter2") are not credentials (field test).
|
|
146
|
+
&& !/[:=]\s*["'][^"']*(passw|hash|redact|hidden|\bhunter2\b|[^\x00-\x7F])/i.test(l) }),
|
|
136
147
|
rule({ id: "jwt.no-expiry", title: "JWT signed without an expiry", status: "partial", severity: "medium", controls: [A07],
|
|
137
148
|
fix: "Add expiresIn (Node) or an exp claim (Python), and keep access tokens short-lived.",
|
|
138
149
|
note: "A stolen token without an expiry works forever (insufficient session expiration, CWE-613). Partial because the expiry may be set in a payload built elsewhere.", extensions: CODE,
|
|
@@ -159,7 +170,7 @@ export const owaspRules = [
|
|
|
159
170
|
if (a === null)
|
|
160
171
|
return false;
|
|
161
172
|
// Logging only whether a token exists (!!token) or a short prefix (token[:8], token.slice(0, 8)) is safe.
|
|
162
|
-
const safe = stripStrings(a).replace(/!!\s*[\w.?]+/g, "").replace(/[\w.?]+\s*\[\s*:\s*\d+\s*\]/g, "").replace(/[\w.?]+\.slice\(\s*0\s*,\s*\d+\s*\)/g, "");
|
|
173
|
+
const safe = stripStrings(a).replace(/!!\s*[\w.?]+/g, "").replace(/[\w.?]+\s*\[\s*:\s*\d+\s*\]/g, "").replace(/[\w.?]+\.slice\(\s*0\s*,\s*\d+\s*\)/g, "").replace(/[\w.?]+\.length\b/g, ""); // its length is safe too
|
|
163
174
|
return /\b(token|secret|authorization|api_?key|apiKey|bearer|access_token|refresh_token|private_?key|client_secret)\b/i.test(safe);
|
|
164
175
|
} }),
|
|
165
176
|
rule({ id: "log.injection", title: "Raw request data written to logs", status: "partial", severity: "low", controls: [A09],
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Rule } from "../types.js";
|
|
2
|
+
/** Tables created in this SQL file with no "enable row level security" for them in the same file. Pure. */
|
|
3
|
+
export declare function tablesWithoutRls(lines: string[], shared?: string): number[];
|
|
4
|
+
export declare const stackRules: Rule[];
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
const CODE = [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs"];
|
|
2
|
+
const DRAFT = { mappedBy: "beta", reviewedAt: "pending" };
|
|
3
|
+
const GDPR32 = { framework: "gdpr", id: "Art. 32", title: "Security of processing" };
|
|
4
|
+
const OW = (n, title) => ({ framework: "owasp-top10", id: `A${n}:2025`, title });
|
|
5
|
+
const A01 = OW("01", "Broken Access Control"), A02 = OW("02", "Security Misconfiguration"), A04 = OW("04", "Cryptographic Failures");
|
|
6
|
+
const rule = (r) => ({ ...r, ...DRAFT });
|
|
7
|
+
// Tables in schemas Supabase manages itself; RLS on these is not the app's job.
|
|
8
|
+
const SYSTEM_SCHEMA = /^(auth|storage|realtime|extensions|supabase_\w+|pg_\w+|graphql\w*|vault)\./i;
|
|
9
|
+
/** Tables created in this SQL file with no "enable row level security" for them in the same file. Pure. */
|
|
10
|
+
export function tablesWithoutRls(lines, shared) {
|
|
11
|
+
const text = (shared ?? lines.join("\n")).toLowerCase();
|
|
12
|
+
const out = [];
|
|
13
|
+
lines.forEach((l, i) => {
|
|
14
|
+
const m = /^\s*create\s+table\s+(if\s+not\s+exists\s+)?([\w."]+)/i.exec(l);
|
|
15
|
+
if (!m)
|
|
16
|
+
return;
|
|
17
|
+
const full = m[2].replace(/"/g, "");
|
|
18
|
+
if (SYSTEM_SCHEMA.test(full))
|
|
19
|
+
return;
|
|
20
|
+
const name = full.split(".").pop().toLowerCase();
|
|
21
|
+
const rls = new RegExp(`alter\\s+table\\s+(only\\s+)?(if\\s+exists\\s+)?("?\\w+"?\\.)?"?${name}"?\\s+enable\\s+row\\s+level\\s+security`);
|
|
22
|
+
if (!rls.test(text))
|
|
23
|
+
out.push(i + 1);
|
|
24
|
+
});
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
27
|
+
// Browser-exposed env prefixes: Next.js, Vite, Expo, Create React App, Nuxt, SvelteKit/Astro (PUBLIC_).
|
|
28
|
+
// No bare PUBLIC_: it matches ordinary constants like PUBLIC_WITH_PRIVATE_AGENT.
|
|
29
|
+
const PUBLIC_ENV = /\b(NEXT_PUBLIC|VITE|EXPO_PUBLIC|REACT_APP|NUXT_PUBLIC)_[A-Z0-9_]*/g;
|
|
30
|
+
// Services whose API keys are always server-side secrets (widget and analytics keys are often public, so not these).
|
|
31
|
+
const SECRET_SERVICE = /OPENAI|ANTHROPIC|CLAUDE|GEMINI|GOOGLE_AI|GROQ|MISTRAL|DEEPSEEK|COHERE|REPLICATE|ELEVENLABS|RESEND|SENDGRID|MAILGUN|POSTMARK|TWILIO|AWS|DATABASE|PINECONE|GITHUB_TOKEN/;
|
|
32
|
+
// Supabase projects keep their SQL in supabase/. Prisma or Drizzle migrations elsewhere talk to a database the
|
|
33
|
+
// browser can't reach, so row level security isn't the point there (found in the field test: 263 false alarms).
|
|
34
|
+
const SUPABASE_DIR = /(^|\/)supabase\//;
|
|
35
|
+
// Keys that are public by design and fine in the browser.
|
|
36
|
+
const PUBLIC_BY_DESIGN = /ANON|PUBLISHABLE|_PK_|PUBLIC_KEY|FIREBASE|MAPS|MAPBOX|POSTHOG|SENTRY_DSN|ALGOLIA_SEARCH|SITE_KEY|MEASUREMENT_ID|URL$|_URL_/;
|
|
37
|
+
export const stackRules = [
|
|
38
|
+
rule({ id: "supabase.rls-disabled", title: "Database table without row level security", status: "partial", severity: "high", controls: [GDPR32, A01],
|
|
39
|
+
fix: "Add `alter table <name> enable row level security;` and a policy that limits each row to its owner, for example `using (auth.uid() = user_id)`.",
|
|
40
|
+
note: "In Supabase, a table without row level security can be read and changed by anyone with your public anon key, which ships in every browser. Lintsure looks across every SQL file in supabase/. Marked Partial: it may be switched on outside these files, for example in the dashboard.", extensions: [".sql"],
|
|
41
|
+
pathMatch: SUPABASE_DIR,
|
|
42
|
+
sharedContext: true, // RLS is often switched on in a later migration (field test, 50 repos)
|
|
43
|
+
fileTest: tablesWithoutRls }),
|
|
44
|
+
rule({ id: "supabase.policy-allows-all", title: "Database policy that lets everyone in", status: "partial", severity: "high", controls: [GDPR32, A01],
|
|
45
|
+
fix: "Limit the policy to the right people, for example `using (auth.uid() = user_id)`. Keep `using (true)` only for data that is meant to be public, such as published posts.",
|
|
46
|
+
note: "`using (true)` or `with check (true)` turns row level security on but lets every request through, so the table is as open as having no security at all. Marked Partial: public read access can be intended.", extensions: [".sql"],
|
|
47
|
+
pathMatch: SUPABASE_DIR,
|
|
48
|
+
test: (l) => /\b(using|with\s+check)\s*\(\s*true\s*\)/i.test(l) }),
|
|
49
|
+
rule({ id: "secret.public-env", title: "Secret in a variable the browser can see", status: "gap", severity: "high", controls: [GDPR32, A04],
|
|
50
|
+
fix: "Rename the variable without the public prefix (NEXT_PUBLIC_, VITE_ and so on), use it only in server code, and rotate the key, since it has already been shipped to browsers.",
|
|
51
|
+
note: "Variables starting with NEXT_PUBLIC_, VITE_, EXPO_PUBLIC_ or REACT_APP_ are copied into the JavaScript every visitor downloads. Anyone can read a secret, service-role or private key put there. Keys that are public by design (Supabase anon, Stripe publishable, Firebase) are not flagged.",
|
|
52
|
+
extensions: [...CODE, ".env"],
|
|
53
|
+
test: (l) => {
|
|
54
|
+
const names = l.match(PUBLIC_ENV) ?? [];
|
|
55
|
+
const risky = names.filter((n) => !PUBLIC_BY_DESIGN.test(n));
|
|
56
|
+
return risky.some((n) => /SECRET|PRIVATE|SERVICE_ROLE|PASSWORD|SB_SECRET/.test(n) || (SECRET_SERVICE.test(n) && /KEY|TOKEN/.test(n)));
|
|
57
|
+
} }),
|
|
58
|
+
rule({ id: "supabase.service-key-in-client", title: "Supabase service-role key used in browser code", status: "gap", severity: "high", controls: [GDPR32, A01],
|
|
59
|
+
fix: "Use the service-role key only in server code (API routes, server actions, edge functions). In browser code, use the anon key with row level security, and rotate the service-role key if it was ever shipped.",
|
|
60
|
+
note: "The service-role key skips every row level security rule. In a file marked \"use client\", or in browser-exposed env vars, it reaches every visitor, who can then read and change your whole database.", extensions: CODE,
|
|
61
|
+
fileTest: (lines) => lines.some((l) => /^\s*["']use client["']/.test(l))
|
|
62
|
+
? lines.flatMap((l, i) => (/SERVICE_ROLE|service_role|sb_secret_/.test(l) ? [i + 1] : [])) : [] }),
|
|
63
|
+
rule({ id: "build.sourcemaps-public", title: "Source maps published in production", status: "partial", severity: "low", controls: [A02],
|
|
64
|
+
fix: "Turn off browser source maps for production, or upload them privately to your error tracker instead of serving them.",
|
|
65
|
+
note: "Public source maps let anyone read your original front-end code, comments and file structure, which makes other weaknesses easier to find. Marked Partial: some teams publish them on purpose.", extensions: CODE,
|
|
66
|
+
// Only Next.js's browser source maps: Vite's sourcemap: true is normal in libraries and CLIs (field test: 5 false alarms).
|
|
67
|
+
fileName: /^next\.config\./,
|
|
68
|
+
test: (l) => /productionBrowserSourceMaps\s*:\s*true/.test(l) }),
|
|
69
|
+
];
|