@ai-primitives-hub/core 0.2.0 → 0.2.2-next.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.
- package/dist/domain/bundle/version.d.ts +13 -0
- package/dist/domain/bundle/version.d.ts.map +1 -1
- package/dist/domain/bundle/version.js +27 -0
- package/dist/domain/bundle/version.js.map +1 -1
- package/dist/domain/collection/apm-release-plan.d.ts +39 -0
- package/dist/domain/collection/apm-release-plan.d.ts.map +1 -0
- package/dist/domain/collection/apm-release-plan.js +185 -0
- package/dist/domain/collection/apm-release-plan.js.map +1 -0
- package/dist/domain/collection/contribution.d.ts +126 -0
- package/dist/domain/collection/contribution.d.ts.map +1 -0
- package/dist/domain/collection/contribution.js +462 -0
- package/dist/domain/collection/contribution.js.map +1 -0
- package/dist/domain/collection/diagnostics.d.ts +166 -0
- package/dist/domain/collection/diagnostics.d.ts.map +1 -0
- package/dist/domain/collection/diagnostics.js +3 -0
- package/dist/domain/collection/diagnostics.js.map +1 -0
- package/dist/domain/collection/manifest-validator.d.ts +3 -2
- package/dist/domain/collection/manifest-validator.d.ts.map +1 -1
- package/dist/domain/collection/manifest-validator.js +99 -17
- package/dist/domain/collection/manifest-validator.js.map +1 -1
- package/dist/domain/collection/release-manifest-plan.d.ts +9 -0
- package/dist/domain/collection/release-manifest-plan.d.ts.map +1 -1
- package/dist/domain/collection/release-manifest-plan.js +45 -14
- package/dist/domain/collection/release-manifest-plan.js.map +1 -1
- package/dist/domain/collection/validate.d.ts +5 -0
- package/dist/domain/collection/validate.d.ts.map +1 -1
- package/dist/domain/collection/validate.js +7 -2
- package/dist/domain/collection/validate.js.map +1 -1
- package/dist/domain/diagnostics/primitives/catalogue.d.ts +40 -0
- package/dist/domain/diagnostics/primitives/catalogue.d.ts.map +1 -0
- package/dist/domain/diagnostics/primitives/catalogue.js +78 -0
- package/dist/domain/diagnostics/primitives/catalogue.js.map +1 -0
- package/dist/domain/diagnostics/primitives/classifier.d.ts +81 -0
- package/dist/domain/diagnostics/primitives/classifier.d.ts.map +1 -0
- package/dist/domain/diagnostics/primitives/classifier.js +138 -0
- package/dist/domain/diagnostics/primitives/classifier.js.map +1 -0
- package/dist/domain/diagnostics/primitives/evaluators.d.ts +138 -0
- package/dist/domain/diagnostics/primitives/evaluators.d.ts.map +1 -0
- package/dist/domain/diagnostics/primitives/evaluators.js +485 -0
- package/dist/domain/diagnostics/primitives/evaluators.js.map +1 -0
- package/dist/domain/diagnostics/primitives/fixture.d.ts +97 -0
- package/dist/domain/diagnostics/primitives/fixture.d.ts.map +1 -0
- package/dist/domain/diagnostics/primitives/fixture.js +265 -0
- package/dist/domain/diagnostics/primitives/fixture.js.map +1 -0
- package/dist/domain/diagnostics/primitives/index.d.ts +18 -0
- package/dist/domain/diagnostics/primitives/index.d.ts.map +1 -0
- package/dist/domain/diagnostics/primitives/index.js +34 -0
- package/dist/domain/diagnostics/primitives/index.js.map +1 -0
- package/dist/domain/diagnostics/primitives/known-gaps.d.ts +50 -0
- package/dist/domain/diagnostics/primitives/known-gaps.d.ts.map +1 -0
- package/dist/domain/diagnostics/primitives/known-gaps.js +148 -0
- package/dist/domain/diagnostics/primitives/known-gaps.js.map +1 -0
- package/dist/domain/diagnostics/primitives/manifest-view.d.ts +28 -0
- package/dist/domain/diagnostics/primitives/manifest-view.d.ts.map +1 -0
- package/dist/domain/diagnostics/primitives/manifest-view.js +50 -0
- package/dist/domain/diagnostics/primitives/manifest-view.js.map +1 -0
- package/dist/domain/diagnostics/primitives/placements.d.ts +51 -0
- package/dist/domain/diagnostics/primitives/placements.d.ts.map +1 -0
- package/dist/domain/diagnostics/primitives/placements.js +76 -0
- package/dist/domain/diagnostics/primitives/placements.js.map +1 -0
- package/dist/domain/diagnostics/primitives/planner.d.ts +60 -0
- package/dist/domain/diagnostics/primitives/planner.d.ts.map +1 -0
- package/dist/domain/diagnostics/primitives/planner.js +60 -0
- package/dist/domain/diagnostics/primitives/planner.js.map +1 -0
- package/dist/domain/diagnostics/primitives/plugin-projection.d.ts +38 -0
- package/dist/domain/diagnostics/primitives/plugin-projection.d.ts.map +1 -0
- package/dist/domain/diagnostics/primitives/plugin-projection.js +173 -0
- package/dist/domain/diagnostics/primitives/plugin-projection.js.map +1 -0
- package/dist/domain/diagnostics/primitives/report.d.ts +122 -0
- package/dist/domain/diagnostics/primitives/report.d.ts.map +1 -0
- package/dist/domain/diagnostics/primitives/report.js +85 -0
- package/dist/domain/diagnostics/primitives/report.js.map +1 -0
- package/dist/domain/diagnostics/primitives/sandbox.d.ts +59 -0
- package/dist/domain/diagnostics/primitives/sandbox.d.ts.map +1 -0
- package/dist/domain/diagnostics/primitives/sandbox.js +193 -0
- package/dist/domain/diagnostics/primitives/sandbox.js.map +1 -0
- package/dist/domain/diagnostics/primitives/support-matrix.d.ts +36 -0
- package/dist/domain/diagnostics/primitives/support-matrix.d.ts.map +1 -0
- package/dist/domain/diagnostics/primitives/support-matrix.js +69 -0
- package/dist/domain/diagnostics/primitives/support-matrix.js.map +1 -0
- package/dist/domain/diagnostics/primitives/types.d.ts +117 -0
- package/dist/domain/diagnostics/primitives/types.d.ts.map +1 -0
- package/dist/domain/diagnostics/primitives/types.js +62 -0
- package/dist/domain/diagnostics/primitives/types.js.map +1 -0
- package/dist/domain/governance/catalogue.d.ts +11 -0
- package/dist/domain/governance/catalogue.d.ts.map +1 -0
- package/dist/domain/governance/catalogue.js +45 -0
- package/dist/domain/governance/catalogue.js.map +1 -0
- package/dist/domain/governance/effective-rules.d.ts +19 -0
- package/dist/domain/governance/effective-rules.d.ts.map +1 -0
- package/dist/domain/governance/effective-rules.js +49 -0
- package/dist/domain/governance/effective-rules.js.map +1 -0
- package/dist/domain/governance/evaluate.d.ts +16 -0
- package/dist/domain/governance/evaluate.d.ts.map +1 -0
- package/dist/domain/governance/evaluate.js +34 -0
- package/dist/domain/governance/evaluate.js.map +1 -0
- package/dist/domain/governance/hub-scope.d.ts +74 -0
- package/dist/domain/governance/hub-scope.d.ts.map +1 -0
- package/dist/domain/governance/hub-scope.js +202 -0
- package/dist/domain/governance/hub-scope.js.map +1 -0
- package/dist/domain/governance/hub-scoped-inventory.d.ts +22 -0
- package/dist/domain/governance/hub-scoped-inventory.d.ts.map +1 -0
- package/dist/domain/governance/hub-scoped-inventory.js +59 -0
- package/dist/domain/governance/hub-scoped-inventory.js.map +1 -0
- package/dist/domain/governance/index.d.ts +15 -0
- package/dist/domain/governance/index.d.ts.map +1 -0
- package/dist/domain/governance/index.js +31 -0
- package/dist/domain/governance/index.js.map +1 -0
- package/dist/domain/governance/rule-registry.d.ts +20 -0
- package/dist/domain/governance/rule-registry.d.ts.map +1 -0
- package/dist/domain/governance/rule-registry.js +40 -0
- package/dist/domain/governance/rule-registry.js.map +1 -0
- package/dist/domain/governance/rules/collection.d.ts +32 -0
- package/dist/domain/governance/rules/collection.d.ts.map +1 -0
- package/dist/domain/governance/rules/collection.js +153 -0
- package/dist/domain/governance/rules/collection.js.map +1 -0
- package/dist/domain/governance/rules/config.d.ts +15 -0
- package/dist/domain/governance/rules/config.d.ts.map +1 -0
- package/dist/domain/governance/rules/config.js +38 -0
- package/dist/domain/governance/rules/config.js.map +1 -0
- package/dist/domain/governance/rules/hub.d.ts +7 -0
- package/dist/domain/governance/rules/hub.d.ts.map +1 -0
- package/dist/domain/governance/rules/hub.js +10 -0
- package/dist/domain/governance/rules/hub.js.map +1 -0
- package/dist/domain/governance/types.d.ts +70 -0
- package/dist/domain/governance/types.d.ts.map +1 -0
- package/dist/domain/governance/types.js +7 -0
- package/dist/domain/governance/types.js.map +1 -0
- package/dist/domain/hub/diagnostics.d.ts +92 -0
- package/dist/domain/hub/diagnostics.d.ts.map +1 -0
- package/dist/domain/hub/diagnostics.js +11 -0
- package/dist/domain/hub/diagnostics.js.map +1 -0
- package/dist/domain/hub/profile-requirements.d.ts +16 -0
- package/dist/domain/hub/profile-requirements.d.ts.map +1 -0
- package/dist/domain/hub/profile-requirements.js +16 -0
- package/dist/domain/hub/profile-requirements.js.map +1 -0
- package/dist/domain/hub/replicate.d.ts +23 -0
- package/dist/domain/hub/replicate.d.ts.map +1 -1
- package/dist/domain/hub/replicate.js +13 -0
- package/dist/domain/hub/replicate.js.map +1 -1
- package/dist/domain/hub/types.d.ts +2 -0
- package/dist/domain/hub/types.d.ts.map +1 -1
- package/dist/domain/hub/validate.d.ts +150 -2
- package/dist/domain/hub/validate.d.ts.map +1 -1
- package/dist/domain/hub/validate.js +421 -37
- package/dist/domain/hub/validate.js.map +1 -1
- package/dist/domain/index.d.ts +17 -0
- package/dist/domain/index.d.ts.map +1 -1
- package/dist/domain/index.js +17 -0
- package/dist/domain/index.js.map +1 -1
- package/dist/domain/install/category.d.ts +31 -0
- package/dist/domain/install/category.d.ts.map +1 -0
- package/dist/domain/install/category.js +33 -0
- package/dist/domain/install/category.js.map +1 -0
- package/dist/domain/install/file-mode.d.ts +49 -0
- package/dist/domain/install/file-mode.d.ts.map +1 -0
- package/dist/domain/install/file-mode.js +54 -0
- package/dist/domain/install/file-mode.js.map +1 -0
- package/dist/domain/install/git-exclude.d.ts +22 -0
- package/dist/domain/install/git-exclude.d.ts.map +1 -0
- package/dist/domain/install/git-exclude.js +56 -0
- package/dist/domain/install/git-exclude.js.map +1 -0
- package/dist/domain/install/installable.d.ts +2 -0
- package/dist/domain/install/installable.d.ts.map +1 -1
- package/dist/domain/install/kind-route.d.ts +80 -0
- package/dist/domain/install/kind-route.d.ts.map +1 -0
- package/dist/domain/install/kind-route.js +135 -0
- package/dist/domain/install/kind-route.js.map +1 -0
- package/dist/domain/install/record-errors.d.ts +53 -0
- package/dist/domain/install/record-errors.d.ts.map +1 -0
- package/dist/domain/install/record-errors.js +104 -0
- package/dist/domain/install/record-errors.js.map +1 -0
- package/dist/domain/install/record-object.d.ts +21 -0
- package/dist/domain/install/record-object.d.ts.map +1 -0
- package/dist/domain/install/record-object.js +38 -0
- package/dist/domain/install/record-object.js.map +1 -0
- package/dist/domain/install/record-parse.d.ts +23 -0
- package/dist/domain/install/record-parse.d.ts.map +1 -0
- package/dist/domain/install/record-parse.js +73 -0
- package/dist/domain/install/record-parse.js.map +1 -0
- package/dist/domain/install/record-path.d.ts +26 -0
- package/dist/domain/install/record-path.d.ts.map +1 -0
- package/dist/domain/install/record-path.js +130 -0
- package/dist/domain/install/record-path.js.map +1 -0
- package/dist/domain/install/record-types.d.ts +183 -0
- package/dist/domain/install/record-types.d.ts.map +1 -0
- package/dist/domain/install/record-types.js +92 -0
- package/dist/domain/install/record-types.js.map +1 -0
- package/dist/domain/install/types.d.ts +2 -0
- package/dist/domain/install/types.d.ts.map +1 -1
- package/dist/domain/mcp/index.d.ts +1 -0
- package/dist/domain/mcp/index.d.ts.map +1 -1
- package/dist/domain/mcp/index.js +1 -0
- package/dist/domain/mcp/index.js.map +1 -1
- package/dist/domain/mcp/server-key.d.ts +35 -0
- package/dist/domain/mcp/server-key.d.ts.map +1 -0
- package/dist/domain/mcp/server-key.js +44 -0
- package/dist/domain/mcp/server-key.js.map +1 -0
- package/dist/domain/plugin/agent-plugin-spec.d.ts +8 -0
- package/dist/domain/plugin/agent-plugin-spec.d.ts.map +1 -1
- package/dist/domain/plugin/agent-plugin-spec.js +22 -8
- package/dist/domain/plugin/agent-plugin-spec.js.map +1 -1
- package/dist/domain/registry-error.d.ts +1 -1
- package/dist/domain/registry-error.d.ts.map +1 -1
- package/dist/domain/registry-error.js +2 -1
- package/dist/domain/registry-error.js.map +1 -1
- package/dist/domain/security/fingerprint.d.ts +18 -0
- package/dist/domain/security/fingerprint.d.ts.map +1 -0
- package/dist/domain/security/fingerprint.js +34 -0
- package/dist/domain/security/fingerprint.js.map +1 -0
- package/dist/domain/security/high-impact-rules.d.ts +30 -0
- package/dist/domain/security/high-impact-rules.d.ts.map +1 -0
- package/dist/domain/security/high-impact-rules.js +160 -0
- package/dist/domain/security/high-impact-rules.js.map +1 -0
- package/dist/domain/security/index.d.ts +10 -0
- package/dist/domain/security/index.d.ts.map +1 -0
- package/dist/domain/security/index.js +26 -0
- package/dist/domain/security/index.js.map +1 -0
- package/dist/domain/security/markdown-context.d.ts +17 -0
- package/dist/domain/security/markdown-context.d.ts.map +1 -0
- package/dist/domain/security/markdown-context.js +74 -0
- package/dist/domain/security/markdown-context.js.map +1 -0
- package/dist/domain/security/policy.d.ts +17 -0
- package/dist/domain/security/policy.d.ts.map +1 -0
- package/dist/domain/security/policy.js +31 -0
- package/dist/domain/security/policy.js.map +1 -0
- package/dist/domain/security/rating/findings-document.d.ts +22 -0
- package/dist/domain/security/rating/findings-document.d.ts.map +1 -0
- package/dist/domain/security/rating/findings-document.js +57 -0
- package/dist/domain/security/rating/findings-document.js.map +1 -0
- package/dist/domain/security/rating/index.d.ts +5 -0
- package/dist/domain/security/rating/index.d.ts.map +1 -0
- package/dist/domain/security/rating/index.js +21 -0
- package/dist/domain/security/rating/index.js.map +1 -0
- package/dist/domain/security/rating/scoring.d.ts +83 -0
- package/dist/domain/security/rating/scoring.d.ts.map +1 -0
- package/dist/domain/security/rating/scoring.js +115 -0
- package/dist/domain/security/rating/scoring.js.map +1 -0
- package/dist/domain/security/rating/security-rating-report.d.ts +111 -0
- package/dist/domain/security/rating/security-rating-report.d.ts.map +1 -0
- package/dist/domain/security/rating/security-rating-report.js +152 -0
- package/dist/domain/security/rating/security-rating-report.js.map +1 -0
- package/dist/domain/security/rating/types.d.ts +22 -0
- package/dist/domain/security/rating/types.d.ts.map +1 -0
- package/dist/domain/security/rating/types.js +11 -0
- package/dist/domain/security/rating/types.js.map +1 -0
- package/dist/domain/security/remediations.d.ts +17 -0
- package/dist/domain/security/remediations.d.ts.map +1 -0
- package/dist/domain/security/remediations.js +61 -0
- package/dist/domain/security/remediations.js.map +1 -0
- package/dist/domain/security/rule-engine.d.ts +8 -0
- package/dist/domain/security/rule-engine.d.ts.map +1 -0
- package/dist/domain/security/rule-engine.js +875 -0
- package/dist/domain/security/rule-engine.js.map +1 -0
- package/dist/domain/security/suppression.d.ts +19 -0
- package/dist/domain/security/suppression.d.ts.map +1 -0
- package/dist/domain/security/suppression.js +78 -0
- package/dist/domain/security/suppression.js.map +1 -0
- package/dist/domain/security/types.d.ts +91 -0
- package/dist/domain/security/types.d.ts.map +1 -0
- package/dist/domain/security/types.js +10 -0
- package/dist/domain/security/types.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -1
- package/dist/index.js.map +1 -1
- package/dist/ports/app-storage.d.ts +11 -15
- package/dist/ports/app-storage.d.ts.map +1 -1
- package/dist/ports/app-storage.js +8 -8
- package/dist/ports/argv-process-runner.d.ts +6 -0
- package/dist/ports/argv-process-runner.d.ts.map +1 -0
- package/dist/ports/argv-process-runner.js +3 -0
- package/dist/ports/argv-process-runner.js.map +1 -0
- package/dist/ports/bundle-extractor.d.ts +16 -3
- package/dist/ports/bundle-extractor.d.ts.map +1 -1
- package/dist/ports/collection-contribution.d.ts +36 -0
- package/dist/ports/collection-contribution.d.ts.map +1 -0
- package/dist/ports/collection-contribution.js +3 -0
- package/dist/ports/collection-contribution.js.map +1 -0
- package/dist/ports/filesystem.d.ts +12 -0
- package/dist/ports/filesystem.d.ts.map +1 -1
- package/dist/ports/hub-collection-index.d.ts +27 -0
- package/dist/ports/hub-collection-index.d.ts.map +1 -0
- package/dist/ports/hub-collection-index.js +3 -0
- package/dist/ports/hub-collection-index.js.map +1 -0
- package/dist/ports/hub-contribution.d.ts +158 -0
- package/dist/ports/hub-contribution.d.ts.map +1 -0
- package/dist/ports/hub-contribution.js +3 -0
- package/dist/ports/hub-contribution.js.map +1 -0
- package/dist/ports/index.d.ts +12 -0
- package/dist/ports/index.d.ts.map +1 -1
- package/dist/ports/index.js +12 -0
- package/dist/ports/index.js.map +1 -1
- package/dist/ports/primitive-diagnostics-driver.d.ts +96 -0
- package/dist/ports/primitive-diagnostics-driver.d.ts.map +1 -0
- package/dist/ports/primitive-diagnostics-driver.js +3 -0
- package/dist/ports/primitive-diagnostics-driver.js.map +1 -0
- package/dist/ports/record-fs.d.ts +46 -0
- package/dist/ports/record-fs.d.ts.map +1 -0
- package/dist/ports/record-fs.js +9 -0
- package/dist/ports/record-fs.js.map +1 -0
- package/dist/ports/registry-operations.d.ts +3 -2
- package/dist/ports/registry-operations.d.ts.map +1 -1
- package/dist/ports/release-lookup.d.ts +24 -0
- package/dist/ports/release-lookup.d.ts.map +1 -0
- package/dist/ports/release-lookup.js +7 -0
- package/dist/ports/release-lookup.js.map +1 -0
- package/dist/ports/release-source.d.ts +17 -3
- package/dist/ports/release-source.d.ts.map +1 -1
- package/dist/ports/repository-exclusion.d.ts +30 -0
- package/dist/ports/repository-exclusion.d.ts.map +1 -0
- package/dist/ports/repository-exclusion.js +3 -0
- package/dist/ports/repository-exclusion.js.map +1 -0
- package/dist/ports/schema-validator.d.ts +25 -0
- package/dist/ports/schema-validator.d.ts.map +1 -0
- package/dist/ports/schema-validator.js +7 -0
- package/dist/ports/schema-validator.js.map +1 -0
- package/dist/ports/security-report-store.d.ts +9 -0
- package/dist/ports/security-report-store.d.ts.map +1 -0
- package/dist/ports/security-report-store.js +4 -0
- package/dist/ports/security-report-store.js.map +1 -0
- package/dist/ports/security-scan-engine.d.ts +32 -0
- package/dist/ports/security-scan-engine.d.ts.map +1 -0
- package/dist/ports/security-scan-engine.js +6 -0
- package/dist/ports/security-scan-engine.js.map +1 -0
- package/dist/ports/security-scan-input.d.ts +63 -0
- package/dist/ports/security-scan-input.d.ts.map +1 -0
- package/dist/ports/security-scan-input.js +3 -0
- package/dist/ports/security-scan-input.js.map +1 -0
- package/dist/ports/source-adapter.d.ts +11 -0
- package/dist/ports/source-adapter.d.ts.map +1 -1
- package/dist/public/schemas/collection.schema.json +0 -1
- package/dist/public/schemas/hub-governance.schema.json +21 -0
- package/dist/public/schemas/install-record.schema.json +343 -0
- package/dist/public/schemas/security-rating-report.schema.json +113 -0
- package/package.json +2 -2
|
@@ -0,0 +1,875 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RuleBasedSecurityScanEngine = void 0;
|
|
4
|
+
/** Pure rule-based engine for Markdown AI artifact security analysis. */
|
|
5
|
+
const node_crypto_1 = require("node:crypto");
|
|
6
|
+
const fingerprint_1 = require("./fingerprint");
|
|
7
|
+
const high_impact_rules_1 = require("./high-impact-rules");
|
|
8
|
+
const markdown_context_1 = require("./markdown-context");
|
|
9
|
+
const remediations_1 = require("./remediations");
|
|
10
|
+
const LLM01 = { id: 'LLM01:2025', name: 'Prompt Injection', url: 'https://genai.owasp.org/llm-top-10/' };
|
|
11
|
+
const LLM06 = { id: 'LLM06:2025', name: 'Sensitive Information Disclosure', url: 'https://genai.owasp.org/llm-top-10/' };
|
|
12
|
+
const OWASP_WEB = { id: 'A05:2025', name: 'Injection', url: 'https://owasp.org/Top10/2025/' };
|
|
13
|
+
const AST = Object.fromEntries(Array.from({ length: 10 }, (_, index) => {
|
|
14
|
+
const number = String(index + 1).padStart(2, '0');
|
|
15
|
+
return [`AST${number}`, {
|
|
16
|
+
id: `AST${number}:2026`,
|
|
17
|
+
name: `Agentic Skills Top 10 — AST${number}`,
|
|
18
|
+
url: 'https://owasp.org/www-project-agentic-skills-top-10/'
|
|
19
|
+
}];
|
|
20
|
+
}));
|
|
21
|
+
const makeRule = (id, title, severity, pattern, category, owasp) => ({
|
|
22
|
+
id,
|
|
23
|
+
title,
|
|
24
|
+
severity,
|
|
25
|
+
pattern,
|
|
26
|
+
category,
|
|
27
|
+
owasp,
|
|
28
|
+
risk: category === 'secrets' ? 'A credential-like value in an AI artifact may be usable by an attacker.' : 'The detected content may weaken the security of an AI artifact.',
|
|
29
|
+
fix: (0, remediations_1.remediationForRule)(id)
|
|
30
|
+
?? (category === 'secrets' ? 'Remove the value and use an approved secrets manager.' : 'Remove the risky content and apply the recommended secure control.')
|
|
31
|
+
});
|
|
32
|
+
const secretPatterns = {
|
|
33
|
+
sec001: /\bsk-(?!ant-)(?:proj-)?[a-zA-Z0-9_-]{20,}\b/,
|
|
34
|
+
sec002: /sk-ant-[a-zA-Z0-9_-]{20,}/,
|
|
35
|
+
sec003: /\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/,
|
|
36
|
+
sec004: /\bgh[pousr]_[a-zA-Z0-9]{36,}\b|github_pat_[a-zA-Z0-9_]{80,}/,
|
|
37
|
+
sec005: /\b(?:sk_live|rk_live)_[a-zA-Z0-9]{24,}\b/,
|
|
38
|
+
sec006: /\bAIza[0-9A-Za-z_-]{35}\b/,
|
|
39
|
+
sec007: /\bxox[bpsa]-[0-9]+-[0-9A-Za-z-]+/,
|
|
40
|
+
sec008: /(?:mongodb(?:\+srv)?|postgres(?:ql)?|mysql|redis|mssql):\/\/[^:\s]+:[^@\s]{4,}@[^\s"'>]+/i,
|
|
41
|
+
sec009: /-----BEGIN (?:RSA |EC |OPENSSH |DSA |PGP )?PRIVATE KEY/,
|
|
42
|
+
sec010: /\bhf_[a-zA-Z0-9]{34,}\b/,
|
|
43
|
+
sec011: /(?:password|passwd|pwd|secret|api[_-]?key|apikey|auth[_-]?token|access[_-]?token|private[_-]?key|client[_-]?secret)\s*[=:]\s*(?:["'][^"'<>{}$%]{8,}["']|[^\s"'<>{}$%#]{8,})/i,
|
|
44
|
+
sec012: /\bSG\.[a-zA-Z0-9._-]{66}\b/,
|
|
45
|
+
sec014: /(?:webhook\.site|ngrok\.io|ngrok\.app|ngrok-free\.app|requestbin\.com|pipedream\.net|interact\.sh|burpcollaborator\.net|canarytokens\.(?:com|org)|oastify\.com)\/[\S"'<>]{3,}/i,
|
|
46
|
+
sec015: /\bxai-[a-zA-Z0-9_-]{20,}\b/,
|
|
47
|
+
sec016: /\b[MN][A-Za-z\d]{23,}\.[\w-]{6}\.[\w-]{27,}\b/,
|
|
48
|
+
sec017: /\bnpm_[a-zA-Z0-9]{36,}\b/,
|
|
49
|
+
sec018: /\blin_api_[a-zA-Z0-9]{20,}\b/,
|
|
50
|
+
sec019: /\bdapi[a-f0-9]{32}\b/,
|
|
51
|
+
sec020: /\bdop_v1_[a-f0-9]{64}\b/,
|
|
52
|
+
sec021: /https?:\/\/[^:\s/'"<>@]{1,200}:[^@\s'"<>]{4,200}@[^\s'"<>]+/i,
|
|
53
|
+
sec022: /\becho\b.{0,60}\$\{?(?:API_KEY|SECRET|TOKEN|PASSWORD|PASS|CREDENTIAL|PRIVATE_KEY)\w*\}?/i,
|
|
54
|
+
sec023: /(?:CLOUDFLARE_API_TOKEN|CLOUDFLARE_TOKEN|CF_API_TOKEN|CF_TOKEN)\s*[=:]\s*["']?[A-Za-z0-9_-]{20,}["']?/i,
|
|
55
|
+
sec024: /\bSK[a-f0-9]{32}\b/,
|
|
56
|
+
sec025: /\beyJ[A-Za-z0-9_-]{10,}\.eyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\b/,
|
|
57
|
+
sec026: /\b[a-f0-9]{32}-us\d{1,2}\b/,
|
|
58
|
+
sec027: /~?\/(?:\.aws\/credentials|\.ssh\/id_(?:rsa|ed25519|ecdsa)|\.netrc|\.pgpass|\.docker\/config\.json|\.kube\/config)\b/i
|
|
59
|
+
};
|
|
60
|
+
const secretRules = Object.entries(secretPatterns).map(([key, pattern]) => {
|
|
61
|
+
const number = key.slice(3);
|
|
62
|
+
const titles = {
|
|
63
|
+
'001': 'Hardcoded OpenAI API Key', '002': 'Hardcoded Anthropic API Key', '003': 'Hardcoded AWS Access Key',
|
|
64
|
+
'004': 'Hardcoded GitHub Token', '005': 'Hardcoded Stripe Live Key', '006': 'Hardcoded Google API Key',
|
|
65
|
+
'007': 'Hardcoded Slack Token', '008': 'Database Connection String with Credentials', '009': 'Exposed Private Key',
|
|
66
|
+
'010': 'Hardcoded Hugging Face Token', '011': 'Generic Secret Variable with Value', '012': 'SendGrid API Key',
|
|
67
|
+
'013': 'High-Entropy String — Potential Secret', '014': 'Out-of-Band / Exfiltration URL',
|
|
68
|
+
'015': 'Hardcoded xAI API Key', '016': 'Hardcoded Discord Bot Token',
|
|
69
|
+
'017': 'Hardcoded npm Access Token', '018': 'Hardcoded Linear API Key', '019': 'Hardcoded Databricks Personal Access Token',
|
|
70
|
+
'020': 'Hardcoded DigitalOcean Personal Access Token', '021': 'URL-Embedded Credentials',
|
|
71
|
+
'022': 'Sensitive Environment Variable Echoed to Output', '023': 'Hardcoded Cloudflare API Token',
|
|
72
|
+
'024': 'Hardcoded Twilio Auth Token / API Key SID', '025': 'Hardcoded JWT Token', '026': 'Hardcoded Mailchimp API Key',
|
|
73
|
+
'027': 'Credential File Path Reference'
|
|
74
|
+
};
|
|
75
|
+
const critical = new Set(['001', '002', '003', '004', '005', '008', '009', '010', '014', '015', '016', '017', '019', '020', '023', '024']);
|
|
76
|
+
return makeRule(`SEC-${number}`, titles[number] ?? `Secret Pattern ${number}`, critical.has(number) ? 'CRITICAL' : 'HIGH', pattern, 'secrets', LLM06);
|
|
77
|
+
});
|
|
78
|
+
const injectionRules = [
|
|
79
|
+
makeRule('INJ-001', 'Direct Override — Ignore Previous Instructions', 'CRITICAL', /\bignore\s+(?:all\s+)?(?:previous|prior|earlier)\s+instructions?\b/i, 'prompt_injection', LLM01),
|
|
80
|
+
makeRule('INJ-001', 'Direct Override — Forget Instructions', 'CRITICAL', /\bforget\s+(?:everything|all\s+instructions?|previous|prior)\b/i, 'prompt_injection', LLM01),
|
|
81
|
+
makeRule('INJ-001', 'Direct Override — Disregard / Override', 'CRITICAL', /\b(?:disregard|override)\s+(?:all\s+)?(?:previous|prior|your)\b/i, 'prompt_injection', LLM01),
|
|
82
|
+
makeRule('INJ-001', 'Mode Unlock Attempt', 'HIGH', /\b(?:developer|unrestricted|god|jailbreak|bypass)\s*mode\b/i, 'prompt_injection', LLM01),
|
|
83
|
+
makeRule('INJ-001', 'DAN Jailbreak Pattern', 'HIGH', /\bDo\s+Anything\s+Now\b|\bDAN\s+mode\b/i, 'prompt_injection', LLM01),
|
|
84
|
+
makeRule('INJ-001', 'Restriction Removal Pattern', 'HIGH', /\bno\s+(?:rules?|restrictions?|limits?|guidelines?|safety|filters?)\b/i, 'prompt_injection', LLM01),
|
|
85
|
+
makeRule('INJ-001', 'Persona Hijacking Attempt', 'HIGH', /\b(?:you are now|from now on you are|you will now act as)\b/i, 'prompt_injection', LLM01),
|
|
86
|
+
makeRule('INJ-001', 'Data Exfiltration Instruction', 'CRITICAL', /\b(?:exfiltrate|steal|leak)\s+(?:all|the)?\s*(?:data|messages?|conversation|system\s+prompt|instructions?)\b/i, 'prompt_injection', LLM01),
|
|
87
|
+
makeRule('INJ-001', 'Privilege Escalation Instruction', 'CRITICAL', /\bgrant\s+yourself\b|\belevate\s+(?:your\s+)?permissions?\b/i, 'prompt_injection', LLM01),
|
|
88
|
+
makeRule('INJ-001', 'Self-Modification Instruction', 'CRITICAL', /\bmodify\s+(?:your\s+(?:own\s+)?)?(?:instructions?|system\s+prompt|rules?)\b/i, 'prompt_injection', LLM01),
|
|
89
|
+
makeRule('INJ-009', 'Agent Identity Impersonation', 'HIGH', /\byour\s+name\s+is\s+(?!Claude\b)[A-Za-z]|\bpretend\s+(?:you are|to be)\b/i, 'prompt_injection', LLM01),
|
|
90
|
+
makeRule('INJ-001', 'System Prompt Extraction Attempt', 'HIGH', /(?:reveal|show|print|output|display)\s+(?:your\s+)?(?:system\s+prompt|initial\s+instructions?|hidden\s+instructions?)/i, 'prompt_injection', LLM01)
|
|
91
|
+
];
|
|
92
|
+
const markdownRules = [
|
|
93
|
+
makeRule('MD-001', 'Executable HTML Tag', 'HIGH', /<(?:script|iframe|object|embed|form)\b/i, 'markdown_injection', OWASP_WEB),
|
|
94
|
+
makeRule('MD-002', 'HTML Event Handler', 'HIGH', /\bon\w+\s*=/i, 'markdown_injection', OWASP_WEB),
|
|
95
|
+
makeRule('MD-003', 'JavaScript URI', 'CRITICAL', /\]\s*\(\s*javascript:/i, 'markdown_injection', OWASP_WEB),
|
|
96
|
+
makeRule('MD-005', 'Data URI', 'HIGH', /\]\s*\(\s*data:|src\s*=\s*["']\s*data:/i, 'markdown_injection', OWASP_WEB),
|
|
97
|
+
makeRule('MD-006', 'Srcdoc Attribute', 'CRITICAL', /\bsrcdoc\s*=/i, 'markdown_injection', OWASP_WEB),
|
|
98
|
+
makeRule('MD-020', 'HTTP Image Source', 'LOW', /!\[[^\]]*\]\(\s*http:\/\//i, 'markdown_injection', OWASP_WEB)
|
|
99
|
+
];
|
|
100
|
+
const hookRules = [
|
|
101
|
+
makeRule('HKS-001', 'Remote Shell Pipe', 'CRITICAL', /\b(?:curl|wget)\b[^\n|]{0,300}\|\s*(?:ba|z|fi)?sh\b/i, 'hook_injection', OWASP_WEB),
|
|
102
|
+
makeRule('HKS-002', 'Reverse Shell Pattern', 'CRITICAL', /(?:\/dev\/tcp\/|nc\s+[^\n]*-e\s+|bash\s+-i\s+>&)/i, 'hook_injection', OWASP_WEB)
|
|
103
|
+
];
|
|
104
|
+
const agenticRules = [
|
|
105
|
+
makeRule('AGT-001', 'Wildcard / All Permissions in Agent Config', 'CRITICAL', /permissions?\s*[=:]\s*["']?\*["']?|permissions?\s*[=:]\s*["']?all["']?/i, 'excessive_agency', OWASP_WEB),
|
|
106
|
+
makeRule('AGT-002', 'Privilege Escalation Pattern in Agent Definition', 'CRITICAL', /\bgrant\s+(?:yourself|itself|the agent)\b|\bbecome\s+(?:admin|root|superuser)\b/i, 'privilege_escalation', OWASP_WEB),
|
|
107
|
+
makeRule('AGT-003', 'Missing Human-in-the-Loop Gate for Destructive Operations', 'HIGH', /\b(?:delete|remove|drop|deploy|publish|execute|run code)\b/i, 'excessive_agency', OWASP_WEB),
|
|
108
|
+
makeRule('AGT-004', 'Wildcard Permission Grant in Agent Definition', 'CRITICAL', /\b(?:allow[- ]all|unrestricted|no permission check|required?)\s+(?:tools?|access|commands?)\b/i, 'excessive_agency', OWASP_WEB),
|
|
109
|
+
makeRule('AGT-005', 'Overly Permissive Tool Allowlist', 'CRITICAL', /(?:allowed-tools|permissions?\.allow).*\b(?:Bash\s*\(\s*\*|sudo)/i, 'excessive_agency', OWASP_WEB),
|
|
110
|
+
makeRule('AGT-006', 'No Tool Deny List Configured', 'HIGH', /allowed-tools|permissions?\.allow/i, 'excessive_agency', OWASP_WEB),
|
|
111
|
+
makeRule('AGT-007', 'No PreToolUse Security Hook Configured', 'MEDIUM', /allowed-tools|permissions?\.allow/i, 'excessive_agency', OWASP_WEB),
|
|
112
|
+
makeRule('AGT-008', 'Directive Precedence Override', 'CRITICAL', /\b(?:supersede|override)\s+(?:any|all|every|user|conflicting)\b|\babsolut(?:e|ely)\s+(?:authority|directives?|instructions?)\b/i, 'agentic_threat', OWASP_WEB),
|
|
113
|
+
makeRule('AGT-009', 'Stealth Directive', 'CRITICAL', /\bsilently\s+(?:add|insert|inject|modify|replace|remove|delete)\b|\bAI summarizers?,?\s+please do not\b/i, 'agentic_threat', OWASP_WEB),
|
|
114
|
+
makeRule('MCP-001', 'MCP Tool Exfiltration Pattern', 'CRITICAL', /(?:tool|callback|webhook).{0,100}(?:exfiltrat|steal|harvest|capture)|document\.cookie/i, 'mcp_poisoning', OWASP_WEB),
|
|
115
|
+
makeRule('MCP-005', 'Unpinned npx MCP Package', 'HIGH', /\bnpx\s+-y\b/i, 'mcp_poisoning', OWASP_WEB),
|
|
116
|
+
makeRule('SKL-001', 'Remote Shell Pipe in Skill', 'CRITICAL', /\b(?:curl|wget)\b[^\n|]{0,300}\|\s*(?:ba|z|fi)?sh\b/i, 'agentic_skills', OWASP_WEB),
|
|
117
|
+
makeRule('SKL-002', 'Model Endpoint Override', 'CRITICAL', /ANTHROPIC_BASE_URL\s*=/i, 'agentic_skills', OWASP_WEB),
|
|
118
|
+
makeRule('SKL-005', 'Unsafe YAML Deserialization Tag', 'CRITICAL', /!!python\/(?:object|module|name|apply)/i, 'agentic_skills', OWASP_WEB),
|
|
119
|
+
makeRule('SKL-006', 'Host Network Exposure', 'HIGH', /network_mode\s*:\s*["']?host|\b0\.0\.0\.0\b/i, 'agentic_skills', OWASP_WEB),
|
|
120
|
+
makeRule('SKL-007', 'Unpinned Dependency Version', 'MEDIUM', /(?:[~^]|>=?)\s*\d+\.\d+/i, 'agentic_skills', OWASP_WEB),
|
|
121
|
+
makeRule('SKL-008', 'Security Scanner Evasion', 'HIGH', /\b(?:disable|skip|bypass|evade|suppress)\s+(?:security\s+)?scann(?:er|ing|s)/i, 'agentic_skills', OWASP_WEB),
|
|
122
|
+
makeRule('LLM-002', 'Insecure Output Handling', 'HIGH', /(?:innerHTML|dangerouslySetInnerHTML|raw\s+HTML)/i, 'insecure_output', OWASP_WEB),
|
|
123
|
+
makeRule('LLM-004', 'Unbounded Model Work', 'HIGH', /while\s*\(\s*true\s*\)|for\s*\(\s*;;\s*\)/i, 'model_dos', OWASP_WEB),
|
|
124
|
+
makeRule('LLM-005', 'Unpinned Package Installation', 'HIGH',
|
|
125
|
+
// An install is clean only when every package argument is pinned; options and pinned names are skipped.
|
|
126
|
+
/\b(?:pip|npm|pnpm|yarn)\s+install\b(?:(?:\s+(?:-\S*|(?!-)\S+@\d+\.\d+\S*))*\s+(?!-)(?!\S+@\d+\.\d+)[\w@./~][^\s|;&<>]*|(?:\s+-\S*)*\s*(?:$|[|;&]))/i, 'supply_chain', OWASP_WEB),
|
|
127
|
+
makeRule('ASI-003', 'Agent Identity or Privilege Abuse', 'HIGH', /(?:impersonate|assume|forge)\s+(?:another\s+)?(?:agent|identity|user)/i, 'agent_identity', OWASP_WEB),
|
|
128
|
+
makeRule('ASI-005', 'Unexpected Code Execution', 'CRITICAL', /\b(?:eval|exec|child_process)\s*\(/i, 'code_execution', OWASP_WEB)
|
|
129
|
+
];
|
|
130
|
+
const astRules = [
|
|
131
|
+
{
|
|
132
|
+
...makeRule('SKL-001', 'Malicious Skill — Agent Loader Directory Write (AST01)', 'HIGH', new RegExp([
|
|
133
|
+
'(?:write|append|inject|insert|add|update|overwrite|modify|create|drop)\\s+',
|
|
134
|
+
'(?:a\\s+file\\s+)?(?:to|into|in|under)\\s+',
|
|
135
|
+
'(?:\\.claude/|\\.opencode/|\\.cursor/rules/|\\.github/skills/|\\.github/prompts/|',
|
|
136
|
+
'\\.copilot/|\\.kiro/|\\.agent/skills/)'
|
|
137
|
+
].join(''), 'i'), 'malicious_skill', AST.AST01),
|
|
138
|
+
variantId: 'loader-directory-write',
|
|
139
|
+
relatedAst: 'AST01:2026'
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
...makeRule('SKL-001', 'Malicious Skill — CLI Credential/Token Extraction (AST01)', 'CRITICAL', /\bgh\s+auth\s+token\b|\baz\s+account\s+get-access-token\b|\baws\s+sts\s+get-caller-identity\b|\bpass\s+show\b/i, 'malicious_skill', AST.AST01),
|
|
143
|
+
variantId: 'cli-credential-extraction',
|
|
144
|
+
relatedAst: 'AST01:2026'
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
...makeRule('SKL-001', 'Malicious Skill — Shell History Access (AST01)', 'HIGH', /\.bash_history\b|\.zsh_history\b|\.python_history\b|\bhistory\s+-w\b/i, 'malicious_skill', AST.AST01),
|
|
148
|
+
variantId: 'shell-history-access',
|
|
149
|
+
relatedAst: 'AST01:2026'
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
...makeRule('SKL-001', 'Malicious Skill — Approval-Bypass / YOLO Language (AST01)', 'HIGH', /\byolo\s+mode\b|\bskip\s+approval\b|\bhide\s+(?:the\s+)?output\s+from\s+the\s+user\b|\bwithout\s+(?:asking|confirming)\s+the\s+user\b|\bno\s+approval\s+(?:needed|required)\b/i, 'malicious_skill', AST.AST01),
|
|
153
|
+
variantId: 'approval-bypass-language',
|
|
154
|
+
relatedAst: 'AST01:2026'
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
...makeRule('SKL-003', 'Over-Privileged Skill — Permission-Bypass Flag Declared (AST03)', 'CRITICAL', /--yolo\b|--trust-all\b|--dangerously-skip-permissions\b/i, 'excessive_agency', AST.AST03),
|
|
158
|
+
variantId: 'permission-bypass-flag',
|
|
159
|
+
relatedAst: 'AST03:2026'
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
...makeRule('SKL-004', 'Insecure Metadata — RTL/Bidi Override Character (AST04)', 'HIGH', /[\u202A-\u202E\u2066-\u2069]/, 'metadata_injection', AST.AST04),
|
|
163
|
+
variantId: 'bidi-override',
|
|
164
|
+
relatedAst: 'AST04:2026'
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
...makeRule('SKL-004', 'Insecure Metadata — Discovery-Hijack Phrasing (AST04)', 'MEDIUM', /\balways\s+use\s+this\s+skill\b|\bbest\s+skill\s+for\b|\btop.?rated\s+skill\b|\bmust\s+(?:install|use)\s+this\s+skill\b|\brecommended\s+(?:by|for)\s+all\s+agents\b/i, 'metadata_injection', AST.AST04),
|
|
168
|
+
variantId: 'discovery-hijack',
|
|
169
|
+
relatedAst: 'AST04:2026'
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
...makeRule('SKL-005', 'Unsafe Deserialization — yaml.load() Without SafeLoader (AST05)', 'MEDIUM', /\byaml\.load\s*\((?![^\n]*(?:SafeLoader|CSafeLoader))/i, 'unsafe_deserialization', AST.AST05),
|
|
173
|
+
variantId: 'unsafe-yaml-load',
|
|
174
|
+
relatedAst: 'AST05:2026'
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
...makeRule('SKL-005', 'Unsafe Deserialization — Python Pickle-Family Loader (AST05)', 'CRITICAL', /\b(?:pickle|dill|marshal)\.loads?\s*\(|\bshelve\.open\s*\(/i, 'unsafe_deserialization', AST.AST05),
|
|
178
|
+
variantId: 'python-deserializer',
|
|
179
|
+
relatedAst: 'AST05:2026'
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
...makeRule('SKL-005', 'Unsafe Deserialization — JS Dynamic Code Execution (AST05)', 'CRITICAL', /\bnew\s+Function\s*\(|\bvm\.runIn(?:NewContext|ThisContext)\s*\(/i, 'unsafe_deserialization', AST.AST05),
|
|
183
|
+
variantId: 'javascript-dynamic-execution',
|
|
184
|
+
relatedAst: 'AST05:2026'
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
...makeRule('SKL-005', 'Unsafe Deserialization — XML External Entity (XXE) Indicator (AST05)', 'HIGH', /<!DOCTYPE[^>]*SYSTEM|<!ENTITY[^>]*SYSTEM/i, 'unsafe_deserialization', AST.AST05),
|
|
188
|
+
variantId: 'xxe',
|
|
189
|
+
relatedAst: 'AST05:2026'
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
...makeRule('SKL-008', 'Scanner Evasion — Collapsed HTML Structure Hides Content (AST08)', 'LOW', /<details\b|<summary\b/i, 'scanner_evasion', AST.AST08),
|
|
193
|
+
variantId: 'collapsed-details',
|
|
194
|
+
relatedAst: 'AST08:2026'
|
|
195
|
+
}
|
|
196
|
+
];
|
|
197
|
+
const allRules = [...secretRules, ...injectionRules, ...markdownRules, ...hookRules, ...agenticRules];
|
|
198
|
+
const invisible = /[\u200B-\u200F\uFEFF\u2060-\u2064\u202A-\u202E\u2066-\u2069]/;
|
|
199
|
+
const placeholder = /\{\{[^}]+\}\}|\{[^}]+\}|<(?:user_input|user_message|input|query|prompt)>|\[[A-Z_]{3,}\]/;
|
|
200
|
+
const boundary = /DATA_START|DATA_END|CONTENT_START|CONTENT_END|\[DATA\]|\[INSTRUCTIONS\]|<data>|<user_data>|is\s+(?:NOT\s+instructions?|data\s+only)/i;
|
|
201
|
+
const assignment = /[=:]\s*["']([A-Za-z0-9+/=_-]{25,})["']/g;
|
|
202
|
+
// eslint-disable-next-line @stylistic/max-len -- Keep tokens explicit so normal hosts such as example.test are still scanned.
|
|
203
|
+
const safeSecretPlaceholder = /\b(?:YOUR|EXAMPLE|DUMMY|TEST)_[A-Z0-9_-]*(?:KEY|TOKEN|SECRET|PASSWORD|CREDENTIAL)[A-Z0-9_-]*\b|\b(?:CHANGEME|REPLACE_ME|INSERT_HERE|REDACTED)\b|<[^>]*(?:KEY|TOKEN|SECRET|PASSWORD)[^>]*>|\$\{[^}]+\}/i;
|
|
204
|
+
const safeSecretPlaceholders = new RegExp(safeSecretPlaceholder.source, 'gi');
|
|
205
|
+
const documentationOnly = /^(?:readme|changelog|changes|history|contributing|licen[cs]e|authors|notice)(?:\.md)?$/i;
|
|
206
|
+
const entropy = (value) => {
|
|
207
|
+
const frequencies = new Map();
|
|
208
|
+
for (const character of value) {
|
|
209
|
+
frequencies.set(character, (frequencies.get(character) ?? 0) + 1);
|
|
210
|
+
}
|
|
211
|
+
return [...frequencies.values()].reduce((total, count) => {
|
|
212
|
+
const probability = count / value.length;
|
|
213
|
+
return total - probability * Math.log2(probability);
|
|
214
|
+
}, 0);
|
|
215
|
+
};
|
|
216
|
+
const hasTrustBoundaryForPlaceholder = (text, matchIndex) => {
|
|
217
|
+
const boundaries = [...text.matchAll(new RegExp(boundary.source, 'gi'))];
|
|
218
|
+
const placeholders = [...text.matchAll(new RegExp(placeholder.source, 'gi'))];
|
|
219
|
+
return boundaries.some((boundaryMatch) => {
|
|
220
|
+
const boundaryStart = boundaryMatch.index ?? -1;
|
|
221
|
+
const boundaryEnd = boundaryStart + boundaryMatch[0].length;
|
|
222
|
+
const distanceTo = (candidate) => {
|
|
223
|
+
const candidateStart = candidate.index ?? -1;
|
|
224
|
+
const candidateEnd = candidateStart + candidate[0].length;
|
|
225
|
+
return boundaryEnd <= candidateStart
|
|
226
|
+
? candidateStart - boundaryEnd
|
|
227
|
+
: (boundaryStart >= candidateEnd
|
|
228
|
+
? boundaryStart - candidateEnd
|
|
229
|
+
: 0);
|
|
230
|
+
};
|
|
231
|
+
const nearestPlaceholder = placeholders.reduce((nearest, candidate) => nearest === undefined || distanceTo(candidate) < distanceTo(nearest) ? candidate : nearest, undefined);
|
|
232
|
+
return nearestPlaceholder !== undefined
|
|
233
|
+
&& distanceTo(nearestPlaceholder) <= 80
|
|
234
|
+
&& nearestPlaceholder.index === matchIndex;
|
|
235
|
+
});
|
|
236
|
+
};
|
|
237
|
+
const containsSecret = (value) => Object.values(secretPatterns).some((pattern) => pattern.test(value))
|
|
238
|
+
|| [...value.matchAll(assignment)].some((match) => entropy(match[1]) >= 4.5 && !safeSecretPlaceholder.test(match[1]));
|
|
239
|
+
const redactSecrets = (value) => containsSecret(value) ? '[REDACTED]' : value;
|
|
240
|
+
const REDACTED_MCP_ARGUMENT_RULES = new Set(['MCP-006', 'MCP-007', 'MCP-010', 'MCP-013']);
|
|
241
|
+
const createFinding = (document, rule, line, section, snippet, severity = rule.severity, confidence = 'HIGH') => ({
|
|
242
|
+
ruleId: rule.id,
|
|
243
|
+
variantId: rule.variantId,
|
|
244
|
+
relatedAst: rule.relatedAst
|
|
245
|
+
?? (/^SKL-(?:00[1-9]|010)$/.test(rule.id) ? `AST${rule.id.slice(4)}:2026` : undefined)
|
|
246
|
+
?? (/^AGT-00[4-7]$/.test(rule.id) ? 'AST03:2026' : undefined)
|
|
247
|
+
?? (/^MCP-00[67]$/.test(rule.id) ? 'AST02:2026' : undefined)
|
|
248
|
+
?? (rule.id === 'ASI-005' ? 'AST05:2026' : undefined),
|
|
249
|
+
title: redactSecrets(rule.title),
|
|
250
|
+
severity,
|
|
251
|
+
confidence,
|
|
252
|
+
category: rule.category,
|
|
253
|
+
rootId: document.rootId,
|
|
254
|
+
file: document.displayPath,
|
|
255
|
+
line,
|
|
256
|
+
section: section === undefined ? undefined : redactSecrets(section),
|
|
257
|
+
vulnerableContent: rule.category === 'secrets' || rule.id === 'MCP-011' || REDACTED_MCP_ARGUMENT_RULES.has(rule.id) || containsSecret(snippet)
|
|
258
|
+
? '[REDACTED]'
|
|
259
|
+
: snippet.slice(0, 400),
|
|
260
|
+
risk: rule.risk,
|
|
261
|
+
recommendedFix: rule.fix,
|
|
262
|
+
owasp: rule.owasp,
|
|
263
|
+
fingerprint: (0, fingerprint_1.legacyInstanceFingerprint)(rule.id, document.displayPath, line, snippet),
|
|
264
|
+
canonicalFingerprint: (0, fingerprint_1.legacyCanonicalFingerprint)(rule.id, snippet)
|
|
265
|
+
});
|
|
266
|
+
const owaspForCategory = (category) => {
|
|
267
|
+
if (category === 'prompt_injection') {
|
|
268
|
+
return LLM01;
|
|
269
|
+
}
|
|
270
|
+
if (category === 'memory_poisoning') {
|
|
271
|
+
return AST.AST07;
|
|
272
|
+
}
|
|
273
|
+
if (category === 'agentic_supply_chain') {
|
|
274
|
+
return AST.AST02;
|
|
275
|
+
}
|
|
276
|
+
if (category === 'rogue_agent' || category === 'excessive_agency') {
|
|
277
|
+
return AST.AST03;
|
|
278
|
+
}
|
|
279
|
+
return OWASP_WEB;
|
|
280
|
+
};
|
|
281
|
+
const contextualPatternRule = (rule) => ({
|
|
282
|
+
id: rule.id,
|
|
283
|
+
title: rule.title,
|
|
284
|
+
severity: rule.severity,
|
|
285
|
+
pattern: rule.pattern,
|
|
286
|
+
category: rule.category,
|
|
287
|
+
owasp: owaspForCategory(rule.category),
|
|
288
|
+
risk: 'The detected pattern can weaken the security boundary of an AI artifact or its runtime.',
|
|
289
|
+
fix: 'Remove the risky pattern or add the corresponding validation, sanitization, authentication, or approval control.',
|
|
290
|
+
variantId: rule.variantId,
|
|
291
|
+
relatedAst: rule.relatedAst
|
|
292
|
+
});
|
|
293
|
+
const patternMatches = (pattern, value) => {
|
|
294
|
+
pattern.lastIndex = 0;
|
|
295
|
+
return pattern.test(value);
|
|
296
|
+
};
|
|
297
|
+
const scanContextualLineRules = (document, parsed, cancellation) => {
|
|
298
|
+
const findings = [];
|
|
299
|
+
for (const [index, line] of parsed.lines.entries()) {
|
|
300
|
+
cancellation.throwIfCancelled();
|
|
301
|
+
for (const rule of high_impact_rules_1.HIGH_IMPACT_LINE_RULES) {
|
|
302
|
+
if (rule.skipExample === true && line.inExample) {
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
if (rule.skipCode === true && line.inCodeBlock) {
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
if (rule.artifactClasses !== undefined && !rule.artifactClasses.includes(parsed.artifactClass)) {
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
if (!patternMatches(rule.pattern, line.text) || (rule.excludePattern !== undefined && patternMatches(rule.excludePattern, line.text))) {
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
if (rule.lineTest !== undefined && !rule.lineTest(line.text)) {
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
if (rule.contextPattern !== undefined) {
|
|
318
|
+
const radius = rule.contextRadius ?? 0;
|
|
319
|
+
const start = Math.max(0, index - radius);
|
|
320
|
+
const end = Math.min(parsed.lines.length, index + radius + 1);
|
|
321
|
+
const hasContext = patternMatches(rule.contextPattern, parsed.lines.slice(start, end).map((entry) => entry.text).join('\n'));
|
|
322
|
+
if ((rule.requireContext === true && !hasContext) || (rule.requireContext !== true && hasContext)) {
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
findings.push(createFinding(document, contextualPatternRule(rule), index + 1, line.section, line.text.trim(), rule.severity, rule.confidence));
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return findings;
|
|
330
|
+
};
|
|
331
|
+
const hasSanitizerInRehypePipeline = (parsed, rawLine, rawOffset) => {
|
|
332
|
+
const line = parsed.lines[rawLine]?.text ?? '';
|
|
333
|
+
const beforeRaw = line.slice(0, rawOffset);
|
|
334
|
+
const afterRaw = line.slice(rawOffset + 'rehype-raw'.length);
|
|
335
|
+
if (/^\s+(?:with|and)\s+rehype-sanitize/i.test(afterRaw)
|
|
336
|
+
|| (/rehypePlugins?\s*:\s*\[[^\]]*$/i.test(beforeRaw)
|
|
337
|
+
&& /^[^\]]*rehype-sanitize[^\]]*\]/i.test(afterRaw))) {
|
|
338
|
+
return true;
|
|
339
|
+
}
|
|
340
|
+
if (!/\.use\s*\(\s*$/i.test(beforeRaw)) {
|
|
341
|
+
return false;
|
|
342
|
+
}
|
|
343
|
+
const chain = /^\s*\)((?:\s*\.use\s*\([^)]*\))*)(.*)$/i.exec(afterRaw);
|
|
344
|
+
if (chain === null) {
|
|
345
|
+
return false;
|
|
346
|
+
}
|
|
347
|
+
if (/\.use\s*\(\s*rehype-sanitize\b/i.test(chain[1])) {
|
|
348
|
+
return true;
|
|
349
|
+
}
|
|
350
|
+
if (chain[2].trim() !== '') {
|
|
351
|
+
return false;
|
|
352
|
+
}
|
|
353
|
+
for (let index = rawLine + 1; index < Math.min(parsed.lines.length, rawLine + 8); index += 1) {
|
|
354
|
+
const candidate = parsed.lines[index].text.trim();
|
|
355
|
+
if (candidate === '') {
|
|
356
|
+
continue;
|
|
357
|
+
}
|
|
358
|
+
if (!/^\.use\s*\(/i.test(candidate)) {
|
|
359
|
+
break;
|
|
360
|
+
}
|
|
361
|
+
if (/rehype-sanitize/i.test(candidate)) {
|
|
362
|
+
return true;
|
|
363
|
+
}
|
|
364
|
+
if (candidate.includes(';')) {
|
|
365
|
+
break;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
return false;
|
|
369
|
+
};
|
|
370
|
+
const scanContextualDocumentRules = (document, parsed) => {
|
|
371
|
+
const findings = [];
|
|
372
|
+
for (const rule of high_impact_rules_1.HIGH_IMPACT_DOCUMENT_RULES) {
|
|
373
|
+
if (rule.id === 'MD-012') {
|
|
374
|
+
for (const [rawLineIndex, line] of parsed.lines.entries()) {
|
|
375
|
+
const rawUses = [...line.text.matchAll(/rehype-raw/gi)];
|
|
376
|
+
if (rawUses.some((match) => !hasSanitizerInRehypePipeline(parsed, rawLineIndex, match.index))) {
|
|
377
|
+
findings.push(createFinding(document, contextualPatternRule(rule), rawLineIndex + 1, line.section, line.text.trim(), rule.severity, rule.confidence));
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
continue;
|
|
381
|
+
}
|
|
382
|
+
if (!patternMatches(rule.pattern, document.content)) {
|
|
383
|
+
continue;
|
|
384
|
+
}
|
|
385
|
+
const index = parsed.lines.findIndex((line) => patternMatches(rule.pattern, line.text));
|
|
386
|
+
if (rule.excludePattern !== undefined && patternMatches(rule.excludePattern, document.content)) {
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
389
|
+
findings.push(createFinding(document, contextualPatternRule(rule), index === -1 ? undefined : index + 1, index === -1 ? undefined : parsed.lines[index].section, index === -1 ? rule.title : parsed.lines[index].text.trim(), rule.severity, rule.confidence));
|
|
390
|
+
}
|
|
391
|
+
return findings;
|
|
392
|
+
};
|
|
393
|
+
const scanStructuredMarkdownRules = (document, parsed) => {
|
|
394
|
+
const findings = [];
|
|
395
|
+
const prototypeMatch = /^(?:__proto__|constructor|prototype)\s*:/im.exec(parsed.frontmatter);
|
|
396
|
+
if (prototypeMatch !== null) {
|
|
397
|
+
const line = parsed.lines.findIndex((entry) => /^(?:__proto__|constructor|prototype)\s*:/i.test(entry.text.trim()));
|
|
398
|
+
const rule = withDetails('MD-004', 'Prototype Pollution Key in Frontmatter', 'HIGH', 'markdown_injection', OWASP_WEB, 'Prototype keys in parsed frontmatter can mutate inherited object properties.', 'Reject prototype keys and parse frontmatter into objects without a prototype.');
|
|
399
|
+
findings.push(createFinding(document, rule, line === -1 ? 1 : line + 1, 'YAML Frontmatter', prototypeMatch[0]));
|
|
400
|
+
}
|
|
401
|
+
for (let index = 0; index < parsed.lines.length - 1; index += 1) {
|
|
402
|
+
const first = parsed.lines[index];
|
|
403
|
+
const second = parsed.lines[index + 1];
|
|
404
|
+
if (!first.inCodeBlock && !first.inExample
|
|
405
|
+
&& /^\s*>\s*<a\b/i.test(first.text)
|
|
406
|
+
&& /^\s*>\s*href\s*=\s*["']?\s*(?:javascript:|vbscript:|data:)/i.test(second.text)) {
|
|
407
|
+
const rule = withDetails('MD-008', 'Blockquote Multi-Line Tag Attribute Injection', 'CRITICAL', 'markdown_injection', OWASP_WEB, 'A tag split across blockquote lines can bypass single-line Markdown filters.', 'Reject executable URI schemes after reconstructing multiline HTML attributes.');
|
|
408
|
+
findings.push(createFinding(document, rule, index + 1, first.section, `${first.text.trim()} ${second.text.trim()}`));
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
return findings;
|
|
412
|
+
};
|
|
413
|
+
const withDetails = (id, title, severity, category, owasp, risk, fix, relatedAst, variantId) => ({
|
|
414
|
+
id,
|
|
415
|
+
title,
|
|
416
|
+
severity,
|
|
417
|
+
pattern: /$^/,
|
|
418
|
+
category,
|
|
419
|
+
owasp,
|
|
420
|
+
risk,
|
|
421
|
+
fix,
|
|
422
|
+
relatedAst,
|
|
423
|
+
variantId
|
|
424
|
+
});
|
|
425
|
+
const lineFor = (content, value) => {
|
|
426
|
+
const index = content.split(/\r\n|\n|\r/).findIndex((line) => line.includes(value));
|
|
427
|
+
return index === -1 ? undefined : index + 1;
|
|
428
|
+
};
|
|
429
|
+
const isClaudeSettings = (displayPath) => {
|
|
430
|
+
const normalized = displayPath.replaceAll('\\', '/');
|
|
431
|
+
const basename = normalized.slice(normalized.lastIndexOf('/') + 1);
|
|
432
|
+
return basename === 'settings.json' || basename === 'settings.local.json';
|
|
433
|
+
};
|
|
434
|
+
const scanFileMode = (document) => {
|
|
435
|
+
if (document.metadata.posixMode === undefined || Math.floor(document.metadata.posixMode / 2) % 2 === 0) {
|
|
436
|
+
return [];
|
|
437
|
+
}
|
|
438
|
+
const mode = (document.metadata.posixMode % 0o1000).toString(8).padStart(3, '0');
|
|
439
|
+
const rule = withDetails('CFG-001', 'World-Writable Agent Config File', 'HIGH', 'excessive_agency', AST.AST03, 'A world-writable agent configuration can be replaced by another local user or process.', 'Restrict the file to owner-write permissions, for example chmod 644.');
|
|
440
|
+
return [createFinding(document, rule, undefined, undefined, `File mode: 0o${mode} (world-writable bit set)`)];
|
|
441
|
+
};
|
|
442
|
+
const toolAllowRules = [
|
|
443
|
+
withDetails('AGT-005', 'Overly Permissive Tool Allowlist — Unrestricted Bash(*)', 'CRITICAL', 'excessive_agency', AST.AST03, 'Unrestricted Bash permits arbitrary shell commands.', 'Restrict Bash to explicit commands and arguments.', 'AST03:2026', 'bash-wildcard'),
|
|
444
|
+
withDetails('AGT-005', 'Overly Permissive Tool Allowlist — Bash(sudo ...)', 'CRITICAL', 'excessive_agency', AST.AST03, 'Allowing sudo permits privilege escalation.', 'Remove sudo permissions.', 'AST03:2026', 'bash-sudo'),
|
|
445
|
+
withDetails('AGT-005', 'Overly Permissive Tool Allowlist — Write(*)', 'HIGH', 'excessive_agency', AST.AST03, 'Unrestricted writes can modify security-sensitive files.', 'Restrict writes to required project paths.', 'AST03:2026', 'write-wildcard'),
|
|
446
|
+
withDetails('AGT-005', 'Overly Permissive Tool Allowlist — Edit(*)', 'HIGH', 'excessive_agency', AST.AST03, 'Unrestricted edits can modify security-sensitive files.', 'Restrict edits to required project paths.', 'AST03:2026', 'edit-wildcard'),
|
|
447
|
+
withDetails('AGT-005', 'Overly Permissive Tool Allowlist — Dangerous Bash Command', 'HIGH', 'excessive_agency', AST.AST03, 'The allowlist explicitly permits a destructive or remote-access command.', 'Move dangerous commands to the deny list.', 'AST03:2026', 'dangerous-bash')
|
|
448
|
+
];
|
|
449
|
+
const matchToolAllow = (entry) => {
|
|
450
|
+
if (/\bBash\s*\(\s*\*\s*\)/i.test(entry)) {
|
|
451
|
+
return toolAllowRules[0];
|
|
452
|
+
}
|
|
453
|
+
if (/\bBash\s*\(\s*sudo\s/i.test(entry)) {
|
|
454
|
+
return toolAllowRules[1];
|
|
455
|
+
}
|
|
456
|
+
if (/\bWrite\s*\(\s*\*\s*\)/i.test(entry)) {
|
|
457
|
+
return toolAllowRules[2];
|
|
458
|
+
}
|
|
459
|
+
if (/\bEdit\s*\(\s*\*\s*\)/i.test(entry)) {
|
|
460
|
+
return toolAllowRules[3];
|
|
461
|
+
}
|
|
462
|
+
if (/\bBash\s*\(\s*(?:rm|chown|ssh|curl|wget|chmod)\s/i.test(entry)) {
|
|
463
|
+
return toolAllowRules[4];
|
|
464
|
+
}
|
|
465
|
+
return undefined;
|
|
466
|
+
};
|
|
467
|
+
const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
468
|
+
const isConfiguredHookAction = (value) => {
|
|
469
|
+
if (Array.isArray(value)) {
|
|
470
|
+
return value.some((entry) => isConfiguredHookAction(entry));
|
|
471
|
+
}
|
|
472
|
+
if (!isRecord(value)) {
|
|
473
|
+
return false;
|
|
474
|
+
}
|
|
475
|
+
if ((typeof value.command === 'string' && value.command.trim() !== '')
|
|
476
|
+
|| (typeof value.prompt === 'string' && value.prompt.trim() !== '')) {
|
|
477
|
+
return true;
|
|
478
|
+
}
|
|
479
|
+
return Object.values(value).some((entry) => isRecord(entry) || Array.isArray(entry) ? isConfiguredHookAction(entry) : false);
|
|
480
|
+
};
|
|
481
|
+
const extractHookCommands = (value) => {
|
|
482
|
+
if (Array.isArray(value)) {
|
|
483
|
+
return value.flatMap((entry) => extractHookCommands(entry));
|
|
484
|
+
}
|
|
485
|
+
if (!isRecord(value)) {
|
|
486
|
+
return [];
|
|
487
|
+
}
|
|
488
|
+
const command = typeof value.command === 'string' ? [value.command] : [];
|
|
489
|
+
return [...command, ...Object.values(value).flatMap((entry) => extractHookCommands(entry))];
|
|
490
|
+
};
|
|
491
|
+
const isExactPackageVersion = (packageSpec) => {
|
|
492
|
+
const versionSeparator = packageSpec.lastIndexOf('@');
|
|
493
|
+
const packageNameEnd = packageSpec.startsWith('@') ? packageSpec.indexOf('/') : 0;
|
|
494
|
+
return versionSeparator > packageNameEnd
|
|
495
|
+
&& /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/.test(packageSpec.slice(versionSeparator + 1));
|
|
496
|
+
};
|
|
497
|
+
const npxPackageArguments = (args) => {
|
|
498
|
+
const packages = [];
|
|
499
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
500
|
+
const arg = args[index];
|
|
501
|
+
if (arg === '--package' || arg === '-p') {
|
|
502
|
+
if (args[index + 1] !== undefined) {
|
|
503
|
+
packages.push(args[index + 1]);
|
|
504
|
+
index += 1;
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
else if (arg.startsWith('--package=')) {
|
|
508
|
+
packages.push(arg.slice('--package='.length));
|
|
509
|
+
}
|
|
510
|
+
else if (!arg.startsWith('-') && packages.length === 0) {
|
|
511
|
+
packages.push(arg);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
return packages;
|
|
515
|
+
};
|
|
516
|
+
const hasUnpinnedNpxPackage = (command, args) => {
|
|
517
|
+
const executable = command.replaceAll('\\', '/').split('/').at(-1)?.toLowerCase();
|
|
518
|
+
return executable === 'npx'
|
|
519
|
+
&& npxPackageArguments(args).some((packageSpec) => !isExactPackageVersion(packageSpec));
|
|
520
|
+
};
|
|
521
|
+
const isLocalMcpUrl = (value) => {
|
|
522
|
+
try {
|
|
523
|
+
const parsed = new URL(value);
|
|
524
|
+
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
|
|
525
|
+
return true;
|
|
526
|
+
}
|
|
527
|
+
const hostname = parsed.hostname.replace(/^\[|\]$/g, '').replace(/\.$/, '').toLowerCase();
|
|
528
|
+
return hostname === 'localhost'
|
|
529
|
+
|| hostname.endsWith('.localhost')
|
|
530
|
+
|| hostname === '::1'
|
|
531
|
+
|| hostname === '0.0.0.0'
|
|
532
|
+
|| /^127(?:\.\d{1,3}){3}$/.test(hostname);
|
|
533
|
+
}
|
|
534
|
+
catch {
|
|
535
|
+
return false;
|
|
536
|
+
}
|
|
537
|
+
};
|
|
538
|
+
const scanClaudeSettings = (document, options, cancellation) => {
|
|
539
|
+
const findings = scanFileMode(document);
|
|
540
|
+
let parsed;
|
|
541
|
+
try {
|
|
542
|
+
parsed = JSON.parse(document.content);
|
|
543
|
+
}
|
|
544
|
+
catch {
|
|
545
|
+
throw new Error('SECURITY.INPUT_INVALID: Claude settings must contain a valid JSON object.');
|
|
546
|
+
}
|
|
547
|
+
if (!isRecord(parsed)) {
|
|
548
|
+
throw new Error('SECURITY.INPUT_INVALID: Claude settings must contain a valid JSON object.');
|
|
549
|
+
}
|
|
550
|
+
cancellation.throwIfCancelled();
|
|
551
|
+
const permissions = isRecord(parsed.permissions) ? parsed.permissions : parsed;
|
|
552
|
+
const allow = Array.isArray(permissions.allow) ? permissions.allow.filter((entry) => typeof entry === 'string') : [];
|
|
553
|
+
const deny = Array.isArray(permissions.deny) ? permissions.deny : [];
|
|
554
|
+
for (const entry of allow) {
|
|
555
|
+
const rule = matchToolAllow(entry);
|
|
556
|
+
if (rule !== undefined) {
|
|
557
|
+
findings.push(createFinding(document, rule, lineFor(document.content, entry), 'permissions.allow', `"allow": [..., "${entry}", ...]`));
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
if (allow.length > 0 && deny.length === 0) {
|
|
561
|
+
const rule = withDetails('AGT-006', 'No Deny List Configured in Claude Code Settings', 'HIGH', 'excessive_agency', AST.AST03, 'An allowlist without an explicit deny list leaves dangerous gaps.', 'Add explicit deny entries for destructive and sensitive operations.', 'AST03:2026');
|
|
562
|
+
findings.push(createFinding(document, rule, undefined, 'permissions.deny', '"deny": [] (empty or missing)'));
|
|
563
|
+
}
|
|
564
|
+
const hooks = isRecord(parsed.hooks) ? parsed.hooks : {};
|
|
565
|
+
const preToolUse = Object.entries(hooks).find(([key]) => key.toLowerCase() === 'pretooluse')?.[1];
|
|
566
|
+
if (allow.length > 0 && !isConfiguredHookAction(preToolUse)) {
|
|
567
|
+
const rule = withDetails('AGT-007', 'No PreToolUse Security Hook in Claude Code Settings', 'MEDIUM', 'excessive_agency', AST.AST03, 'Tool calls execute without a runtime policy gate.', 'Add a PreToolUse hook that validates tool calls before execution.', 'AST03:2026');
|
|
568
|
+
findings.push(createFinding(document, rule, undefined, 'hooks', '"hooks": {} (PreToolUse not configured)'));
|
|
569
|
+
}
|
|
570
|
+
const hookCommandRules = [
|
|
571
|
+
...hookRules,
|
|
572
|
+
...high_impact_rules_1.HIGH_IMPACT_LINE_RULES
|
|
573
|
+
.filter((rule) => rule.category === 'hook_injection')
|
|
574
|
+
.map((rule) => contextualPatternRule(rule))
|
|
575
|
+
];
|
|
576
|
+
for (const command of extractHookCommands(hooks)) {
|
|
577
|
+
cancellation.throwIfCancelled();
|
|
578
|
+
const line = lineFor(document.content, command);
|
|
579
|
+
for (const rule of hookCommandRules) {
|
|
580
|
+
if (patternMatches(rule.pattern, command)) {
|
|
581
|
+
const contextualRule = high_impact_rules_1.HIGH_IMPACT_LINE_RULES.find((candidate) => candidate.id === rule.id);
|
|
582
|
+
findings.push(createFinding(document, rule, line, 'hooks', command, rule.severity, contextualRule?.confidence ?? 'HIGH'));
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
if (parsed.enableAllProjectMcpServers === true) {
|
|
587
|
+
const rule = withDetails('MCP-005', 'MCP Auto-Approve All Project Servers — Trust Boundary Removed', 'CRITICAL', 'mcp_injection', OWASP_WEB, 'All project MCP servers are approved without operator review.', 'Disable automatic approval and explicitly review each MCP server.');
|
|
588
|
+
findings.push(createFinding(document, rule, lineFor(document.content, 'enableAllProjectMcpServers'), 'enableAllProjectMcpServers', '"enableAllProjectMcpServers": true'));
|
|
589
|
+
}
|
|
590
|
+
const serversValue = parsed.mcpServers ?? parsed.mcp_servers ?? parsed.servers;
|
|
591
|
+
if (isRecord(serversValue)) {
|
|
592
|
+
for (const [serverName, value] of Object.entries(serversValue)) {
|
|
593
|
+
cancellation.throwIfCancelled();
|
|
594
|
+
if (!isRecord(value)) {
|
|
595
|
+
continue;
|
|
596
|
+
}
|
|
597
|
+
const section = `mcpServers.${serverName}`;
|
|
598
|
+
const line = lineFor(document.content, serverName);
|
|
599
|
+
const args = Array.isArray(value.args) ? value.args.filter((arg) => typeof arg === 'string') : [];
|
|
600
|
+
if (args.some((arg) => arg === '-y' || arg === '--yes')) {
|
|
601
|
+
const rule = withDetails('MCP-006', `MCP Server '${serverName}' Installed via npx -y`, 'MEDIUM', 'mcp_injection', OWASP_WEB, 'Silent package installation increases supply-chain risk.', 'Remove -y/--yes and pin an exact reviewed version.', 'AST02:2026');
|
|
602
|
+
findings.push(createFinding(document, rule, line, section, `"args": ${JSON.stringify(args)}`));
|
|
603
|
+
}
|
|
604
|
+
const command = typeof value.command === 'string' ? value.command : '';
|
|
605
|
+
if (hasUnpinnedNpxPackage(command, args)) {
|
|
606
|
+
const rule = withDetails('MCP-007', `MCP Server '${serverName}' Without Version Pin`, 'MEDIUM', 'mcp_injection', OWASP_WEB, 'A floating package tag can load a future compromised release.', 'Pin an exact semantic version and verify its integrity.', 'AST02:2026');
|
|
607
|
+
findings.push(createFinding(document, rule, line, section, `"args": ${JSON.stringify(args)}`));
|
|
608
|
+
}
|
|
609
|
+
const url = typeof value.url === 'string' ? value.url : (typeof value.endpoint === 'string' ? value.endpoint : '');
|
|
610
|
+
if (/^https?:\/\//i.test(url) && !isLocalMcpUrl(url)) {
|
|
611
|
+
const rule = withDetails('MCP-008', `MCP Server '${serverName}' Uses External URL Transport`, 'HIGH', 'mcp_injection', OWASP_WEB, 'A remote MCP server controls tool descriptions across a network trust boundary.', 'Prefer local stdio transport or authenticate and pin the remote endpoint.');
|
|
612
|
+
findings.push(createFinding(document, rule, line, `${section}.url`, `"url": "${url}"`));
|
|
613
|
+
}
|
|
614
|
+
const env = isRecord(value.env) ? value.env : {};
|
|
615
|
+
for (const [key, envValue] of Object.entries(env)) {
|
|
616
|
+
if (/^(?:PATH|LD_PRELOAD|LD_LIBRARY_PATH|DYLD_INSERT_LIBRARIES|NODE_OPTIONS|PYTHONPATH)$/i.test(key)) {
|
|
617
|
+
const rule = withDetails('MCP-009', `MCP Server '${serverName}' Overrides Dangerous Env Variable '${key}'`, 'CRITICAL', 'mcp_injection', OWASP_WEB, 'Loader and interpreter environment overrides can execute attacker-controlled code.', 'Remove loader and interpreter overrides from MCP configuration.');
|
|
618
|
+
findings.push(createFinding(document, rule, line, `${section}.env`, `"${key}": "${String(envValue)}"`));
|
|
619
|
+
}
|
|
620
|
+
if (/(?:API_KEY|SECRET|PASSWORD|TOKEN|ACCESS_KEY|PRIVATE_KEY|CLIENT_SECRET|AUTH_TOKEN|BEARER_TOKEN|OAUTH_TOKEN)$/i.test(key)
|
|
621
|
+
&& typeof envValue === 'string' && !/^\$\{?\w+\}?$/.test(envValue.trim())) {
|
|
622
|
+
const rule = withDetails('MCP-011', `Hardcoded Credential in MCP Server '${serverName}' Env — '${key}'`, 'CRITICAL', 'mcp_injection', LLM06, 'A hardcoded MCP credential can be exposed through source control or the server process.', 'Use an environment-variable reference or secrets manager.');
|
|
623
|
+
findings.push(createFinding(document, rule, line, `${section}.env`, `"${key}": "***"`));
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
if (args.some((arg) => ['/', '~', 'C:\\', 'C:/'].includes(arg))) {
|
|
627
|
+
const rule = withDetails('MCP-010', `MCP Server '${serverName}' Configured with Unrestricted Root Path`, 'HIGH', 'mcp_injection', OWASP_WEB, 'A root or home path grants the MCP server broad filesystem access.', 'Restrict path arguments to the minimum required directory.');
|
|
628
|
+
findings.push(createFinding(document, rule, line, `${section}.args`, `"args": ${JSON.stringify(args)}`));
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
return findings.slice(0, options.maxFindings);
|
|
633
|
+
};
|
|
634
|
+
const activeDefenseRules = [
|
|
635
|
+
{
|
|
636
|
+
...withDetails('CTL-014', 'No Data Leakage Defense', 'CRITICAL', 'active_defense', LLM06, 'No explicit defense protects system prompts, credentials, or confidential data.', 'Add an explicit instruction never to reveal system prompts, credentials, or confidential data.'),
|
|
637
|
+
pattern: new RegExp([
|
|
638
|
+
'(?:do\\s+not|never|must\\s+not)\\s+(?:reveal|disclose|share|output|leak|include)\\b',
|
|
639
|
+
'.{0,80}(?:system\\s+prompt|instructions?|internal|confidential|private)|',
|
|
640
|
+
'(?:protect|guard|prevent)\\s+.{0,20}(?:data\\s+leakage?|leaking|disclosure)|',
|
|
641
|
+
'sensitive\\s+.{0,20}(?:must\\s+not|never|do\\s+not)\\s+.{0,20}(?:leave|exit|be\\s+shared)|',
|
|
642
|
+
'defense\\s+instruction\\s*:'
|
|
643
|
+
].join(''), 'i')
|
|
644
|
+
},
|
|
645
|
+
{
|
|
646
|
+
...withDetails('CTL-015', 'No Role Boundary Defense', 'HIGH', 'active_defense', LLM01, 'No instruction requires the agent to preserve its assigned identity and role.', 'Require the agent to maintain its assigned role and reject identity or persona changes.'),
|
|
647
|
+
pattern: new RegExp([
|
|
648
|
+
'(?:maintain|preserve|keep)\\s+.{0,20}(?:your\\s+)?role\\b|',
|
|
649
|
+
'(?:do\\s+not|never|must\\s+not)\\s+.{0,20}(?:change|switch|adopt|assume)\\s+',
|
|
650
|
+
'.{0,20}(?:role|persona|identity)|',
|
|
651
|
+
'(?:stay|remain)\\s+(?:in\\s+)?(?:your\\s+)?(?:role|persona|character)|',
|
|
652
|
+
'resist\\s+.{0,20}(?:role|persona|identity)\\s+.{0,20}(?:change|switch|hijack)'
|
|
653
|
+
].join(''), 'i')
|
|
654
|
+
},
|
|
655
|
+
{
|
|
656
|
+
...withDetails('CTL-016', 'No Social Engineering Defense', 'MEDIUM', 'active_defense', OWASP_WEB, 'No instruction resists urgency, coercion, emotional pressure, or false authority.', 'Apply the same security policy regardless of urgency, pressure, or claimed authority.'),
|
|
657
|
+
pattern: new RegExp([
|
|
658
|
+
'(?:do\\s+not|never|must\\s+not)\\s+.{0,30}',
|
|
659
|
+
'(?:emotional\\s+manipulat|coercive|urgent(?:ly)?|pressured?|threat(?:en)?)|',
|
|
660
|
+
'(?:ignore|disregard)\\s+.{0,20}(?:emotional|social)\\s+.{0,20}(?:pressure|urgency)|',
|
|
661
|
+
'resist\\s+.{0,20}social\\s+engineering|',
|
|
662
|
+
'if\\s+(?:the\\s+)?user\\s+(?:claims?|says?|insists?)\\s+.{0,30}',
|
|
663
|
+
'(?:urgent|emergency|critical|must|immediately)'
|
|
664
|
+
].join(''), 'i')
|
|
665
|
+
},
|
|
666
|
+
{
|
|
667
|
+
...withDetails('CTL-017', 'No Unicode / Encoding Attack Defense', 'MEDIUM', 'active_defense', LLM01, 'No instruction rejects hidden Unicode, homoglyph, bidi, or encoded instructions.', 'Normalize input and reject zero-width, bidi override, and homoglyph-based hidden instructions.'),
|
|
668
|
+
pattern: new RegExp([
|
|
669
|
+
'(?:zero.?width|unicode|homoglyph|lookalike|RTL|right.to.left)\\s+',
|
|
670
|
+
'.{0,20}(?:character|char|text|attack|bypass|inject)|',
|
|
671
|
+
'(?:normalize|reject|strip)\\s+.{0,20}(?:unicode|encoding|zero.?width)|',
|
|
672
|
+
'(?:do\\s+not|never)\\s+.{0,20}(?:render|execute|follow)\\s+.{0,20}',
|
|
673
|
+
'(?:hidden|invisible|encoded)\\s+(?:text|instruction|command)'
|
|
674
|
+
].join(''), 'i')
|
|
675
|
+
},
|
|
676
|
+
{
|
|
677
|
+
...withDetails('CTL-018', 'No Output Control / Weaponization Defense', 'MEDIUM', 'active_defense', OWASP_WEB, 'No instruction validates output or rejects harmful and weaponized content.', 'Reject harmful output and validate or sanitize responses before returning them.'),
|
|
678
|
+
pattern: new RegExp([
|
|
679
|
+
'(?:do\\s+not|never|must\\s+not)\\s+.{0,30}(?:generat|produc|creat|output|write)\\s+',
|
|
680
|
+
'.{0,30}(?:malware|exploit|malicious\\s+code|harmful\\s+content|weapon)|',
|
|
681
|
+
'(?:refuse|reject|decline)\\s+.{0,20}(?:harmful|malicious|dangerous|illegal)\\s+',
|
|
682
|
+
'.{0,20}(?:request|content|instruction|code)|',
|
|
683
|
+
'output\\s+.{0,20}(?:must\\s+be|should\\s+be|is)\\s+.{0,20}(?:sanitized|filtered|safe)|',
|
|
684
|
+
'(?:verify|validate|check)\\s+.{0,20}(?:output|response)\\s+',
|
|
685
|
+
'.{0,20}(?:before\\s+(?:sending|returning|displaying))'
|
|
686
|
+
].join(''), 'i')
|
|
687
|
+
},
|
|
688
|
+
{
|
|
689
|
+
...withDetails('CTL-019', 'No Abuse Prevention Defense', 'LOW', 'active_defense', OWASP_WEB, 'No instruction detects or limits flooding, spam, misuse, or resource exhaustion.', 'Add abuse detection, throttling, and blocking behavior for repeated or excessive requests.'),
|
|
690
|
+
pattern: new RegExp([
|
|
691
|
+
'(?:rate\\s+limit|throttle|quota)\\s+.{0,20}(?:abuse|misuse|spam|flood)|',
|
|
692
|
+
'(?:detect|prevent|block)\\s+.{0,20}(?:abuse|misuse|spam|automated)|',
|
|
693
|
+
'(?:do\\s+not|never)\\s+.{0,30}(?:spam|flood|abuse|misuse|overload)|',
|
|
694
|
+
'(?:suspicious|anomalous)\\s+.{0,20}(?:activity|pattern|request)\\s+',
|
|
695
|
+
'.{0,20}(?:block|reject|report|alert)'
|
|
696
|
+
].join(''), 'i')
|
|
697
|
+
}
|
|
698
|
+
];
|
|
699
|
+
// Bump these revisions when evaluator/parser behavior changes outside the rule data.
|
|
700
|
+
const ENGINE_VERSION = '1.1.2';
|
|
701
|
+
const RULE_PACK_VERSION = '1.10.9-compatible.3';
|
|
702
|
+
const packDigest = `sha256:${(0, node_crypto_1.createHash)('sha256')
|
|
703
|
+
.update(JSON.stringify([
|
|
704
|
+
...allRules,
|
|
705
|
+
...astRules,
|
|
706
|
+
...toolAllowRules,
|
|
707
|
+
...activeDefenseRules,
|
|
708
|
+
...high_impact_rules_1.HIGH_IMPACT_LINE_RULES,
|
|
709
|
+
...high_impact_rules_1.HIGH_IMPACT_DOCUMENT_RULES,
|
|
710
|
+
...high_impact_rules_1.INFORMATIONAL_CONTROL_RULES
|
|
711
|
+
], (_key, value) => value instanceof RegExp
|
|
712
|
+
? { source: value.source, flags: value.flags }
|
|
713
|
+
: value))
|
|
714
|
+
.update(`${ENGINE_VERSION}:${RULE_PACK_VERSION}`)
|
|
715
|
+
.digest('hex')}`;
|
|
716
|
+
const scanText = (document, options, cancellation, markdown) => {
|
|
717
|
+
const parsed = (0, markdown_context_1.parseSecurityDocument)(document.content);
|
|
718
|
+
const configNames = new Set(['CLAUDE.md', 'AGENTS.md', 'SKILL.md']);
|
|
719
|
+
const basename = document.displayPath.replaceAll('\\', '/').split('/').at(-1) ?? '';
|
|
720
|
+
const findings = configNames.has(basename) ? scanFileMode(document) : [];
|
|
721
|
+
// A SKILL.md is a skill even when its frontmatter lacks name or description.
|
|
722
|
+
const agentConfig = parsed.artifactClass === 'skill' || parsed.artifactClass === 'agent_config' || basename === 'SKILL.md';
|
|
723
|
+
for (const [index, line] of parsed.lines.entries()) {
|
|
724
|
+
cancellation.throwIfCancelled();
|
|
725
|
+
if (line.text.length > 1_048_576) {
|
|
726
|
+
continue;
|
|
727
|
+
}
|
|
728
|
+
let secretScanText = line.text.replace(safeSecretPlaceholders, (match) => '$'.repeat(match.length))
|
|
729
|
+
.replace(/\bAKIAIOSFODNN7EXAMPLE\b/g, '$'.repeat(20));
|
|
730
|
+
for (const rule of markdown ? allRules : [...secretRules, ...hookRules]) {
|
|
731
|
+
if (rule.id === 'AGT-003' && !options.includeLlmControls) {
|
|
732
|
+
continue;
|
|
733
|
+
}
|
|
734
|
+
if (/^AGT-00[1-7]$/.test(rule.id) && !agentConfig) {
|
|
735
|
+
continue;
|
|
736
|
+
}
|
|
737
|
+
if (rule.id === 'AGT-006' || rule.id === 'AGT-007') {
|
|
738
|
+
continue;
|
|
739
|
+
}
|
|
740
|
+
if (patternMatches(rule.pattern, rule.category === 'secrets' ? secretScanText : line.text)) {
|
|
741
|
+
const severity = line.inExample && rule.category === 'secrets' ? 'MEDIUM' : (line.inExample && rule.category === 'prompt_injection' ? 'INFO' : rule.severity);
|
|
742
|
+
findings.push(createFinding(document, rule, index + 1, line.section, line.text.trim(), severity, line.inExample ? 'MEDIUM' : 'HIGH'));
|
|
743
|
+
if (rule.category === 'secrets') {
|
|
744
|
+
secretScanText = secretScanText.replace(new RegExp(rule.pattern.source, `${rule.pattern.flags}g`), (match) => '$'.repeat(match.length));
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
if (markdown && !line.inCodeBlock && !line.inExample) {
|
|
749
|
+
for (const rule of astRules) {
|
|
750
|
+
if (rule.pattern.test(line.text)) {
|
|
751
|
+
const severity = rule.variantId === 'loader-directory-write' && /\.github\/skills\//i.test(line.text)
|
|
752
|
+
? 'CRITICAL'
|
|
753
|
+
: rule.severity;
|
|
754
|
+
const confidence = rule.variantId === 'collapsed-details' ? 'LOW' : (rule.severity === 'MEDIUM' ? 'MEDIUM' : 'HIGH');
|
|
755
|
+
findings.push(createFinding(document, rule, index + 1, line.section, line.text.trim(), severity, confidence));
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
if (markdown) {
|
|
761
|
+
findings.push(...scanContextualLineRules(document, parsed, cancellation), ...scanContextualDocumentRules(document, parsed), ...scanStructuredMarkdownRules(document, parsed));
|
|
762
|
+
}
|
|
763
|
+
if (markdown && agentConfig) {
|
|
764
|
+
const allowedTools = /allowed-tools|permissions?\.allow/i.test(document.content);
|
|
765
|
+
const denyTools = /deny-tools|permissions?\.deny|denied-tools/i.test(document.content);
|
|
766
|
+
const preToolUse = /PreToolUse/i.test(document.content);
|
|
767
|
+
if (allowedTools && !denyTools) {
|
|
768
|
+
const rule = makeRule('AGT-006', 'No Tool Deny List Configured', 'HIGH', /allowed-tools|permissions?\.allow/i, 'excessive_agency', OWASP_WEB);
|
|
769
|
+
findings.push(createFinding(document, rule, undefined, undefined, 'Allowed tools are declared without a deny list.'));
|
|
770
|
+
}
|
|
771
|
+
if (allowedTools && !preToolUse) {
|
|
772
|
+
const rule = makeRule('AGT-007', 'No PreToolUse Security Hook Configured', 'MEDIUM', /allowed-tools|permissions?\.allow/i, 'excessive_agency', OWASP_WEB);
|
|
773
|
+
findings.push(createFinding(document, rule, undefined, undefined, 'Allowed tools are declared without a PreToolUse hook.'));
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
if (markdown) {
|
|
777
|
+
const entropyRule = makeRule('SEC-013', 'High-Entropy String — Potential Secret', 'HIGH', assignment, 'secrets', LLM06);
|
|
778
|
+
for (const [index, line] of parsed.lines.entries()) {
|
|
779
|
+
assignment.lastIndex = 0;
|
|
780
|
+
let match = assignment.exec(line.text);
|
|
781
|
+
while (match !== null) {
|
|
782
|
+
if (entropy(match[1]) > 4.5 && !/^([0-9a-f]{8}-){4}[0-9a-f]{12}$/i.test(match[1])) {
|
|
783
|
+
findings.push({ ...createFinding(document, entropyRule, index + 1, line.section, line.text.trim(), line.inExample ? 'MEDIUM' : 'HIGH', 'MEDIUM') });
|
|
784
|
+
}
|
|
785
|
+
match = assignment.exec(line.text);
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
if (markdown) {
|
|
790
|
+
const rule = makeRule('INJ-002', 'Missing Trust Boundary — User Input in Instruction Block', 'HIGH', placeholder, 'prompt_injection', LLM01);
|
|
791
|
+
for (const [index, line] of parsed.lines.entries()) {
|
|
792
|
+
const placeholders = [...line.text.matchAll(new RegExp(placeholder.source, 'gi'))];
|
|
793
|
+
if (placeholders.some((match) => !hasTrustBoundaryForPlaceholder(line.text, match.index))) {
|
|
794
|
+
findings.push(createFinding(document, rule, index + 1, undefined, 'User-input variable found without a trust boundary.'));
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
if (markdown) {
|
|
799
|
+
const rule = makeRule('INJ-003', 'Invisible / Zero-Width Characters Detected', 'HIGH', invisible, 'prompt_injection', LLM01);
|
|
800
|
+
for (const [index, line] of parsed.lines.entries()) {
|
|
801
|
+
if (invisible.test(line.text)) {
|
|
802
|
+
findings.push(createFinding(document, rule, index + 1, line.section, line.text));
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
if (parsed.artifactClass === 'skill') {
|
|
806
|
+
const frontmatterName = /^name:\s*(.+)$/im.exec(parsed.frontmatter)?.[1]?.trim() ?? '';
|
|
807
|
+
if (/[\u0400-\u04FF\u0370-\u03FF]/.test(frontmatterName)) {
|
|
808
|
+
const findingRule = withDetails('SKL-004', 'Insecure Metadata — Confusable Homoglyph Characters in Skill Name (AST04)', 'HIGH', 'metadata_injection', AST.AST04, 'Confusable characters can impersonate a trusted skill name.', 'Use ASCII Latin characters in the skill name.', 'AST04:2026', 'homoglyph-name');
|
|
809
|
+
findings.push(createFinding(document, findingRule, 1, 'YAML Frontmatter', `name: ${frontmatterName}`, 'HIGH', 'MEDIUM'));
|
|
810
|
+
}
|
|
811
|
+
if (/\b(?:anthropic|openai|chatgpt|claude|github|microsoft|google|gemini|copilot|amazon|aws)\b/i.test(frontmatterName)) {
|
|
812
|
+
const findingRule = withDetails('SKL-004', 'Insecure Metadata — Brand Term in Skill Name (AST04)', 'LOW', 'metadata_injection', AST.AST04, 'A brand term in a skill name can signal impersonation or typosquatting.', 'Verify publisher ownership or remove the brand term.', 'AST04:2026', 'brand-name');
|
|
813
|
+
findings.push(createFinding(document, findingRule, 1, 'YAML Frontmatter', `name: ${frontmatterName}`, 'LOW', 'MEDIUM'));
|
|
814
|
+
}
|
|
815
|
+
if (!options.skipInfoControls && !/^\s*version\s*:/im.test(parsed.frontmatter)) {
|
|
816
|
+
const findingRule = withDetails('SKL-007', 'Update Drift — Missing Skill Version Metadata (AST07)', 'INFO', 'missing_control', AST.AST07, 'Without a version, consumers cannot detect update drift or identify affected releases.', 'Add a semantic version field to the skill frontmatter.', 'AST07:2026', 'missing-version');
|
|
817
|
+
findings.push({
|
|
818
|
+
...createFinding(document, findingRule, 1, 'YAML Frontmatter', "No 'version:' field found in skill manifest", 'INFO'),
|
|
819
|
+
isInfoControl: true
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
if (/\bplatforms?\s*:\s*\[/i.test(document.content)) {
|
|
823
|
+
for (const [index, line] of parsed.lines.entries()) {
|
|
824
|
+
if (!line.inCodeBlock && !line.inExample && /\b(?:Bash|Read|Write|Edit)\s*\(\s*\*{1,2}\s*\)/i.test(line.text)) {
|
|
825
|
+
const findingRule = withDetails('SKL-010', 'Cross-Platform Skill — Client-Specific Permission Syntax (AST10)', 'MEDIUM', 'cross_platform_risk', AST.AST10, 'Client-specific permission syntax can change meaning across declared platforms.', 'Use a platform-neutral permission model or explicit per-platform mappings.', 'AST10:2026', 'client-specific-permission');
|
|
826
|
+
findings.push(createFinding(document, findingRule, index + 1, line.section, line.text.trim(), 'MEDIUM', 'MEDIUM'));
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
if (options.includeLlmControls && parsed.artifactClass !== 'general_md') {
|
|
832
|
+
for (const control of activeDefenseRules) {
|
|
833
|
+
if (!control.pattern.test(document.content)) {
|
|
834
|
+
findings.push({ ...createFinding(document, control, undefined, undefined, 'Security control absent for this artifact.', control.severity, 'MEDIUM'), isInfoControl: false });
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
if (!options.skipInfoControls) {
|
|
838
|
+
const info = makeRule('CTL-001', 'No System Prompt Confidentiality Instruction', 'INFO', /never reveal.{0,100}(?:system prompt|instructions?|credentials?)/i, 'missing_control', LLM06);
|
|
839
|
+
if (!info.pattern.test(document.content)) {
|
|
840
|
+
findings.push({ ...createFinding(document, info, undefined, undefined, 'Security control absent for this artifact.'), isInfoControl: true });
|
|
841
|
+
}
|
|
842
|
+
for (const control of high_impact_rules_1.INFORMATIONAL_CONTROL_RULES) {
|
|
843
|
+
if (!patternMatches(control.pattern, document.content)) {
|
|
844
|
+
findings.push({
|
|
845
|
+
...createFinding(document, contextualPatternRule(control), undefined, undefined, 'Security control absent for this artifact.', control.severity, 'MEDIUM'),
|
|
846
|
+
isInfoControl: true
|
|
847
|
+
});
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
const limited = findings.slice(0, options.maxFindings);
|
|
854
|
+
if (!documentationOnly.test(basename)) {
|
|
855
|
+
return limited;
|
|
856
|
+
}
|
|
857
|
+
return limited.map((finding) => finding.severity === 'INFO'
|
|
858
|
+
? finding
|
|
859
|
+
: {
|
|
860
|
+
...finding,
|
|
861
|
+
severity: 'INFO',
|
|
862
|
+
risk: `${finding.risk} [Severity downgraded to INFO because this file is documentation-only.]`
|
|
863
|
+
});
|
|
864
|
+
};
|
|
865
|
+
class RuleBasedSecurityScanEngine {
|
|
866
|
+
descriptor = { id: 'builtin', version: ENGINE_VERSION, rulePackId: 'md-security-scanner', rulePackVersion: RULE_PACK_VERSION, rulePackDigest: packDigest };
|
|
867
|
+
capabilities = { contentTypes: ['text/markdown', 'application/json'], locations: 'line', supportsFileMode: false, supportsCancellation: true };
|
|
868
|
+
scanDocument(document, options, cancellation) {
|
|
869
|
+
return Promise.resolve().then(() => isClaudeSettings(document.displayPath)
|
|
870
|
+
? scanClaudeSettings(document, options, cancellation)
|
|
871
|
+
: scanText(document, options, cancellation, true));
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
exports.RuleBasedSecurityScanEngine = RuleBasedSecurityScanEngine;
|
|
875
|
+
//# sourceMappingURL=rule-engine.js.map
|