xploitscan-shared-rules 2.0.2 → 2.1.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/README.md +2 -2
- package/dist/index.cjs +807 -94
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +135 -7
- package/dist/index.d.ts +135 -7
- package/dist/index.js +799 -94
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -13,7 +13,7 @@ import { File, Node, CallExpression, ObjectExpression, BinaryExpression } from '
|
|
|
13
13
|
* ProjectContext is the narrow exception: a small set of facts computed ONCE
|
|
14
14
|
* over the whole file list before any rule runs, then handed to every rule.
|
|
15
15
|
* It is intentionally not "here is every file" — that would let rules re-parse
|
|
16
|
-
* the project
|
|
16
|
+
* the project 223 times and quietly become a cross-file analyser, which the
|
|
17
17
|
* roadmap explicitly rules out as an unwinnable race against CodeQL.
|
|
18
18
|
*
|
|
19
19
|
* Every field is optional and every consumer must behave correctly when the
|
|
@@ -186,8 +186,11 @@ declare function getSnippet(content: string, line: number, contextLines?: number
|
|
|
186
186
|
* 3. Multi-line block: `/* VC146-OK: ... *\/` above the match
|
|
187
187
|
*
|
|
188
188
|
* The marker is `<RULE-ID>-OK` (with optional `:` and explanation) or the
|
|
189
|
-
* wildcard `scanner-OK`.
|
|
190
|
-
* comment prefixes are accepted.
|
|
189
|
+
* wildcard `scanner-OK`. `#` (Python/Ruby/sh), `//` (JS/TS/Go) and `--`
|
|
190
|
+
* (SQL) comment prefixes are accepted. `--` is there because rules now read
|
|
191
|
+
* migration SQL (VC215), where `--` is the only line comment a developer
|
|
192
|
+
* would think to write; without it the marker the fix text recommends would
|
|
193
|
+
* silently do nothing in exactly the files that rule scans.
|
|
191
194
|
*
|
|
192
195
|
* Rationale: some findings aren't a regex-tightening problem — they're "I
|
|
193
196
|
* have reviewed this and accept it here." An intentionally public OG-image
|
|
@@ -691,6 +694,67 @@ declare function checkIntent(files: Array<{
|
|
|
691
694
|
content: string;
|
|
692
695
|
}>, findings: Finding[]): IntentReport;
|
|
693
696
|
|
|
697
|
+
/**
|
|
698
|
+
* Browser-exposed environment variables: which names a framework ships to the
|
|
699
|
+
* client, and which of those look like secrets.
|
|
700
|
+
*
|
|
701
|
+
* Shared by VC011 (secret-named variable in a .env file), the entropy scanner
|
|
702
|
+
* (which must not suppress a secret just because its name is public-prefixed,
|
|
703
|
+
* and must not report a public-by-design key either) and the Pro rule for AI
|
|
704
|
+
* keys read in browser code. One definition, so the three cannot disagree
|
|
705
|
+
* about whether VITE_SUPABASE_ANON_KEY is a secret.
|
|
706
|
+
*/
|
|
707
|
+
/**
|
|
708
|
+
* Env-var prefixes a framework inlines into code it ships to the browser, or
|
|
709
|
+
* into a mobile app bundle: Next.js NEXT_PUBLIC_, Vite VITE_, Create React App
|
|
710
|
+
* REACT_APP_, Expo EXPO_PUBLIC_, Gatsby GATSBY_, SvelteKit/Astro PUBLIC_ and
|
|
711
|
+
* Nuxt NUXT_PUBLIC_ (which fills runtimeConfig.public, sent to every client).
|
|
712
|
+
*
|
|
713
|
+
* VC011 only knew NEXT_PUBLIC_. The AI app builders mostly generate Vite apps
|
|
714
|
+
* (Lovable, Bolt) or Expo apps, so `VITE_OPENAI_API_KEY=sk-…` in a committed
|
|
715
|
+
* .env — a key that ends up in the public JavaScript of every deploy — got no
|
|
716
|
+
* finding naming the problem. Vite's own docs say VITE_* variables "should not
|
|
717
|
+
* contain sensitive information such as API keys".
|
|
718
|
+
*
|
|
719
|
+
* Anchored, so `PUBLIC_` cannot match inside `NEXT_PUBLIC_`/`NUXT_PUBLIC_`/
|
|
720
|
+
* `EXPO_PUBLIC_`; alternation order puts those first for the same reason.
|
|
721
|
+
* Exported for the Pro browser-key rule and the entropy scanner, which apply
|
|
722
|
+
* the same idea of "exposed by name".
|
|
723
|
+
*/
|
|
724
|
+
declare const PUBLIC_ENV_PREFIX_RE: RegExp;
|
|
725
|
+
/**
|
|
726
|
+
* Classify an env var by name (and, if known, value): `null` when the name has
|
|
727
|
+
* no browser-exposed prefix, otherwise the prefix and whether the variable
|
|
728
|
+
* looks like a secret. Order matters: a publishable VALUE beats any name; an
|
|
729
|
+
* unambiguous secret word beats the public-by-design list (so
|
|
730
|
+
* VITE_FIREBASE_ADMIN_PRIVATE_KEY is still a secret); a key-like name that
|
|
731
|
+
* survives both is treated as a secret.
|
|
732
|
+
*
|
|
733
|
+
* `publicByDesign` is true only when something positively says the value is
|
|
734
|
+
* not a credential — a publishable value, a boolean/number/plain URL, an anon
|
|
735
|
+
* JWT, or a name on the public-by-design list. A name that merely does not
|
|
736
|
+
* look key-like is `secret: false` without it, so the entropy scanner can
|
|
737
|
+
* still judge the value on its own.
|
|
738
|
+
*/
|
|
739
|
+
declare function classifyPublicEnvVar(name: string, value?: string): {
|
|
740
|
+
prefix: string;
|
|
741
|
+
secret: boolean;
|
|
742
|
+
publicByDesign: boolean;
|
|
743
|
+
} | null;
|
|
744
|
+
declare function isDotenvPath(filePath: string): boolean;
|
|
745
|
+
/**
|
|
746
|
+
* `NAME=value` / `export NAME=value`, the dotenv grammar. The value stops at a
|
|
747
|
+
* line break of either kind: callers split on "\n", so a CRLF file leaves a
|
|
748
|
+
* trailing "\r" on every line, and `(.*)$` (`.` does not match "\r") made
|
|
749
|
+
* every line of a Windows-saved .env fail to parse.
|
|
750
|
+
*/
|
|
751
|
+
declare const DOTENV_ASSIGN_RE: RegExp;
|
|
752
|
+
/**
|
|
753
|
+
* The value of a dotenv assignment, as dotenv reads it: the text inside
|
|
754
|
+
* matching quotes, or for an unquoted value everything up to a ` #` comment.
|
|
755
|
+
*/
|
|
756
|
+
declare function dotenvValue(raw: string): string;
|
|
757
|
+
|
|
694
758
|
/**
|
|
695
759
|
* Centralized Babel parser with per-file caching.
|
|
696
760
|
*
|
|
@@ -820,6 +884,19 @@ declare function isTestFile(filePath: string): boolean;
|
|
|
820
884
|
* beneath them, so this is not a fixture artefact.
|
|
821
885
|
*/
|
|
822
886
|
declare function maskComments(content: string): string;
|
|
887
|
+
/**
|
|
888
|
+
* Replace every closed `/* … *\/` block comment with `replace(comment)`.
|
|
889
|
+
* Same output as `content.replace(/\/\*[\s\S]*?\*\//g, replace)`, in linear
|
|
890
|
+
* time.
|
|
891
|
+
*
|
|
892
|
+
* WHY NOT THAT REGEX. The lazy `[\s\S]*?` scans to the end of the file for
|
|
893
|
+
* every `/*` that has no closer, so a payload of unclosed `/*` lines costs
|
|
894
|
+
* O(n²): about 1.6s per caller on 256KB, and maskComments has many callers.
|
|
895
|
+
* Here each `/*` costs one indexOf for its closer. When there is none, no
|
|
896
|
+
* later `/*` can be closed either (its closer would have been found first),
|
|
897
|
+
* so the rest of the file is left as it is, which is what the regex does.
|
|
898
|
+
*/
|
|
899
|
+
declare function replaceBlockComments(content: string, replace: (comment: string) => string): string;
|
|
823
900
|
/**
|
|
824
901
|
* Return the source of the handler enclosing `index`, or null if none is found.
|
|
825
902
|
*
|
|
@@ -879,6 +956,16 @@ declare function isInsideFixMessage(content: string, matchIndex: number): boolea
|
|
|
879
956
|
*/
|
|
880
957
|
declare function filterSilenced(matches: RuleMatch[], content: string, ruleId: string): RuleMatch[];
|
|
881
958
|
declare function findMatches(content: string, pattern: RegExp, rule: Omit<CustomRule, "check">, filePath: string, fixTemplate?: (match: RegExpExecArray) => string): RuleMatch[];
|
|
959
|
+
/**
|
|
960
|
+
* findMatches for a matcher that is not a single RegExp — one a regex can
|
|
961
|
+
* only express with super-linear backtracking. `found` yields the matches'
|
|
962
|
+
* start indices in increasing order, as RegExp#exec would; the comment and
|
|
963
|
+
* fix-message skips, line numbers and the per-file cap are findMatches' own,
|
|
964
|
+
* so a rule moved off a regex reports exactly what the regex reported.
|
|
965
|
+
*/
|
|
966
|
+
declare function findMatchesAt<M extends {
|
|
967
|
+
index: number;
|
|
968
|
+
}>(content: string, found: Iterable<M>, rule: Omit<CustomRule, "check">, filePath: string, fixTemplate?: (match: M) => string): RuleMatch[];
|
|
882
969
|
/**
|
|
883
970
|
* Build a RuleMatch from an AST-derived location. Mirrors findMatches' output
|
|
884
971
|
* shape so AST-based rules can be mixed into the same Finding stream. `line`
|
|
@@ -891,6 +978,47 @@ declare function tryParse(content: string, filePath: string): {
|
|
|
891
978
|
} | null;
|
|
892
979
|
declare const hardcodedSecrets: CustomRule;
|
|
893
980
|
declare const exposedEnvFile: CustomRule;
|
|
981
|
+
/**
|
|
982
|
+
* Blank the parts of a file that LOOK like caller authentication but are the
|
|
983
|
+
* server authenticating ITSELF to somebody else, or chat-message plumbing.
|
|
984
|
+
*
|
|
985
|
+
* WHY THIS EXISTS. An AI chat endpoint is the most common server function an
|
|
986
|
+
* AI app builder writes, and every one of them contains
|
|
987
|
+
*
|
|
988
|
+
* fetch("https://ai.gateway.lovable.dev/v1/chat/completions", {
|
|
989
|
+
* headers: { Authorization: `Bearer ${LOVABLE_API_KEY}` },
|
|
990
|
+
* body: JSON.stringify({ messages: [{ role: "user", content }] }),
|
|
991
|
+
* })
|
|
992
|
+
*
|
|
993
|
+
* The outbound `Authorization: Bearer …` header matched VC003's `bearer`,
|
|
994
|
+
* `authorization` and strong `bearer\s` patterns, and `role: "user"` matched
|
|
995
|
+
* its `user` hint, so an endpoint that lets anyone on the internet spend the
|
|
996
|
+
* owner's AI credits was reported as authenticated. Neither says anything
|
|
997
|
+
* about who is CALLING the endpoint.
|
|
998
|
+
*
|
|
999
|
+
* What is blanked:
|
|
1000
|
+
* - `role: "user" | "assistant" | "system" | …` literals;
|
|
1001
|
+
* - object literals passed as request headers (`headers: { … }`,
|
|
1002
|
+
* `headers = { … }`, `new Headers({ … })`), unless the object forwards
|
|
1003
|
+
* the inbound request's credential (see INBOUND_CREDENTIAL_READ_RE), or
|
|
1004
|
+
* a variable bound to one (see credentialValueReadsCaller);
|
|
1005
|
+
* - `headers.set("Authorization", …)` style calls building outbound headers,
|
|
1006
|
+
* with the same exception;
|
|
1007
|
+
* - SDK key configuration, `apiKey: process.env.X` / `Deno.env.get("X")`.
|
|
1008
|
+
*
|
|
1009
|
+
* What is NOT blanked, on purpose: anything that reads the inbound request
|
|
1010
|
+
* (`req.headers.get("Authorization")`, `getUser(token)`, a 401 branch). Those
|
|
1011
|
+
* are the evidence the rule is looking for.
|
|
1012
|
+
*
|
|
1013
|
+
* Offset-preserving (every blanked character becomes a space, newlines are
|
|
1014
|
+
* kept), so the result can stand in for the input in code that slices by
|
|
1015
|
+
* index or reports line numbers.
|
|
1016
|
+
*
|
|
1017
|
+
* Linear: every regex here is bounded, and the brace scan is capped both per
|
|
1018
|
+
* object and in the number of objects examined. Past the cap the remaining
|
|
1019
|
+
* objects are left as they are, which can only suppress a finding.
|
|
1020
|
+
*/
|
|
1021
|
+
declare function maskOutboundAuthNoise(code: string): string;
|
|
894
1022
|
declare const missingAuthMiddleware: CustomRule;
|
|
895
1023
|
declare const supabaseNoRLS: CustomRule;
|
|
896
1024
|
declare const stripeWebhookUnprotected: CustomRule;
|
|
@@ -986,7 +1114,7 @@ project?: ProjectContext): Finding[];
|
|
|
986
1114
|
* CLI should have to import to print one.
|
|
987
1115
|
*
|
|
988
1116
|
* Since 2.0.0 the Pro rules are not in this package at all — they live in the
|
|
989
|
-
* private packages/pro-rules — so this package CANNOT compute
|
|
1117
|
+
* private packages/pro-rules — so this package CANNOT compute 193 or 223: the
|
|
990
1118
|
* arrays those numbers describe do not exist here. Literals are the only way
|
|
991
1119
|
* to publish them.
|
|
992
1120
|
*
|
|
@@ -1000,9 +1128,9 @@ project?: ProjectContext): Finding[];
|
|
|
1000
1128
|
/** Rules any caller gets, including anonymous and free-tier CLI users. */
|
|
1001
1129
|
declare const FREE_RULE_COUNT = 30;
|
|
1002
1130
|
/** Rules gated behind a paid plan and served from the API, never bundled. */
|
|
1003
|
-
declare const PRO_RULE_COUNT =
|
|
1131
|
+
declare const PRO_RULE_COUNT = 193;
|
|
1004
1132
|
/** The full catalog. FREE_RULE_COUNT + PRO_RULE_COUNT, asserted in the test. */
|
|
1005
|
-
declare const TOTAL_RULE_COUNT =
|
|
1133
|
+
declare const TOTAL_RULE_COUNT = 223;
|
|
1006
1134
|
|
|
1007
1135
|
interface FilteredFinding {
|
|
1008
1136
|
finding: Finding;
|
|
@@ -1369,4 +1497,4 @@ input: {
|
|
|
1369
1497
|
content: string;
|
|
1370
1498
|
}[] | QualityContext, rules?: QualityRule[]): Finding[];
|
|
1371
1499
|
|
|
1372
|
-
export { type AIFilterResult, type AppRoute, type BuilderFingerprint, CHECKABLE_CLAIMS, type Confidence, type CustomRule, type DetectedFramework, type ExposedConfig, type Exposure, FREE_RULE_COUNT, type FilteredFinding, type Finding, type GradeOptions, type GradeResult, type HeaderFinding, INTENT_EXPECTATIONS, type IntentExpectation, type IntentMismatch, type IntentOrigin, type IntentReport, type IntentStatement, MODEL_ANALYSIS, MODEL_POLICY_REVIEWED, MODEL_REVIEW_INTERVAL_DAYS, MODEL_TEMPERATURE, MODEL_TRIAGE, NON_APP_PATH_PATTERNS, PRO_RULE_COUNT, type ParsedFile, type ProjectContext, QUALITY_EXAMPLES, type QualityContext, type QualityExample, type QualityFile, type QualityHit, type QualityRule, RULE_IMPACTS, type RouteFramework, type RouteTable, type RuleMatch, type SecurityGrade, type Severity, TEST_FILE_PATTERN, TOTAL_RULE_COUNT, type TaintMap, type TargetCheck, type VibePlatform, allRules, assessHeaders, astMatch, buildProjectContext, buildQualityContext, buildTaintMap, calculateGrade, callSpreads, checkIntent, classifyExposure, classifyStatement, clientSideAuth, complianceMap, consoleLogProduction, corsWildcard, dangerousInnerHTML, detectBuilder, detectExposedConfig, detectFramework, detectPlatform, disabledTLSVerification, emptyCatchBlock, enclosingHandler, envNotGitignored, evalUsage, exposedAuthSecret, exposedDebugMode, exposedEnvFile, exposedStackTraces, extractRoutes, extractScriptUrls, filterFalsePositives, filterSilenced, findMatches, findSourceMapRefs, freeRules, getObjectProperty, getSnippet, hardcodedJWTSecret, hardcodedSecrets, harvestIntent, insecureCookies, insecureRandomness, isCalleeNamed, isClientTarget, isCommentLine, isInlineSilenced, isInsideFixMessage, isLineSilenced, isMethodCall, isPrivateAddress, isServerSideFile, isServerTarget, isTestFile, isVendoredFinding, isVendoredPath, lineNumberAt, lineTextAt, maskComments, missingAuthMiddleware, missingCSP, missingErrorBoundary, missingHTTPS, missingLockFile, nextPublicSecret, noRateLimiting, normalizeScanPath, parseFile, parseScanTarget, parseSupabaseConfig, qualityRules, routeForFile, runCustomRules, scanEntropy, scanQuality, sqlInjection, stripeWebhookUnprotected, supabaseFunctionName, supabaseNoRLS, todoLeftInCode, tryParse, unmeasuredQualityRules, unvalidatedRedirect, vendoredReason, visitBinary, visitCalls, weakHashing, xssVulnerability };
|
|
1500
|
+
export { type AIFilterResult, type AppRoute, type BuilderFingerprint, CHECKABLE_CLAIMS, type Confidence, type CustomRule, DOTENV_ASSIGN_RE, type DetectedFramework, type ExposedConfig, type Exposure, FREE_RULE_COUNT, type FilteredFinding, type Finding, type GradeOptions, type GradeResult, type HeaderFinding, INTENT_EXPECTATIONS, type IntentExpectation, type IntentMismatch, type IntentOrigin, type IntentReport, type IntentStatement, MODEL_ANALYSIS, MODEL_POLICY_REVIEWED, MODEL_REVIEW_INTERVAL_DAYS, MODEL_TEMPERATURE, MODEL_TRIAGE, NON_APP_PATH_PATTERNS, PRO_RULE_COUNT, PUBLIC_ENV_PREFIX_RE, type ParsedFile, type ProjectContext, QUALITY_EXAMPLES, type QualityContext, type QualityExample, type QualityFile, type QualityHit, type QualityRule, RULE_IMPACTS, type RouteFramework, type RouteTable, type RuleMatch, type SecurityGrade, type Severity, TEST_FILE_PATTERN, TOTAL_RULE_COUNT, type TaintMap, type TargetCheck, type VibePlatform, allRules, assessHeaders, astMatch, buildProjectContext, buildQualityContext, buildTaintMap, calculateGrade, callSpreads, checkIntent, classifyExposure, classifyPublicEnvVar, classifyStatement, clientSideAuth, complianceMap, consoleLogProduction, corsWildcard, dangerousInnerHTML, detectBuilder, detectExposedConfig, detectFramework, detectPlatform, disabledTLSVerification, dotenvValue, emptyCatchBlock, enclosingHandler, envNotGitignored, evalUsage, exposedAuthSecret, exposedDebugMode, exposedEnvFile, exposedStackTraces, extractRoutes, extractScriptUrls, filterFalsePositives, filterSilenced, findMatches, findMatchesAt, findSourceMapRefs, freeRules, getObjectProperty, getSnippet, hardcodedJWTSecret, hardcodedSecrets, harvestIntent, insecureCookies, insecureRandomness, isCalleeNamed, isClientTarget, isCommentLine, isDotenvPath, isInlineSilenced, isInsideFixMessage, isLineSilenced, isMethodCall, isPrivateAddress, isServerSideFile, isServerTarget, isTestFile, isVendoredFinding, isVendoredPath, lineNumberAt, lineTextAt, maskComments, maskOutboundAuthNoise, missingAuthMiddleware, missingCSP, missingErrorBoundary, missingHTTPS, missingLockFile, nextPublicSecret, noRateLimiting, normalizeScanPath, parseFile, parseScanTarget, parseSupabaseConfig, qualityRules, replaceBlockComments, routeForFile, runCustomRules, scanEntropy, scanQuality, sqlInjection, stripeWebhookUnprotected, supabaseFunctionName, supabaseNoRLS, todoLeftInCode, tryParse, unmeasuredQualityRules, unvalidatedRedirect, vendoredReason, visitBinary, visitCalls, weakHashing, xssVulnerability };
|
package/dist/index.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ import { File, Node, CallExpression, ObjectExpression, BinaryExpression } from '
|
|
|
13
13
|
* ProjectContext is the narrow exception: a small set of facts computed ONCE
|
|
14
14
|
* over the whole file list before any rule runs, then handed to every rule.
|
|
15
15
|
* It is intentionally not "here is every file" — that would let rules re-parse
|
|
16
|
-
* the project
|
|
16
|
+
* the project 223 times and quietly become a cross-file analyser, which the
|
|
17
17
|
* roadmap explicitly rules out as an unwinnable race against CodeQL.
|
|
18
18
|
*
|
|
19
19
|
* Every field is optional and every consumer must behave correctly when the
|
|
@@ -186,8 +186,11 @@ declare function getSnippet(content: string, line: number, contextLines?: number
|
|
|
186
186
|
* 3. Multi-line block: `/* VC146-OK: ... *\/` above the match
|
|
187
187
|
*
|
|
188
188
|
* The marker is `<RULE-ID>-OK` (with optional `:` and explanation) or the
|
|
189
|
-
* wildcard `scanner-OK`.
|
|
190
|
-
* comment prefixes are accepted.
|
|
189
|
+
* wildcard `scanner-OK`. `#` (Python/Ruby/sh), `//` (JS/TS/Go) and `--`
|
|
190
|
+
* (SQL) comment prefixes are accepted. `--` is there because rules now read
|
|
191
|
+
* migration SQL (VC215), where `--` is the only line comment a developer
|
|
192
|
+
* would think to write; without it the marker the fix text recommends would
|
|
193
|
+
* silently do nothing in exactly the files that rule scans.
|
|
191
194
|
*
|
|
192
195
|
* Rationale: some findings aren't a regex-tightening problem — they're "I
|
|
193
196
|
* have reviewed this and accept it here." An intentionally public OG-image
|
|
@@ -691,6 +694,67 @@ declare function checkIntent(files: Array<{
|
|
|
691
694
|
content: string;
|
|
692
695
|
}>, findings: Finding[]): IntentReport;
|
|
693
696
|
|
|
697
|
+
/**
|
|
698
|
+
* Browser-exposed environment variables: which names a framework ships to the
|
|
699
|
+
* client, and which of those look like secrets.
|
|
700
|
+
*
|
|
701
|
+
* Shared by VC011 (secret-named variable in a .env file), the entropy scanner
|
|
702
|
+
* (which must not suppress a secret just because its name is public-prefixed,
|
|
703
|
+
* and must not report a public-by-design key either) and the Pro rule for AI
|
|
704
|
+
* keys read in browser code. One definition, so the three cannot disagree
|
|
705
|
+
* about whether VITE_SUPABASE_ANON_KEY is a secret.
|
|
706
|
+
*/
|
|
707
|
+
/**
|
|
708
|
+
* Env-var prefixes a framework inlines into code it ships to the browser, or
|
|
709
|
+
* into a mobile app bundle: Next.js NEXT_PUBLIC_, Vite VITE_, Create React App
|
|
710
|
+
* REACT_APP_, Expo EXPO_PUBLIC_, Gatsby GATSBY_, SvelteKit/Astro PUBLIC_ and
|
|
711
|
+
* Nuxt NUXT_PUBLIC_ (which fills runtimeConfig.public, sent to every client).
|
|
712
|
+
*
|
|
713
|
+
* VC011 only knew NEXT_PUBLIC_. The AI app builders mostly generate Vite apps
|
|
714
|
+
* (Lovable, Bolt) or Expo apps, so `VITE_OPENAI_API_KEY=sk-…` in a committed
|
|
715
|
+
* .env — a key that ends up in the public JavaScript of every deploy — got no
|
|
716
|
+
* finding naming the problem. Vite's own docs say VITE_* variables "should not
|
|
717
|
+
* contain sensitive information such as API keys".
|
|
718
|
+
*
|
|
719
|
+
* Anchored, so `PUBLIC_` cannot match inside `NEXT_PUBLIC_`/`NUXT_PUBLIC_`/
|
|
720
|
+
* `EXPO_PUBLIC_`; alternation order puts those first for the same reason.
|
|
721
|
+
* Exported for the Pro browser-key rule and the entropy scanner, which apply
|
|
722
|
+
* the same idea of "exposed by name".
|
|
723
|
+
*/
|
|
724
|
+
declare const PUBLIC_ENV_PREFIX_RE: RegExp;
|
|
725
|
+
/**
|
|
726
|
+
* Classify an env var by name (and, if known, value): `null` when the name has
|
|
727
|
+
* no browser-exposed prefix, otherwise the prefix and whether the variable
|
|
728
|
+
* looks like a secret. Order matters: a publishable VALUE beats any name; an
|
|
729
|
+
* unambiguous secret word beats the public-by-design list (so
|
|
730
|
+
* VITE_FIREBASE_ADMIN_PRIVATE_KEY is still a secret); a key-like name that
|
|
731
|
+
* survives both is treated as a secret.
|
|
732
|
+
*
|
|
733
|
+
* `publicByDesign` is true only when something positively says the value is
|
|
734
|
+
* not a credential — a publishable value, a boolean/number/plain URL, an anon
|
|
735
|
+
* JWT, or a name on the public-by-design list. A name that merely does not
|
|
736
|
+
* look key-like is `secret: false` without it, so the entropy scanner can
|
|
737
|
+
* still judge the value on its own.
|
|
738
|
+
*/
|
|
739
|
+
declare function classifyPublicEnvVar(name: string, value?: string): {
|
|
740
|
+
prefix: string;
|
|
741
|
+
secret: boolean;
|
|
742
|
+
publicByDesign: boolean;
|
|
743
|
+
} | null;
|
|
744
|
+
declare function isDotenvPath(filePath: string): boolean;
|
|
745
|
+
/**
|
|
746
|
+
* `NAME=value` / `export NAME=value`, the dotenv grammar. The value stops at a
|
|
747
|
+
* line break of either kind: callers split on "\n", so a CRLF file leaves a
|
|
748
|
+
* trailing "\r" on every line, and `(.*)$` (`.` does not match "\r") made
|
|
749
|
+
* every line of a Windows-saved .env fail to parse.
|
|
750
|
+
*/
|
|
751
|
+
declare const DOTENV_ASSIGN_RE: RegExp;
|
|
752
|
+
/**
|
|
753
|
+
* The value of a dotenv assignment, as dotenv reads it: the text inside
|
|
754
|
+
* matching quotes, or for an unquoted value everything up to a ` #` comment.
|
|
755
|
+
*/
|
|
756
|
+
declare function dotenvValue(raw: string): string;
|
|
757
|
+
|
|
694
758
|
/**
|
|
695
759
|
* Centralized Babel parser with per-file caching.
|
|
696
760
|
*
|
|
@@ -820,6 +884,19 @@ declare function isTestFile(filePath: string): boolean;
|
|
|
820
884
|
* beneath them, so this is not a fixture artefact.
|
|
821
885
|
*/
|
|
822
886
|
declare function maskComments(content: string): string;
|
|
887
|
+
/**
|
|
888
|
+
* Replace every closed `/* … *\/` block comment with `replace(comment)`.
|
|
889
|
+
* Same output as `content.replace(/\/\*[\s\S]*?\*\//g, replace)`, in linear
|
|
890
|
+
* time.
|
|
891
|
+
*
|
|
892
|
+
* WHY NOT THAT REGEX. The lazy `[\s\S]*?` scans to the end of the file for
|
|
893
|
+
* every `/*` that has no closer, so a payload of unclosed `/*` lines costs
|
|
894
|
+
* O(n²): about 1.6s per caller on 256KB, and maskComments has many callers.
|
|
895
|
+
* Here each `/*` costs one indexOf for its closer. When there is none, no
|
|
896
|
+
* later `/*` can be closed either (its closer would have been found first),
|
|
897
|
+
* so the rest of the file is left as it is, which is what the regex does.
|
|
898
|
+
*/
|
|
899
|
+
declare function replaceBlockComments(content: string, replace: (comment: string) => string): string;
|
|
823
900
|
/**
|
|
824
901
|
* Return the source of the handler enclosing `index`, or null if none is found.
|
|
825
902
|
*
|
|
@@ -879,6 +956,16 @@ declare function isInsideFixMessage(content: string, matchIndex: number): boolea
|
|
|
879
956
|
*/
|
|
880
957
|
declare function filterSilenced(matches: RuleMatch[], content: string, ruleId: string): RuleMatch[];
|
|
881
958
|
declare function findMatches(content: string, pattern: RegExp, rule: Omit<CustomRule, "check">, filePath: string, fixTemplate?: (match: RegExpExecArray) => string): RuleMatch[];
|
|
959
|
+
/**
|
|
960
|
+
* findMatches for a matcher that is not a single RegExp — one a regex can
|
|
961
|
+
* only express with super-linear backtracking. `found` yields the matches'
|
|
962
|
+
* start indices in increasing order, as RegExp#exec would; the comment and
|
|
963
|
+
* fix-message skips, line numbers and the per-file cap are findMatches' own,
|
|
964
|
+
* so a rule moved off a regex reports exactly what the regex reported.
|
|
965
|
+
*/
|
|
966
|
+
declare function findMatchesAt<M extends {
|
|
967
|
+
index: number;
|
|
968
|
+
}>(content: string, found: Iterable<M>, rule: Omit<CustomRule, "check">, filePath: string, fixTemplate?: (match: M) => string): RuleMatch[];
|
|
882
969
|
/**
|
|
883
970
|
* Build a RuleMatch from an AST-derived location. Mirrors findMatches' output
|
|
884
971
|
* shape so AST-based rules can be mixed into the same Finding stream. `line`
|
|
@@ -891,6 +978,47 @@ declare function tryParse(content: string, filePath: string): {
|
|
|
891
978
|
} | null;
|
|
892
979
|
declare const hardcodedSecrets: CustomRule;
|
|
893
980
|
declare const exposedEnvFile: CustomRule;
|
|
981
|
+
/**
|
|
982
|
+
* Blank the parts of a file that LOOK like caller authentication but are the
|
|
983
|
+
* server authenticating ITSELF to somebody else, or chat-message plumbing.
|
|
984
|
+
*
|
|
985
|
+
* WHY THIS EXISTS. An AI chat endpoint is the most common server function an
|
|
986
|
+
* AI app builder writes, and every one of them contains
|
|
987
|
+
*
|
|
988
|
+
* fetch("https://ai.gateway.lovable.dev/v1/chat/completions", {
|
|
989
|
+
* headers: { Authorization: `Bearer ${LOVABLE_API_KEY}` },
|
|
990
|
+
* body: JSON.stringify({ messages: [{ role: "user", content }] }),
|
|
991
|
+
* })
|
|
992
|
+
*
|
|
993
|
+
* The outbound `Authorization: Bearer …` header matched VC003's `bearer`,
|
|
994
|
+
* `authorization` and strong `bearer\s` patterns, and `role: "user"` matched
|
|
995
|
+
* its `user` hint, so an endpoint that lets anyone on the internet spend the
|
|
996
|
+
* owner's AI credits was reported as authenticated. Neither says anything
|
|
997
|
+
* about who is CALLING the endpoint.
|
|
998
|
+
*
|
|
999
|
+
* What is blanked:
|
|
1000
|
+
* - `role: "user" | "assistant" | "system" | …` literals;
|
|
1001
|
+
* - object literals passed as request headers (`headers: { … }`,
|
|
1002
|
+
* `headers = { … }`, `new Headers({ … })`), unless the object forwards
|
|
1003
|
+
* the inbound request's credential (see INBOUND_CREDENTIAL_READ_RE), or
|
|
1004
|
+
* a variable bound to one (see credentialValueReadsCaller);
|
|
1005
|
+
* - `headers.set("Authorization", …)` style calls building outbound headers,
|
|
1006
|
+
* with the same exception;
|
|
1007
|
+
* - SDK key configuration, `apiKey: process.env.X` / `Deno.env.get("X")`.
|
|
1008
|
+
*
|
|
1009
|
+
* What is NOT blanked, on purpose: anything that reads the inbound request
|
|
1010
|
+
* (`req.headers.get("Authorization")`, `getUser(token)`, a 401 branch). Those
|
|
1011
|
+
* are the evidence the rule is looking for.
|
|
1012
|
+
*
|
|
1013
|
+
* Offset-preserving (every blanked character becomes a space, newlines are
|
|
1014
|
+
* kept), so the result can stand in for the input in code that slices by
|
|
1015
|
+
* index or reports line numbers.
|
|
1016
|
+
*
|
|
1017
|
+
* Linear: every regex here is bounded, and the brace scan is capped both per
|
|
1018
|
+
* object and in the number of objects examined. Past the cap the remaining
|
|
1019
|
+
* objects are left as they are, which can only suppress a finding.
|
|
1020
|
+
*/
|
|
1021
|
+
declare function maskOutboundAuthNoise(code: string): string;
|
|
894
1022
|
declare const missingAuthMiddleware: CustomRule;
|
|
895
1023
|
declare const supabaseNoRLS: CustomRule;
|
|
896
1024
|
declare const stripeWebhookUnprotected: CustomRule;
|
|
@@ -986,7 +1114,7 @@ project?: ProjectContext): Finding[];
|
|
|
986
1114
|
* CLI should have to import to print one.
|
|
987
1115
|
*
|
|
988
1116
|
* Since 2.0.0 the Pro rules are not in this package at all — they live in the
|
|
989
|
-
* private packages/pro-rules — so this package CANNOT compute
|
|
1117
|
+
* private packages/pro-rules — so this package CANNOT compute 193 or 223: the
|
|
990
1118
|
* arrays those numbers describe do not exist here. Literals are the only way
|
|
991
1119
|
* to publish them.
|
|
992
1120
|
*
|
|
@@ -1000,9 +1128,9 @@ project?: ProjectContext): Finding[];
|
|
|
1000
1128
|
/** Rules any caller gets, including anonymous and free-tier CLI users. */
|
|
1001
1129
|
declare const FREE_RULE_COUNT = 30;
|
|
1002
1130
|
/** Rules gated behind a paid plan and served from the API, never bundled. */
|
|
1003
|
-
declare const PRO_RULE_COUNT =
|
|
1131
|
+
declare const PRO_RULE_COUNT = 193;
|
|
1004
1132
|
/** The full catalog. FREE_RULE_COUNT + PRO_RULE_COUNT, asserted in the test. */
|
|
1005
|
-
declare const TOTAL_RULE_COUNT =
|
|
1133
|
+
declare const TOTAL_RULE_COUNT = 223;
|
|
1006
1134
|
|
|
1007
1135
|
interface FilteredFinding {
|
|
1008
1136
|
finding: Finding;
|
|
@@ -1369,4 +1497,4 @@ input: {
|
|
|
1369
1497
|
content: string;
|
|
1370
1498
|
}[] | QualityContext, rules?: QualityRule[]): Finding[];
|
|
1371
1499
|
|
|
1372
|
-
export { type AIFilterResult, type AppRoute, type BuilderFingerprint, CHECKABLE_CLAIMS, type Confidence, type CustomRule, type DetectedFramework, type ExposedConfig, type Exposure, FREE_RULE_COUNT, type FilteredFinding, type Finding, type GradeOptions, type GradeResult, type HeaderFinding, INTENT_EXPECTATIONS, type IntentExpectation, type IntentMismatch, type IntentOrigin, type IntentReport, type IntentStatement, MODEL_ANALYSIS, MODEL_POLICY_REVIEWED, MODEL_REVIEW_INTERVAL_DAYS, MODEL_TEMPERATURE, MODEL_TRIAGE, NON_APP_PATH_PATTERNS, PRO_RULE_COUNT, type ParsedFile, type ProjectContext, QUALITY_EXAMPLES, type QualityContext, type QualityExample, type QualityFile, type QualityHit, type QualityRule, RULE_IMPACTS, type RouteFramework, type RouteTable, type RuleMatch, type SecurityGrade, type Severity, TEST_FILE_PATTERN, TOTAL_RULE_COUNT, type TaintMap, type TargetCheck, type VibePlatform, allRules, assessHeaders, astMatch, buildProjectContext, buildQualityContext, buildTaintMap, calculateGrade, callSpreads, checkIntent, classifyExposure, classifyStatement, clientSideAuth, complianceMap, consoleLogProduction, corsWildcard, dangerousInnerHTML, detectBuilder, detectExposedConfig, detectFramework, detectPlatform, disabledTLSVerification, emptyCatchBlock, enclosingHandler, envNotGitignored, evalUsage, exposedAuthSecret, exposedDebugMode, exposedEnvFile, exposedStackTraces, extractRoutes, extractScriptUrls, filterFalsePositives, filterSilenced, findMatches, findSourceMapRefs, freeRules, getObjectProperty, getSnippet, hardcodedJWTSecret, hardcodedSecrets, harvestIntent, insecureCookies, insecureRandomness, isCalleeNamed, isClientTarget, isCommentLine, isInlineSilenced, isInsideFixMessage, isLineSilenced, isMethodCall, isPrivateAddress, isServerSideFile, isServerTarget, isTestFile, isVendoredFinding, isVendoredPath, lineNumberAt, lineTextAt, maskComments, missingAuthMiddleware, missingCSP, missingErrorBoundary, missingHTTPS, missingLockFile, nextPublicSecret, noRateLimiting, normalizeScanPath, parseFile, parseScanTarget, parseSupabaseConfig, qualityRules, routeForFile, runCustomRules, scanEntropy, scanQuality, sqlInjection, stripeWebhookUnprotected, supabaseFunctionName, supabaseNoRLS, todoLeftInCode, tryParse, unmeasuredQualityRules, unvalidatedRedirect, vendoredReason, visitBinary, visitCalls, weakHashing, xssVulnerability };
|
|
1500
|
+
export { type AIFilterResult, type AppRoute, type BuilderFingerprint, CHECKABLE_CLAIMS, type Confidence, type CustomRule, DOTENV_ASSIGN_RE, type DetectedFramework, type ExposedConfig, type Exposure, FREE_RULE_COUNT, type FilteredFinding, type Finding, type GradeOptions, type GradeResult, type HeaderFinding, INTENT_EXPECTATIONS, type IntentExpectation, type IntentMismatch, type IntentOrigin, type IntentReport, type IntentStatement, MODEL_ANALYSIS, MODEL_POLICY_REVIEWED, MODEL_REVIEW_INTERVAL_DAYS, MODEL_TEMPERATURE, MODEL_TRIAGE, NON_APP_PATH_PATTERNS, PRO_RULE_COUNT, PUBLIC_ENV_PREFIX_RE, type ParsedFile, type ProjectContext, QUALITY_EXAMPLES, type QualityContext, type QualityExample, type QualityFile, type QualityHit, type QualityRule, RULE_IMPACTS, type RouteFramework, type RouteTable, type RuleMatch, type SecurityGrade, type Severity, TEST_FILE_PATTERN, TOTAL_RULE_COUNT, type TaintMap, type TargetCheck, type VibePlatform, allRules, assessHeaders, astMatch, buildProjectContext, buildQualityContext, buildTaintMap, calculateGrade, callSpreads, checkIntent, classifyExposure, classifyPublicEnvVar, classifyStatement, clientSideAuth, complianceMap, consoleLogProduction, corsWildcard, dangerousInnerHTML, detectBuilder, detectExposedConfig, detectFramework, detectPlatform, disabledTLSVerification, dotenvValue, emptyCatchBlock, enclosingHandler, envNotGitignored, evalUsage, exposedAuthSecret, exposedDebugMode, exposedEnvFile, exposedStackTraces, extractRoutes, extractScriptUrls, filterFalsePositives, filterSilenced, findMatches, findMatchesAt, findSourceMapRefs, freeRules, getObjectProperty, getSnippet, hardcodedJWTSecret, hardcodedSecrets, harvestIntent, insecureCookies, insecureRandomness, isCalleeNamed, isClientTarget, isCommentLine, isDotenvPath, isInlineSilenced, isInsideFixMessage, isLineSilenced, isMethodCall, isPrivateAddress, isServerSideFile, isServerTarget, isTestFile, isVendoredFinding, isVendoredPath, lineNumberAt, lineTextAt, maskComments, maskOutboundAuthNoise, missingAuthMiddleware, missingCSP, missingErrorBoundary, missingHTTPS, missingLockFile, nextPublicSecret, noRateLimiting, normalizeScanPath, parseFile, parseScanTarget, parseSupabaseConfig, qualityRules, replaceBlockComments, routeForFile, runCustomRules, scanEntropy, scanQuality, sqlInjection, stripeWebhookUnprotected, supabaseFunctionName, supabaseNoRLS, todoLeftInCode, tryParse, unmeasuredQualityRules, unvalidatedRedirect, vendoredReason, visitBinary, visitCalls, weakHashing, xssVulnerability };
|