@complior/engine 0.9.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/.well-known/ai-compliance.json +16 -0
- package/COMPLIANCE.md +64 -0
- package/data/data-integrity.test.ts +75 -0
- package/data/eval/eval-mappings.json +33 -0
- package/data/llm/model-pricing.json +15 -0
- package/data/llm/model-routing.json +36 -0
- package/data/onboarding/risk-profile.json +17 -0
- package/data/regulations/eu-ai-act/README.md +245 -0
- package/data/regulations/eu-ai-act/applicability-tree.json +160 -0
- package/data/regulations/eu-ai-act/cross-mapping.json +175 -0
- package/data/regulations/eu-ai-act/localization.json +186 -0
- package/data/regulations/eu-ai-act/obligations.json +3981 -0
- package/data/regulations/eu-ai-act/regulation-meta.json +482 -0
- package/data/regulations/eu-ai-act/scoring.json +342 -0
- package/data/regulations/eu-ai-act/technical-requirements.json +2590 -0
- package/data/regulations/eu-ai-act/timeline.json +160 -0
- package/data/regulations/jurisdictions/at.json +15 -0
- package/data/regulations/jurisdictions/be.json +15 -0
- package/data/regulations/jurisdictions/bg.json +15 -0
- package/data/regulations/jurisdictions/cy.json +15 -0
- package/data/regulations/jurisdictions/cz.json +15 -0
- package/data/regulations/jurisdictions/de.json +15 -0
- package/data/regulations/jurisdictions/dk.json +15 -0
- package/data/regulations/jurisdictions/ee.json +15 -0
- package/data/regulations/jurisdictions/es.json +15 -0
- package/data/regulations/jurisdictions/fi.json +15 -0
- package/data/regulations/jurisdictions/fr.json +15 -0
- package/data/regulations/jurisdictions/gr.json +15 -0
- package/data/regulations/jurisdictions/hr.json +15 -0
- package/data/regulations/jurisdictions/hu.json +15 -0
- package/data/regulations/jurisdictions/ie.json +15 -0
- package/data/regulations/jurisdictions/is.json +15 -0
- package/data/regulations/jurisdictions/it.json +15 -0
- package/data/regulations/jurisdictions/li.json +15 -0
- package/data/regulations/jurisdictions/lt.json +15 -0
- package/data/regulations/jurisdictions/lu.json +15 -0
- package/data/regulations/jurisdictions/lv.json +15 -0
- package/data/regulations/jurisdictions/mt.json +15 -0
- package/data/regulations/jurisdictions/nl.json +15 -0
- package/data/regulations/jurisdictions/no.json +15 -0
- package/data/regulations/jurisdictions/pl.json +15 -0
- package/data/regulations/jurisdictions/pt.json +15 -0
- package/data/regulations/jurisdictions/ro.json +15 -0
- package/data/regulations/jurisdictions/se.json +15 -0
- package/data/regulations/jurisdictions/si.json +15 -0
- package/data/regulations/jurisdictions/sk.json +15 -0
- package/data/scanner/check-id-categories.json +81 -0
- package/data/scanner/confidence-params.json +16 -0
- package/data/scanner/limits.json +4 -0
- package/data/schemas/http-contract-sample.json +79 -0
- package/data/schemas/http-contract.json +144 -0
- package/data/semgrep-rules/bare-call.yaml +37 -0
- package/data/semgrep-rules/injection.yaml +73 -0
- package/data/semgrep-rules/missing-error-handling.yaml +58 -0
- package/data/semgrep-rules/unsafe-deser.yaml +65 -0
- package/data/templates/eu-ai-act/ai-literacy.md +184 -0
- package/data/templates/eu-ai-act/art5-screening.md +131 -0
- package/data/templates/eu-ai-act/data-governance.md +145 -0
- package/data/templates/eu-ai-act/declaration-of-conformity.md +161 -0
- package/data/templates/eu-ai-act/fria.md +127 -0
- package/data/templates/eu-ai-act/gpai-systemic-risk.md +150 -0
- package/data/templates/eu-ai-act/gpai-transparency.md +166 -0
- package/data/templates/eu-ai-act/incident-report.md +188 -0
- package/data/templates/eu-ai-act/instructions-for-use.md +202 -0
- package/data/templates/eu-ai-act/monitoring-policy.md +110 -0
- package/data/templates/eu-ai-act/qms.md +180 -0
- package/data/templates/eu-ai-act/risk-management-system.md +123 -0
- package/data/templates/eu-ai-act/technical-documentation.md +287 -0
- package/data/templates/eu-ai-act/worker-notification.md +143 -0
- package/data/templates/policies/biometrics-ai-policy.md +214 -0
- package/data/templates/policies/critical-infra-ai-policy.md +228 -0
- package/data/templates/policies/education-ai-policy.md +184 -0
- package/data/templates/policies/finance-ai-policy.md +191 -0
- package/data/templates/policies/healthcare-ai-policy.md +197 -0
- package/data/templates/policies/hr-ai-policy.md +178 -0
- package/data/templates/policies/legal-ai-policy.md +189 -0
- package/data/templates/policies/migration-ai-policy.md +239 -0
- package/engine.log +7 -0
- package/package.json +74 -0
- package/src/composition-root.ts +791 -0
- package/src/data/eval/conformity-tests.test.ts +122 -0
- package/src/data/eval/ct-1-transparency.ts +106 -0
- package/src/data/eval/ct-10-gpai.ts +25 -0
- package/src/data/eval/ct-11-industry.ts +42 -0
- package/src/data/eval/ct-2-oversight.ts +41 -0
- package/src/data/eval/ct-3-explanation.ts +14 -0
- package/src/data/eval/ct-4-bias.ts +83 -0
- package/src/data/eval/ct-5-accuracy.ts +41 -0
- package/src/data/eval/ct-6-robustness.ts +81 -0
- package/src/data/eval/ct-7-prohibited.ts +52 -0
- package/src/data/eval/ct-8-logging.ts +68 -0
- package/src/data/eval/ct-9-risk-awareness.ts +33 -0
- package/src/data/eval/deterministic-evaluator.ts +120 -0
- package/src/data/eval/index.ts +55 -0
- package/src/data/eval/judge-prompts.ts +146 -0
- package/src/data/eval/llm-judged-tests.ts +279 -0
- package/src/data/eval/llm-tests.test.ts +83 -0
- package/src/data/eval/remediation/ct-1-transparency.ts +91 -0
- package/src/data/eval/remediation/ct-10-gpai.ts +94 -0
- package/src/data/eval/remediation/ct-11-industry.ts +94 -0
- package/src/data/eval/remediation/ct-2-oversight.ts +71 -0
- package/src/data/eval/remediation/ct-3-explanation.ts +70 -0
- package/src/data/eval/remediation/ct-4-bias.ts +70 -0
- package/src/data/eval/remediation/ct-5-accuracy.ts +70 -0
- package/src/data/eval/remediation/ct-6-robustness.ts +70 -0
- package/src/data/eval/remediation/ct-7-prohibited.ts +94 -0
- package/src/data/eval/remediation/ct-8-logging.ts +94 -0
- package/src/data/eval/remediation/ct-9-risk-awareness.ts +94 -0
- package/src/data/eval/remediation/index.ts +89 -0
- package/src/data/eval/remediation/owasp-art5.ts +15 -0
- package/src/data/eval/remediation/owasp-llm01.ts +72 -0
- package/src/data/eval/remediation/owasp-llm02.ts +72 -0
- package/src/data/eval/remediation/owasp-llm03.ts +15 -0
- package/src/data/eval/remediation/owasp-llm04.ts +15 -0
- package/src/data/eval/remediation/owasp-llm05.ts +15 -0
- package/src/data/eval/remediation/owasp-llm06.ts +15 -0
- package/src/data/eval/remediation/owasp-llm07.ts +15 -0
- package/src/data/eval/remediation/owasp-llm08.ts +15 -0
- package/src/data/eval/remediation/owasp-llm09.ts +15 -0
- package/src/data/eval/remediation/owasp-llm10.ts +15 -0
- package/src/data/eval/remediation/remediation.test.ts +229 -0
- package/src/data/eval/remediation/test-mapping.ts +290 -0
- package/src/data/eval/security-rubrics.ts +381 -0
- package/src/data/finding-explanations.json +453 -0
- package/src/data/industry-patterns.ts +161 -0
- package/src/data/registry-cards.ts +368 -0
- package/src/data/regulation/index.ts +5 -0
- package/src/data/regulation/jurisdiction-data.test.ts +73 -0
- package/src/data/regulation/jurisdiction-data.ts +65 -0
- package/src/data/regulation/regulation-data.ts +19 -0
- package/src/data/regulation/regulation-loader.test.ts +107 -0
- package/src/data/regulation/regulation-loader.ts +56 -0
- package/src/data/scanner-constants.ts +46 -0
- package/src/data/schemas/schemas-core.ts +140 -0
- package/src/data/schemas/schemas-supplementary.ts +211 -0
- package/src/data/schemas/schemas.ts +28 -0
- package/src/data/security/attack-probes.test.ts +62 -0
- package/src/data/security/attack-probes.ts +496 -0
- package/src/data/security/eu-ai-act-security.ts +40 -0
- package/src/data/security/index.ts +19 -0
- package/src/data/security/mitre-atlas.test.ts +43 -0
- package/src/data/security/mitre-atlas.ts +93 -0
- package/src/data/security/nist-ai-rmf.ts +43 -0
- package/src/data/security/owasp-llm-top10.test.ts +60 -0
- package/src/data/security/owasp-llm-top10.ts +138 -0
- package/src/data/template-registry.ts +53 -0
- package/src/data/tool-versions.json +22 -0
- package/src/domain/audit/audit-package.test.ts +152 -0
- package/src/domain/audit/audit-package.ts +166 -0
- package/src/domain/audit/audit-trail.test.ts +121 -0
- package/src/domain/audit/audit-trail.ts +174 -0
- package/src/domain/audit/index.ts +8 -0
- package/src/domain/audit/permissions-matrix.test.ts +136 -0
- package/src/domain/audit/permissions-matrix.ts +121 -0
- package/src/domain/certification/adversarial/bias-tests.ts +95 -0
- package/src/domain/certification/adversarial/evaluators.ts +304 -0
- package/src/domain/certification/adversarial/index.ts +11 -0
- package/src/domain/certification/adversarial/prompt-injection.ts +103 -0
- package/src/domain/certification/adversarial/safety-boundary.ts +132 -0
- package/src/domain/certification/aiuc1-readiness.test.ts +236 -0
- package/src/domain/certification/aiuc1-readiness.ts +298 -0
- package/src/domain/certification/aiuc1-requirements.ts +235 -0
- package/src/domain/certification/index.ts +10 -0
- package/src/domain/certification/redteam-runner.test.ts +97 -0
- package/src/domain/certification/redteam-runner.ts +205 -0
- package/src/domain/certification/test-runner.test.ts +232 -0
- package/src/domain/certification/test-runner.ts +289 -0
- package/src/domain/cost/cost-estimator.test.ts +187 -0
- package/src/domain/cost/cost-estimator.ts +133 -0
- package/src/domain/disclaimer.test.ts +52 -0
- package/src/domain/disclaimer.ts +39 -0
- package/src/domain/documents/ai-enricher.test.ts +120 -0
- package/src/domain/documents/ai-enricher.ts +159 -0
- package/src/domain/documents/document-generator.test.ts +318 -0
- package/src/domain/documents/document-generator.ts +239 -0
- package/src/domain/documents/index.ts +9 -0
- package/src/domain/documents/passport-helpers.ts +25 -0
- package/src/domain/documents/policy-generator.test.ts +252 -0
- package/src/domain/documents/policy-generator.ts +94 -0
- package/src/domain/documents/worker-notification-generator.test.ts +162 -0
- package/src/domain/documents/worker-notification-generator.ts +141 -0
- package/src/domain/eval/adapters/adapter-port.ts +94 -0
- package/src/domain/eval/adapters/adapters.test.ts +303 -0
- package/src/domain/eval/adapters/anthropic-adapter.ts +57 -0
- package/src/domain/eval/adapters/auto-detect.ts +104 -0
- package/src/domain/eval/adapters/create-chat-adapter.ts +106 -0
- package/src/domain/eval/adapters/custom-adapter.ts +74 -0
- package/src/domain/eval/adapters/http-adapter.ts +66 -0
- package/src/domain/eval/adapters/index.ts +7 -0
- package/src/domain/eval/adapters/ollama-adapter.ts +48 -0
- package/src/domain/eval/adapters/openai-adapter.ts +58 -0
- package/src/domain/eval/adapters/with-timeout.ts +25 -0
- package/src/domain/eval/conformity-score.test.ts +161 -0
- package/src/domain/eval/conformity-score.ts +135 -0
- package/src/domain/eval/eval-constants.ts +55 -0
- package/src/domain/eval/eval-evidence.test.ts +85 -0
- package/src/domain/eval/eval-evidence.ts +103 -0
- package/src/domain/eval/eval-fix-generator.test.ts +421 -0
- package/src/domain/eval/eval-fix-generator.ts +205 -0
- package/src/domain/eval/eval-passport.test.ts +82 -0
- package/src/domain/eval/eval-passport.ts +89 -0
- package/src/domain/eval/eval-remediation-report.test.ts +682 -0
- package/src/domain/eval/eval-remediation-report.ts +170 -0
- package/src/domain/eval/eval-report.ts +108 -0
- package/src/domain/eval/eval-runner.test.ts +609 -0
- package/src/domain/eval/eval-runner.ts +593 -0
- package/src/domain/eval/eval-to-findings.test.ts +293 -0
- package/src/domain/eval/eval-to-findings.ts +83 -0
- package/src/domain/eval/index.ts +31 -0
- package/src/domain/eval/llm-judge.test.ts +139 -0
- package/src/domain/eval/llm-judge.ts +168 -0
- package/src/domain/eval/remediation-types.ts +90 -0
- package/src/domain/eval/security-integration.test.ts +196 -0
- package/src/domain/eval/security-integration.ts +136 -0
- package/src/domain/eval/types.test.ts +173 -0
- package/src/domain/eval/types.ts +244 -0
- package/src/domain/eval/verdict-utils.ts +45 -0
- package/src/domain/fixer/create-fixer.ts +101 -0
- package/src/domain/fixer/diff.ts +70 -0
- package/src/domain/fixer/fix-history.ts +23 -0
- package/src/domain/fixer/fixer.test.ts +306 -0
- package/src/domain/fixer/index.ts +9 -0
- package/src/domain/fixer/strategies/bandit-fix.ts +61 -0
- package/src/domain/fixer/strategies/bias-testing.ts +49 -0
- package/src/domain/fixer/strategies/ci-compliance.ts +57 -0
- package/src/domain/fixer/strategies/content-marking.ts +45 -0
- package/src/domain/fixer/strategies/cve-upgrade.ts +66 -0
- package/src/domain/fixer/strategies/data-governance.ts +65 -0
- package/src/domain/fixer/strategies/disclosure.ts +69 -0
- package/src/domain/fixer/strategies/doc-code-sync.ts +53 -0
- package/src/domain/fixer/strategies/documentation.ts +59 -0
- package/src/domain/fixer/strategies/error-handler.ts +63 -0
- package/src/domain/fixer/strategies/hitl-gate.ts +67 -0
- package/src/domain/fixer/strategies/index.ts +61 -0
- package/src/domain/fixer/strategies/kill-switch-test.ts +85 -0
- package/src/domain/fixer/strategies/kill-switch.ts +53 -0
- package/src/domain/fixer/strategies/license-fix.ts +57 -0
- package/src/domain/fixer/strategies/log-retention.ts +40 -0
- package/src/domain/fixer/strategies/logging.ts +59 -0
- package/src/domain/fixer/strategies/metadata.ts +45 -0
- package/src/domain/fixer/strategies/permission-guard.ts +84 -0
- package/src/domain/fixer/strategies/record-keeping.ts +69 -0
- package/src/domain/fixer/strategies/secret-rotation.ts +52 -0
- package/src/domain/fixer/strategies.test.ts +341 -0
- package/src/domain/fixer/template-engine.test.ts +64 -0
- package/src/domain/fixer/template-engine.ts +38 -0
- package/src/domain/fixer/types.ts +88 -0
- package/src/domain/frameworks/aiuc1-framework.test.ts +159 -0
- package/src/domain/frameworks/aiuc1-framework.ts +126 -0
- package/src/domain/frameworks/collect-foundation-metrics.test.ts +96 -0
- package/src/domain/frameworks/collect-foundation-metrics.ts +34 -0
- package/src/domain/frameworks/eu-ai-act-framework.test.ts +117 -0
- package/src/domain/frameworks/eu-ai-act-framework.ts +100 -0
- package/src/domain/frameworks/framework-registry.test.ts +91 -0
- package/src/domain/frameworks/framework-registry.ts +38 -0
- package/src/domain/frameworks/index.ts +8 -0
- package/src/domain/frameworks/mitre-atlas-framework.test.ts +53 -0
- package/src/domain/frameworks/mitre-atlas-framework.ts +53 -0
- package/src/domain/frameworks/owasp-llm-framework.test.ts +77 -0
- package/src/domain/frameworks/owasp-llm-framework.ts +54 -0
- package/src/domain/frameworks/score-plugin-framework.ts +117 -0
- package/src/domain/fria/fria-generator.test.ts +273 -0
- package/src/domain/fria/fria-generator.ts +366 -0
- package/src/domain/import/promptfoo-importer.test.ts +103 -0
- package/src/domain/import/promptfoo-importer.ts +151 -0
- package/src/domain/onboarding/guided-onboarding.test.ts +144 -0
- package/src/domain/onboarding/guided-onboarding.ts +135 -0
- package/src/domain/passport/builder/domain-mapper.ts +9 -0
- package/src/domain/passport/builder/manifest-builder.test.ts +546 -0
- package/src/domain/passport/builder/manifest-builder.ts +535 -0
- package/src/domain/passport/builder/manifest-diff.test.ts +105 -0
- package/src/domain/passport/builder/manifest-diff.ts +89 -0
- package/src/domain/passport/builder/manifest-files.ts +17 -0
- package/src/domain/passport/crypto-signer.test.ts +93 -0
- package/src/domain/passport/crypto-signer.ts +157 -0
- package/src/domain/passport/discovery/agent-discovery.test.ts +296 -0
- package/src/domain/passport/discovery/agent-discovery.ts +325 -0
- package/src/domain/passport/discovery/autonomy-analyzer.test.ts +141 -0
- package/src/domain/passport/discovery/autonomy-analyzer.ts +113 -0
- package/src/domain/passport/discovery/permission-scanner.test.ts +191 -0
- package/src/domain/passport/discovery/permission-scanner.ts +414 -0
- package/src/domain/passport/export/a2a-mapper.ts +75 -0
- package/src/domain/passport/export/aiuc1-mapper.ts +126 -0
- package/src/domain/passport/export/export.test.ts +207 -0
- package/src/domain/passport/export/index.ts +41 -0
- package/src/domain/passport/export/nist-mapper.ts +227 -0
- package/src/domain/passport/import/a2a-importer.test.ts +133 -0
- package/src/domain/passport/import/a2a-importer.ts +156 -0
- package/src/domain/passport/import/index.ts +2 -0
- package/src/domain/passport/index.ts +32 -0
- package/src/domain/passport/obligation-field-map.test.ts +113 -0
- package/src/domain/passport/obligation-field-map.ts +117 -0
- package/src/domain/passport/passport-validator.test.ts +156 -0
- package/src/domain/passport/passport-validator.ts +126 -0
- package/src/domain/passport/scan-to-compliance.test.ts +336 -0
- package/src/domain/passport/scan-to-compliance.ts +166 -0
- package/src/domain/passport/test-generator.test.ts +93 -0
- package/src/domain/passport/test-generator.ts +136 -0
- package/src/domain/proxy/index.ts +11 -0
- package/src/domain/proxy/json-rpc.test.ts +72 -0
- package/src/domain/proxy/json-rpc.ts +53 -0
- package/src/domain/proxy/policy-engine.test.ts +259 -0
- package/src/domain/proxy/policy-engine.ts +137 -0
- package/src/domain/proxy/proxy-bridge.ts +125 -0
- package/src/domain/proxy/proxy-interceptor.test.ts +184 -0
- package/src/domain/proxy/proxy-interceptor.ts +120 -0
- package/src/domain/proxy/proxy-types.ts +35 -0
- package/src/domain/registry/compute-agent-score.test.ts +279 -0
- package/src/domain/registry/compute-agent-score.ts +162 -0
- package/src/domain/reporter/audit-report.test.ts +87 -0
- package/src/domain/reporter/audit-report.ts +116 -0
- package/src/domain/reporter/badge-generator.test.ts +54 -0
- package/src/domain/reporter/badge-generator.ts +40 -0
- package/src/domain/reporter/compliance-md.ts +45 -0
- package/src/domain/reporter/index.ts +7 -0
- package/src/domain/reporter/pdf-renderer.ts +282 -0
- package/src/domain/reporter/share.test.ts +92 -0
- package/src/domain/reporter/share.ts +80 -0
- package/src/domain/scanner/ast/swc-analyzer.test.ts +49 -0
- package/src/domain/scanner/ast/swc-analyzer.ts +124 -0
- package/src/domain/scanner/attestations.ts +97 -0
- package/src/domain/scanner/checks/ai-disclosure.test.ts +90 -0
- package/src/domain/scanner/checks/ai-disclosure.ts +54 -0
- package/src/domain/scanner/checks/ai-literacy.ts +163 -0
- package/src/domain/scanner/checks/behavioral-constraints.test.ts +167 -0
- package/src/domain/scanner/checks/behavioral-constraints.ts +86 -0
- package/src/domain/scanner/checks/compliance-metadata.ts +63 -0
- package/src/domain/scanner/checks/content-marking.ts +74 -0
- package/src/domain/scanner/checks/dep-deep-scan.test.ts +318 -0
- package/src/domain/scanner/checks/dep-deep-scan.ts +137 -0
- package/src/domain/scanner/checks/documentation.test.ts +88 -0
- package/src/domain/scanner/checks/documentation.ts +79 -0
- package/src/domain/scanner/checks/git-history.test.ts +120 -0
- package/src/domain/scanner/checks/git-history.ts +163 -0
- package/src/domain/scanner/checks/gpai-systemic-risk.test.ts +84 -0
- package/src/domain/scanner/checks/gpai-systemic-risk.ts +98 -0
- package/src/domain/scanner/checks/gpai-transparency.ts +94 -0
- package/src/domain/scanner/checks/index.ts +28 -0
- package/src/domain/scanner/checks/industry/index.ts +40 -0
- package/src/domain/scanner/checks/industry/industry.test.ts +287 -0
- package/src/domain/scanner/checks/interaction-logging.test.ts +113 -0
- package/src/domain/scanner/checks/interaction-logging.ts +142 -0
- package/src/domain/scanner/checks/nhi-scanner.test.ts +158 -0
- package/src/domain/scanner/checks/nhi-scanner.ts +78 -0
- package/src/domain/scanner/checks/passport-completeness.test.ts +127 -0
- package/src/domain/scanner/checks/passport-completeness.ts +82 -0
- package/src/domain/scanner/checks/passport-presence.test.ts +56 -0
- package/src/domain/scanner/checks/passport-presence.ts +78 -0
- package/src/domain/scanner/checks/pattern-check-factory.ts +70 -0
- package/src/domain/scanner/checks/permission-scanner.test.ts +279 -0
- package/src/domain/scanner/checks/permission-scanner.ts +90 -0
- package/src/domain/scanner/checks/presence-check-factory.test.ts +124 -0
- package/src/domain/scanner/checks/presence-check-factory.ts +275 -0
- package/src/domain/scanner/compliance-diff.test.ts +165 -0
- package/src/domain/scanner/compliance-diff.ts +138 -0
- package/src/domain/scanner/confidence.test.ts +235 -0
- package/src/domain/scanner/confidence.ts +156 -0
- package/src/domain/scanner/constants.ts +13 -0
- package/src/domain/scanner/create-scanner.ts +573 -0
- package/src/domain/scanner/cross-layer.test.ts +372 -0
- package/src/domain/scanner/cross-layer.ts +232 -0
- package/src/domain/scanner/data/ai-packages.ts +82 -0
- package/src/domain/scanner/debt-calculator.test.ts +89 -0
- package/src/domain/scanner/debt-calculator.ts +111 -0
- package/src/domain/scanner/drift.test.ts +191 -0
- package/src/domain/scanner/drift.ts +73 -0
- package/src/domain/scanner/evidence-store.test.ts +207 -0
- package/src/domain/scanner/evidence-store.ts +195 -0
- package/src/domain/scanner/evidence.test.ts +104 -0
- package/src/domain/scanner/evidence.ts +71 -0
- package/src/domain/scanner/external/bandit-runner.test.ts +45 -0
- package/src/domain/scanner/external/bandit-runner.ts +90 -0
- package/src/domain/scanner/external/checks.ts +321 -0
- package/src/domain/scanner/external/dedup.test.ts +79 -0
- package/src/domain/scanner/external/dedup.ts +94 -0
- package/src/domain/scanner/external/detect-secrets-runner.test.ts +58 -0
- package/src/domain/scanner/external/detect-secrets-runner.ts +81 -0
- package/src/domain/scanner/external/external-scanner.test.ts +221 -0
- package/src/domain/scanner/external/external-scanner.ts +36 -0
- package/src/domain/scanner/external/finding-mapper.test.ts +95 -0
- package/src/domain/scanner/external/finding-mapper.ts +138 -0
- package/src/domain/scanner/external/index.ts +15 -0
- package/src/domain/scanner/external/mappings.ts +93 -0
- package/src/domain/scanner/external/modelscan-runner.test.ts +35 -0
- package/src/domain/scanner/external/modelscan-runner.ts +101 -0
- package/src/domain/scanner/external/path-utils.ts +8 -0
- package/src/domain/scanner/external/runner-port.ts +45 -0
- package/src/domain/scanner/external/semgrep-runner.test.ts +52 -0
- package/src/domain/scanner/external/semgrep-runner.ts +94 -0
- package/src/domain/scanner/external/types.ts +32 -0
- package/src/domain/scanner/finding-attribution.test.ts +444 -0
- package/src/domain/scanner/finding-attribution.ts +195 -0
- package/src/domain/scanner/finding-explainer.test.ts +157 -0
- package/src/domain/scanner/finding-explainer.ts +73 -0
- package/src/domain/scanner/fix-diff-builder.test.ts +272 -0
- package/src/domain/scanner/fix-diff-builder.ts +477 -0
- package/src/domain/scanner/import-graph.test.ts +162 -0
- package/src/domain/scanner/import-graph.ts +198 -0
- package/src/domain/scanner/languages/adapter.test.ts +105 -0
- package/src/domain/scanner/languages/adapter.ts +239 -0
- package/src/domain/scanner/layers/index.ts +24 -0
- package/src/domain/scanner/layers/layer1-files.ts +54 -0
- package/src/domain/scanner/layers/layer2-docs.test.ts +1207 -0
- package/src/domain/scanner/layers/layer2-docs.ts +297 -0
- package/src/domain/scanner/layers/layer2-parsing.ts +217 -0
- package/src/domain/scanner/layers/layer3-config.test.ts +187 -0
- package/src/domain/scanner/layers/layer3-config.ts +279 -0
- package/src/domain/scanner/layers/layer3-parsers.ts +73 -0
- package/src/domain/scanner/layers/layer4-patterns.test.ts +397 -0
- package/src/domain/scanner/layers/layer4-patterns.ts +216 -0
- package/src/domain/scanner/layers/layer5-docs.test.ts +99 -0
- package/src/domain/scanner/layers/layer5-docs.ts +250 -0
- package/src/domain/scanner/layers/layer5-llm.test.ts +146 -0
- package/src/domain/scanner/layers/layer5-llm.ts +262 -0
- package/src/domain/scanner/layers/layer5-targeted.test.ts +93 -0
- package/src/domain/scanner/layers/layer5-targeted.ts +233 -0
- package/src/domain/scanner/layers/lockfile-parsers.test.ts +320 -0
- package/src/domain/scanner/layers/lockfile-parsers.ts +184 -0
- package/src/domain/scanner/regulation-version.test.ts +54 -0
- package/src/domain/scanner/regulation-version.ts +23 -0
- package/src/domain/scanner/role-filter.test.ts +116 -0
- package/src/domain/scanner/role-filter.ts +51 -0
- package/src/domain/scanner/rules/banned-packages-data.ts +553 -0
- package/src/domain/scanner/rules/banned-packages-sdk.ts +65 -0
- package/src/domain/scanner/rules/banned-packages.test.ts +249 -0
- package/src/domain/scanner/rules/banned-packages.ts +55 -0
- package/src/domain/scanner/rules/comment-filter.test.ts +115 -0
- package/src/domain/scanner/rules/comment-filter.ts +297 -0
- package/src/domain/scanner/rules/index.ts +9 -0
- package/src/domain/scanner/rules/nhi-patterns.test.ts +128 -0
- package/src/domain/scanner/rules/nhi-patterns.ts +60 -0
- package/src/domain/scanner/rules/pattern-rules.ts +1152 -0
- package/src/domain/scanner/sbom.test.ts +136 -0
- package/src/domain/scanner/sbom.ts +103 -0
- package/src/domain/scanner/scan-cache.test.ts +136 -0
- package/src/domain/scanner/scan-cache.ts +115 -0
- package/src/domain/scanner/scanner.test.ts +125 -0
- package/src/domain/scanner/score-calculator.test.ts +363 -0
- package/src/domain/scanner/score-calculator.ts +189 -0
- package/src/domain/scanner/security-score.test.ts +107 -0
- package/src/domain/scanner/security-score.ts +116 -0
- package/src/domain/scanner/source-filter.ts +24 -0
- package/src/domain/scanner/validators.ts +223 -0
- package/src/domain/shared/compliance-constants.ts +48 -0
- package/src/domain/shared/disclosure-patterns.ts +16 -0
- package/src/domain/shared/index.ts +6 -0
- package/src/domain/shared/parse-dependencies.ts +21 -0
- package/src/domain/supply-chain/dependency-analyzer.ts +138 -0
- package/src/domain/supply-chain/index.ts +3 -0
- package/src/domain/supply-chain/supply-chain.test.ts +211 -0
- package/src/domain/supply-chain/types.ts +32 -0
- package/src/domain/whatif/config-fixer.ts +187 -0
- package/src/domain/whatif/index.ts +6 -0
- package/src/domain/whatif/scenario-engine.ts +121 -0
- package/src/domain/whatif/simulate-actions.test.ts +161 -0
- package/src/domain/whatif/simulate-actions.ts +114 -0
- package/src/domain/whatif/whatif.test.ts +135 -0
- package/src/e2e/gaps-e2e.test.ts +259 -0
- package/src/e2e/smoke.test.ts +101 -0
- package/src/hooks/hooks-export.test.ts +81 -0
- package/src/hooks/installer.ts +113 -0
- package/src/http/cors.test.ts +38 -0
- package/src/http/create-router.ts +259 -0
- package/src/http/routes/agent.route.ts +380 -0
- package/src/http/routes/audit.route.ts +66 -0
- package/src/http/routes/badge.route.ts +23 -0
- package/src/http/routes/cert.route.ts +66 -0
- package/src/http/routes/chat.route.ts +228 -0
- package/src/http/routes/cost.route.ts +33 -0
- package/src/http/routes/debt.route.ts +29 -0
- package/src/http/routes/disclaimer.route.ts +64 -0
- package/src/http/routes/eval.route.ts +161 -0
- package/src/http/routes/events.route.test.ts +108 -0
- package/src/http/routes/events.route.ts +71 -0
- package/src/http/routes/external-scan.route.ts +24 -0
- package/src/http/routes/file.route.ts +54 -0
- package/src/http/routes/fix.route.ts +219 -0
- package/src/http/routes/frameworks.route.test.ts +66 -0
- package/src/http/routes/frameworks.route.ts +36 -0
- package/src/http/routes/git.route.ts +27 -0
- package/src/http/routes/guided-onboarding.route.ts +65 -0
- package/src/http/routes/import.route.ts +64 -0
- package/src/http/routes/jurisdiction.route.ts +22 -0
- package/src/http/routes/obligations.route.test.ts +122 -0
- package/src/http/routes/obligations.route.ts +110 -0
- package/src/http/routes/onboarding.route.ts +53 -0
- package/src/http/routes/provider.route.ts +42 -0
- package/src/http/routes/proxy.route.ts +40 -0
- package/src/http/routes/redteam.route.ts +84 -0
- package/src/http/routes/report.route.ts +29 -0
- package/src/http/routes/scan.route.ts +104 -0
- package/src/http/routes/share.route.ts +44 -0
- package/src/http/routes/shell.route.ts +27 -0
- package/src/http/routes/status.route.ts +66 -0
- package/src/http/routes/supply-chain.route.ts +121 -0
- package/src/http/routes/sync.route.ts +328 -0
- package/src/http/routes/tools.route.ts +29 -0
- package/src/http/routes/whatif.route.ts +96 -0
- package/src/http/utils/validation.ts +31 -0
- package/src/index.ts +1 -0
- package/src/infra/bundle-fetcher.ts +77 -0
- package/src/infra/cache-storage.ts +34 -0
- package/src/infra/event-bus.ts +31 -0
- package/src/infra/file-collector.ts +61 -0
- package/src/infra/file-ops-adapter.ts +95 -0
- package/src/infra/file-watcher.test.ts +90 -0
- package/src/infra/file-watcher.ts +106 -0
- package/src/infra/git-adapter.ts +93 -0
- package/src/infra/git-history-adapter.ts +41 -0
- package/src/infra/headless-browser.ts +178 -0
- package/src/infra/llm-adapter.test.ts +83 -0
- package/src/infra/llm-adapter.ts +86 -0
- package/src/infra/logger.ts +27 -0
- package/src/infra/project-config.test.ts +74 -0
- package/src/infra/project-config.ts +35 -0
- package/src/infra/rate-limiter.test.ts +36 -0
- package/src/infra/rate-limiter.ts +34 -0
- package/src/infra/retry.ts +46 -0
- package/src/infra/saas-client.ts +123 -0
- package/src/infra/search-adapter.ts +113 -0
- package/src/infra/shell-adapter.ts +68 -0
- package/src/infra/tool-manager.test.ts +99 -0
- package/src/infra/tool-manager.ts +197 -0
- package/src/llm/agents/agent-modes.test.ts +44 -0
- package/src/llm/agents/modes.ts +68 -0
- package/src/llm/routing/cost-routing.test.ts +37 -0
- package/src/llm/routing/cost-tracker.ts +74 -0
- package/src/llm/routing/model-routing.test.ts +79 -0
- package/src/llm/routing/model-routing.ts +38 -0
- package/src/llm/routing/pricing.ts +19 -0
- package/src/llm/sse-protocol.ts +77 -0
- package/src/llm/tool-definitions.ts +83 -0
- package/src/llm/tool-executors.ts +80 -0
- package/src/llm/tools/types.ts +13 -0
- package/src/mcp/create-mcp-stack.ts +82 -0
- package/src/mcp/handlers.ts +245 -0
- package/src/mcp/index.ts +28 -0
- package/src/mcp/mcp-server.test.ts +80 -0
- package/src/mcp/server.ts +79 -0
- package/src/mcp/tools.ts +48 -0
- package/src/onboarding/auto-detect.ts +164 -0
- package/src/onboarding/onboarding.test.ts +89 -0
- package/src/onboarding/profile.ts +169 -0
- package/src/onboarding/questions.ts +112 -0
- package/src/onboarding/wizard.ts +66 -0
- package/src/output/github-issue.ts +32 -0
- package/src/output/json-output.ts +67 -0
- package/src/ports/browser.port.ts +23 -0
- package/src/ports/events.port.ts +28 -0
- package/src/ports/llm.port.ts +23 -0
- package/src/ports/logger.port.ts +6 -0
- package/src/ports/process.port.ts +6 -0
- package/src/ports/scanner.port.ts +15 -0
- package/src/server.ts +134 -0
- package/src/services/badge-service.ts +67 -0
- package/src/services/chat-service.test.ts +162 -0
- package/src/services/chat-service.ts +152 -0
- package/src/services/cost-service.ts +52 -0
- package/src/services/debt-service.ts +65 -0
- package/src/services/eval-integration.test.ts +132 -0
- package/src/services/eval-service.test.ts +373 -0
- package/src/services/eval-service.ts +463 -0
- package/src/services/external-scan-service.ts +60 -0
- package/src/services/file-service.ts +37 -0
- package/src/services/fix-service.test.ts +470 -0
- package/src/services/fix-service.ts +648 -0
- package/src/services/framework-service.test.ts +159 -0
- package/src/services/framework-service.ts +67 -0
- package/src/services/onboarding-service.ts +165 -0
- package/src/services/passport-audit.ts +244 -0
- package/src/services/passport-documents.ts +258 -0
- package/src/services/passport-service-utils.ts +72 -0
- package/src/services/passport-service.test.ts +251 -0
- package/src/services/passport-service.ts +339 -0
- package/src/services/proxy-service.ts +81 -0
- package/src/services/report-service.ts +72 -0
- package/src/services/scan-service.test.ts +470 -0
- package/src/services/scan-service.ts +335 -0
- package/src/services/share-service.ts +108 -0
- package/src/services/shared/backup.ts +23 -0
- package/src/services/status-service.ts +38 -0
- package/src/services/undo-service.test.ts +190 -0
- package/src/services/undo-service.ts +144 -0
- package/src/test-helpers/factories.ts +116 -0
- package/src/types/common.schemas.ts +147 -0
- package/src/types/common.types.ts +292 -0
- package/src/types/contract.test.ts +217 -0
- package/src/types/errors.ts +52 -0
- package/src/types/framework.types.ts +87 -0
- package/src/types/passport-schemas.ts +241 -0
- package/src/types/passport.types.ts +296 -0
- package/src/version.ts +1 -0
- package/tsconfig.json +20 -0
- package/vitest.config.ts +9 -0
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import type { ExternalCheck, PageData } from './types.js';
|
|
2
|
+
import { CORE_DISCLOSURE_PATTERNS } from '../../shared/disclosure-patterns.js';
|
|
3
|
+
|
|
4
|
+
/** Page-specific disclosure patterns (beyond core). */
|
|
5
|
+
const PAGE_SPECIFIC_PATTERNS: readonly RegExp[] = [
|
|
6
|
+
/generated by ai/i,
|
|
7
|
+
/language model/i,
|
|
8
|
+
/chatbot/i,
|
|
9
|
+
/ai[- ]?enabled/i,
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
const AI_DISCLOSURE_PATTERNS: readonly RegExp[] = [
|
|
13
|
+
...CORE_DISCLOSURE_PATTERNS,
|
|
14
|
+
...PAGE_SPECIFIC_PATTERNS,
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
export const checkAiDisclosure = (page: PageData): ExternalCheck => {
|
|
18
|
+
const html = page.html.toLowerCase();
|
|
19
|
+
const matched = AI_DISCLOSURE_PATTERNS.find((p) => p.test(html));
|
|
20
|
+
|
|
21
|
+
if (matched) {
|
|
22
|
+
const match = html.match(matched);
|
|
23
|
+
return {
|
|
24
|
+
name: 'AI Disclosure Text',
|
|
25
|
+
status: 'PASS',
|
|
26
|
+
obligation: 'OBL-015',
|
|
27
|
+
article: 'Art. 50(1)',
|
|
28
|
+
evidence: `AI disclosure found: "${match?.[0] ?? 'detected'}"`,
|
|
29
|
+
confidence: 85,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
name: 'AI Disclosure Text',
|
|
35
|
+
status: 'FAIL',
|
|
36
|
+
obligation: 'OBL-015',
|
|
37
|
+
article: 'Art. 50(1)',
|
|
38
|
+
evidence: 'No AI disclosure text found on page',
|
|
39
|
+
confidence: 80,
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const checkWellKnown = (page: PageData): ExternalCheck => {
|
|
44
|
+
if (page.wellKnownAiCompliance) {
|
|
45
|
+
try {
|
|
46
|
+
const data = JSON.parse(page.wellKnownAiCompliance);
|
|
47
|
+
const hasRequired = data.aiProvider || data.aiSystem || data.complianceStatus;
|
|
48
|
+
return {
|
|
49
|
+
name: '.well-known/ai-compliance.json',
|
|
50
|
+
status: hasRequired ? 'PASS' : 'PARTIAL',
|
|
51
|
+
obligation: 'OBL-021',
|
|
52
|
+
article: 'Art. 50',
|
|
53
|
+
evidence: hasRequired
|
|
54
|
+
? 'Compliance metadata present with required fields'
|
|
55
|
+
: 'Compliance metadata found but missing required fields',
|
|
56
|
+
confidence: hasRequired ? 95 : 60,
|
|
57
|
+
};
|
|
58
|
+
} catch {
|
|
59
|
+
return {
|
|
60
|
+
name: '.well-known/ai-compliance.json',
|
|
61
|
+
status: 'PARTIAL',
|
|
62
|
+
obligation: 'OBL-021',
|
|
63
|
+
article: 'Art. 50',
|
|
64
|
+
evidence: 'File exists but contains invalid JSON',
|
|
65
|
+
confidence: 40,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
name: '.well-known/ai-compliance.json',
|
|
72
|
+
status: 'FAIL',
|
|
73
|
+
obligation: 'OBL-021',
|
|
74
|
+
article: 'Art. 50',
|
|
75
|
+
evidence: 'No .well-known/ai-compliance.json found (404)',
|
|
76
|
+
confidence: 90,
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export const checkMetaTags = (page: PageData): ExternalCheck => {
|
|
81
|
+
const aiMeta = page.metaTags.filter((t) =>
|
|
82
|
+
t.name.toLowerCase().includes('ai-') ||
|
|
83
|
+
t.name.toLowerCase().includes('ai_') ||
|
|
84
|
+
t.name.toLowerCase() === 'generator',
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
if (aiMeta.length > 0) {
|
|
88
|
+
const names = aiMeta.map((t) => t.name).join(', ');
|
|
89
|
+
return {
|
|
90
|
+
name: 'Meta Tags',
|
|
91
|
+
status: 'PASS',
|
|
92
|
+
obligation: 'OBL-015',
|
|
93
|
+
article: 'Art. 50(1)',
|
|
94
|
+
evidence: `AI-related meta tags found: ${names}`,
|
|
95
|
+
confidence: 90,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
name: 'Meta Tags',
|
|
101
|
+
status: 'FAIL',
|
|
102
|
+
obligation: 'OBL-015',
|
|
103
|
+
article: 'Art. 50(1)',
|
|
104
|
+
evidence: 'No AI-related meta tags found',
|
|
105
|
+
confidence: 75,
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const PRIVACY_AI_PATTERNS = [
|
|
110
|
+
/artificial intelligence/i,
|
|
111
|
+
/machine learning/i,
|
|
112
|
+
/automated decision/i,
|
|
113
|
+
/ai[- ]processing/i,
|
|
114
|
+
/algorithmic/i,
|
|
115
|
+
/ai[- ]system/i,
|
|
116
|
+
/language model/i,
|
|
117
|
+
];
|
|
118
|
+
|
|
119
|
+
export const checkPrivacyPolicy = (page: PageData): ExternalCheck => {
|
|
120
|
+
if (!page.privacyPolicyUrl) {
|
|
121
|
+
return {
|
|
122
|
+
name: 'Privacy Policy AI Section',
|
|
123
|
+
status: 'FAIL',
|
|
124
|
+
obligation: 'GDPR + AI Act',
|
|
125
|
+
article: 'Art. 50',
|
|
126
|
+
evidence: 'No privacy policy link found on page',
|
|
127
|
+
confidence: 70,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (!page.privacyPolicyText) {
|
|
132
|
+
return {
|
|
133
|
+
name: 'Privacy Policy AI Section',
|
|
134
|
+
status: 'PARTIAL',
|
|
135
|
+
obligation: 'GDPR + AI Act',
|
|
136
|
+
article: 'Art. 50',
|
|
137
|
+
evidence: `Privacy policy found at ${page.privacyPolicyUrl} but content not accessible`,
|
|
138
|
+
confidence: 40,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const hasAiSection = PRIVACY_AI_PATTERNS.some((p) => p.test(page.privacyPolicyText!));
|
|
143
|
+
|
|
144
|
+
return {
|
|
145
|
+
name: 'Privacy Policy AI Section',
|
|
146
|
+
status: hasAiSection ? 'PASS' : 'FAIL',
|
|
147
|
+
obligation: 'GDPR + AI Act',
|
|
148
|
+
article: 'Art. 50',
|
|
149
|
+
evidence: hasAiSection
|
|
150
|
+
? 'AI-specific section found in privacy policy'
|
|
151
|
+
: 'No AI-specific section in privacy policy',
|
|
152
|
+
confidence: hasAiSection ? 85 : 75,
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
export const checkApiHeaders = (page: PageData): ExternalCheck => {
|
|
157
|
+
const aiHeaders = Object.entries(page.headers).filter(([key]) => {
|
|
158
|
+
const lower = key.toLowerCase();
|
|
159
|
+
return lower.includes('x-ai-') || lower.includes('x-content-marking') || lower.includes('x-generated-by');
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
if (aiHeaders.length > 0) {
|
|
163
|
+
const names = aiHeaders.map(([k]) => k).join(', ');
|
|
164
|
+
return {
|
|
165
|
+
name: 'API Response Headers',
|
|
166
|
+
status: 'PASS',
|
|
167
|
+
obligation: 'OBL-021',
|
|
168
|
+
article: 'Art. 50',
|
|
169
|
+
evidence: `AI compliance headers found: ${names}`,
|
|
170
|
+
confidence: 95,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return {
|
|
175
|
+
name: 'API Response Headers',
|
|
176
|
+
status: 'FAIL',
|
|
177
|
+
obligation: 'OBL-021',
|
|
178
|
+
article: 'Art. 50',
|
|
179
|
+
evidence: 'No AI compliance headers (X-AI-Disclosure, X-Content-Marking) found',
|
|
180
|
+
confidence: 80,
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
export const checkChatbotDetection = (page: PageData): ExternalCheck => {
|
|
185
|
+
let confidence = 0;
|
|
186
|
+
const evidence: string[] = [];
|
|
187
|
+
|
|
188
|
+
if (page.hasWebSocket) {
|
|
189
|
+
confidence += 30;
|
|
190
|
+
evidence.push('WebSocket detected (likely real-time chat)');
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (page.chatInputs.length > 0) {
|
|
194
|
+
confidence += 40;
|
|
195
|
+
const placeholders = page.chatInputs.map((i) => i.placeholder).filter(Boolean);
|
|
196
|
+
evidence.push(`Chat input found${placeholders.length ? `: "${placeholders[0]}"` : ''}`);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const chatPatterns = /chat|message|ask|conversation|assistant/i;
|
|
200
|
+
if (chatPatterns.test(page.html)) {
|
|
201
|
+
confidence += 20;
|
|
202
|
+
evidence.push('Chat-related keywords found in DOM');
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (confidence >= 50) {
|
|
206
|
+
return {
|
|
207
|
+
name: 'Chatbot Detection',
|
|
208
|
+
status: 'PASS',
|
|
209
|
+
obligation: 'Detection',
|
|
210
|
+
article: 'Art. 50',
|
|
211
|
+
evidence: `AI chatbot detected (confidence ${confidence}%): ${evidence.join('; ')}`,
|
|
212
|
+
confidence,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (confidence > 0) {
|
|
217
|
+
return {
|
|
218
|
+
name: 'Chatbot Detection',
|
|
219
|
+
status: 'PARTIAL',
|
|
220
|
+
obligation: 'Detection',
|
|
221
|
+
article: 'Art. 50',
|
|
222
|
+
evidence: `Possible AI interface (confidence ${confidence}%): ${evidence.join('; ')}`,
|
|
223
|
+
confidence,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return {
|
|
228
|
+
name: 'Chatbot Detection',
|
|
229
|
+
status: 'N_A',
|
|
230
|
+
obligation: 'Detection',
|
|
231
|
+
article: 'Art. 50',
|
|
232
|
+
evidence: 'No AI chatbot interface detected',
|
|
233
|
+
confidence: 60,
|
|
234
|
+
};
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
export const checkImageMetadata = (page: PageData): ExternalCheck => {
|
|
238
|
+
if (page.images.length === 0) {
|
|
239
|
+
return {
|
|
240
|
+
name: 'Image Metadata (C2PA/IPTC)',
|
|
241
|
+
status: 'N_A',
|
|
242
|
+
obligation: 'OBL-016',
|
|
243
|
+
article: 'Art. 50(2)',
|
|
244
|
+
evidence: 'No images found on page',
|
|
245
|
+
confidence: 100,
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// In a real implementation, we'd download images and check C2PA.
|
|
250
|
+
// For L1 passive crawl, we check for alt-text AI indicators.
|
|
251
|
+
const aiImages = page.images.filter((img) =>
|
|
252
|
+
/ai[- ]generated|generated by|dall-?e|midjourney|stable diffusion/i.test(img.alt || img.src),
|
|
253
|
+
);
|
|
254
|
+
|
|
255
|
+
if (aiImages.length === 0) {
|
|
256
|
+
return {
|
|
257
|
+
name: 'Image Metadata (C2PA/IPTC)',
|
|
258
|
+
status: 'PARTIAL',
|
|
259
|
+
obligation: 'OBL-016',
|
|
260
|
+
article: 'Art. 50(2)',
|
|
261
|
+
evidence: `${page.images.length} images found, none indicate AI generation in metadata/alt`,
|
|
262
|
+
confidence: 50,
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
return {
|
|
267
|
+
name: 'Image Metadata (C2PA/IPTC)',
|
|
268
|
+
status: 'FAIL',
|
|
269
|
+
obligation: 'OBL-016',
|
|
270
|
+
article: 'Art. 50(2)',
|
|
271
|
+
evidence: `${aiImages.length} AI-generated images detected without C2PA provenance`,
|
|
272
|
+
confidence: 70,
|
|
273
|
+
};
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
const HUMAN_ESCALATION_PATTERNS = [
|
|
277
|
+
/talk to (?:a )?human/i,
|
|
278
|
+
/contact support/i,
|
|
279
|
+
/speak (?:to|with) (?:a )?(?:person|agent|representative)/i,
|
|
280
|
+
/human (?:agent|support|assistance)/i,
|
|
281
|
+
/live (?:chat|agent|support)/i,
|
|
282
|
+
/request (?:a )?callback/i,
|
|
283
|
+
/escalat/i,
|
|
284
|
+
];
|
|
285
|
+
|
|
286
|
+
export const checkHumanEscalation = (page: PageData): ExternalCheck => {
|
|
287
|
+
const htmlAndLinks = page.html + ' ' + page.links.map((l) => l.text).join(' ');
|
|
288
|
+
const matched = HUMAN_ESCALATION_PATTERNS.find((p) => p.test(htmlAndLinks));
|
|
289
|
+
|
|
290
|
+
if (matched) {
|
|
291
|
+
const match = htmlAndLinks.match(matched);
|
|
292
|
+
return {
|
|
293
|
+
name: 'Human Escalation',
|
|
294
|
+
status: 'PASS',
|
|
295
|
+
obligation: 'OBL-008',
|
|
296
|
+
article: 'Art. 14',
|
|
297
|
+
evidence: `Human escalation option found: "${match?.[0] ?? 'detected'}"`,
|
|
298
|
+
confidence: 85,
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
return {
|
|
303
|
+
name: 'Human Escalation',
|
|
304
|
+
status: 'FAIL',
|
|
305
|
+
obligation: 'OBL-008',
|
|
306
|
+
article: 'Art. 14',
|
|
307
|
+
evidence: 'No human escalation option (talk to human, contact support) found',
|
|
308
|
+
confidence: 70,
|
|
309
|
+
};
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
export const ALL_L1_CHECKS = [
|
|
313
|
+
checkAiDisclosure,
|
|
314
|
+
checkWellKnown,
|
|
315
|
+
checkMetaTags,
|
|
316
|
+
checkPrivacyPolicy,
|
|
317
|
+
checkApiHeaders,
|
|
318
|
+
checkChatbotDetection,
|
|
319
|
+
checkImageMetadata,
|
|
320
|
+
checkHumanEscalation,
|
|
321
|
+
] as const;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { deduplicateFindings, mergeFindings } from './dedup.js';
|
|
3
|
+
import type { Finding } from '../../../types/common.types.js';
|
|
4
|
+
|
|
5
|
+
const mkFinding = (overrides: Partial<Finding>): Finding => ({
|
|
6
|
+
checkId: 'test',
|
|
7
|
+
type: 'fail',
|
|
8
|
+
message: 'test finding',
|
|
9
|
+
severity: 'medium',
|
|
10
|
+
...overrides,
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
describe('deduplicateFindings', () => {
|
|
14
|
+
it('removes detect-secrets findings when NHI scanner found same file:line', () => {
|
|
15
|
+
const base = [
|
|
16
|
+
mkFinding({ checkId: 'l4-nhi-api-key', file: 'config.js', line: 5 }),
|
|
17
|
+
];
|
|
18
|
+
const external = [
|
|
19
|
+
mkFinding({ checkId: 'ext-detect-secrets-HexHighEntropy', file: 'config.js', line: 5 }),
|
|
20
|
+
mkFinding({ checkId: 'ext-detect-secrets-Base64', file: 'other.js', line: 10 }),
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
const result = deduplicateFindings(base, external);
|
|
24
|
+
expect(result).toHaveLength(1);
|
|
25
|
+
expect(result[0]!.file).toBe('other.js');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('keeps Semgrep findings even when L4 found same location', () => {
|
|
29
|
+
const base = [
|
|
30
|
+
mkFinding({ checkId: 'l4-bare-llm', type: 'info', severity: 'info', file: 'ai.ts', line: 42 }),
|
|
31
|
+
];
|
|
32
|
+
const external = [
|
|
33
|
+
mkFinding({ checkId: 'ext-semgrep-complior-bare-call', type: 'info', severity: 'info', file: 'ai.ts', line: 42 }),
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
const result = deduplicateFindings(base, external);
|
|
37
|
+
expect(result).toHaveLength(1);
|
|
38
|
+
expect(result[0]!.checkId).toBe('ext-semgrep-complior-bare-call');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('deduplicates same-tool findings at same file:line', () => {
|
|
42
|
+
const external = [
|
|
43
|
+
mkFinding({ checkId: 'ext-semgrep-rule1', file: 'a.ts', line: 1 }),
|
|
44
|
+
mkFinding({ checkId: 'ext-semgrep-rule1', file: 'a.ts', line: 1 }),
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
const result = deduplicateFindings([], external);
|
|
48
|
+
expect(result).toHaveLength(1);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe('mergeFindings', () => {
|
|
53
|
+
it('removes L4 findings superseded by Semgrep at same location', () => {
|
|
54
|
+
const base = [
|
|
55
|
+
mkFinding({ checkId: 'l4-bare-llm', type: 'info', severity: 'info', file: 'ai.ts', line: 42 }),
|
|
56
|
+
mkFinding({ checkId: 'l1-docs-missing', message: 'keep this' }),
|
|
57
|
+
];
|
|
58
|
+
const external = [
|
|
59
|
+
mkFinding({ checkId: 'ext-semgrep-complior-bare-call', type: 'info', severity: 'info', file: 'ai.ts', line: 42 }),
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
const result = mergeFindings(base, external);
|
|
63
|
+
expect(result).toHaveLength(2);
|
|
64
|
+
expect(result.some((f) => f.checkId === 'l4-bare-llm')).toBe(false);
|
|
65
|
+
expect(result.some((f) => f.checkId === 'ext-semgrep-complior-bare-call')).toBe(true);
|
|
66
|
+
expect(result.some((f) => f.checkId === 'l1-docs-missing')).toBe(true);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('keeps L4 findings without Semgrep equivalent', () => {
|
|
70
|
+
const base = [
|
|
71
|
+
mkFinding({ checkId: 'l4-bare-llm', type: 'info', severity: 'info', file: 'ai.ts', line: 42 }),
|
|
72
|
+
];
|
|
73
|
+
const external: Finding[] = [];
|
|
74
|
+
|
|
75
|
+
const result = mergeFindings(base, external);
|
|
76
|
+
expect(result).toHaveLength(1);
|
|
77
|
+
expect(result[0]!.checkId).toBe('l4-bare-llm');
|
|
78
|
+
});
|
|
79
|
+
});
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { Finding } from '../../../types/common.types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Deduplicate findings from external tools against existing L1-L4 findings.
|
|
5
|
+
*
|
|
6
|
+
* Rules:
|
|
7
|
+
* 1. detect-secrets vs NHI scanner: same file+line → keep NHI (richer metadata)
|
|
8
|
+
* 2. Semgrep vs L4 regex: same file+line+similar checkId → keep Semgrep (more precise)
|
|
9
|
+
* 3. Cross-tool: same file+line+similar message → keep first
|
|
10
|
+
*/
|
|
11
|
+
export const deduplicateFindings = (
|
|
12
|
+
baseFindings: readonly Finding[],
|
|
13
|
+
externalFindings: readonly Finding[],
|
|
14
|
+
): readonly Finding[] => {
|
|
15
|
+
// Build a set of base finding keys for O(1) lookup
|
|
16
|
+
const baseKeys = new Set<string>();
|
|
17
|
+
for (const f of baseFindings) {
|
|
18
|
+
if (f.file && f.line !== undefined) {
|
|
19
|
+
baseKeys.add(`${f.file}:${f.line}`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const result: Finding[] = [];
|
|
24
|
+
const seenExternal = new Set<string>();
|
|
25
|
+
|
|
26
|
+
for (const ext of externalFindings) {
|
|
27
|
+
const fileLineKey = ext.file && ext.line !== undefined
|
|
28
|
+
? `${ext.file}:${ext.line}`
|
|
29
|
+
: null;
|
|
30
|
+
|
|
31
|
+
// Rule 1: detect-secrets vs NHI — skip if NHI already found this file:line
|
|
32
|
+
if (ext.checkId.startsWith('ext-detect-secrets-') && fileLineKey) {
|
|
33
|
+
const nhiDuplicate = baseFindings.some((base) =>
|
|
34
|
+
base.checkId.startsWith('l4-nhi-')
|
|
35
|
+
&& base.file === ext.file
|
|
36
|
+
&& base.line === ext.line,
|
|
37
|
+
);
|
|
38
|
+
if (nhiDuplicate) continue;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Rule 2: Skip non-Semgrep, non-detect-secrets findings if base already has same file:line.
|
|
42
|
+
// Semgrep supersedes L4 in merge step. detect-secrets is handled by Rule 1 (NHI dedup).
|
|
43
|
+
if (fileLineKey && baseKeys.has(fileLineKey)) {
|
|
44
|
+
if (!ext.checkId.startsWith('ext-semgrep-') && !ext.checkId.startsWith('ext-detect-secrets-')) continue;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Rule 3: Cross-tool dedup — skip if same tool already reported same file:line
|
|
48
|
+
if (fileLineKey) {
|
|
49
|
+
const dedupKey = `${ext.checkId}:${fileLineKey}`;
|
|
50
|
+
if (seenExternal.has(dedupKey)) continue;
|
|
51
|
+
seenExternal.add(dedupKey);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
result.push(ext);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return result;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Merge base L1-L4 findings with deduplicated external findings.
|
|
62
|
+
* Removes L4 findings that have a more precise Semgrep equivalent,
|
|
63
|
+
* transferring fixDiff/codeContext from the superseded L4 finding.
|
|
64
|
+
*/
|
|
65
|
+
export const mergeFindings = (
|
|
66
|
+
baseFindings: readonly Finding[],
|
|
67
|
+
externalFindings: readonly Finding[],
|
|
68
|
+
): readonly Finding[] => {
|
|
69
|
+
// Build map of Semgrep file:line keys → index in externalFindings
|
|
70
|
+
const semgrepKeys = new Map<string, number>();
|
|
71
|
+
for (let i = 0; i < externalFindings.length; i++) {
|
|
72
|
+
const f = externalFindings[i]!;
|
|
73
|
+
if (f.checkId.startsWith('ext-semgrep-') && f.file && f.line !== undefined) {
|
|
74
|
+
semgrepKeys.set(`${f.file}:${f.line}`, i);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Transfer fixDiff from superseded L4 findings to their semgrep replacements
|
|
79
|
+
const enrichedExternal = [...externalFindings];
|
|
80
|
+
const filteredBase = baseFindings.filter((f) => {
|
|
81
|
+
if (!f.checkId.startsWith('l4-') || !f.file || f.line === undefined) return true;
|
|
82
|
+
const key = `${f.file}:${f.line}`;
|
|
83
|
+
const extIdx = semgrepKeys.get(key);
|
|
84
|
+
if (extIdx === undefined) return true; // Keep — no semgrep equivalent
|
|
85
|
+
// Transfer fixDiff and codeContext to the semgrep finding
|
|
86
|
+
const ext = enrichedExternal[extIdx]!;
|
|
87
|
+
if (f.fixDiff && !ext.fixDiff) {
|
|
88
|
+
enrichedExternal[extIdx] = { ...ext, fixDiff: f.fixDiff, codeContext: f.codeContext ?? ext.codeContext };
|
|
89
|
+
}
|
|
90
|
+
return false; // Remove — superseded by semgrep
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
return [...filteredBase, ...enrichedExternal];
|
|
94
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { parseDetectSecretsOutput } from './detect-secrets-runner.js';
|
|
3
|
+
|
|
4
|
+
describe('parseDetectSecretsOutput', () => {
|
|
5
|
+
it('parses valid detect-secrets JSON output', () => {
|
|
6
|
+
const output = JSON.stringify({
|
|
7
|
+
version: '1.4.0',
|
|
8
|
+
results: {
|
|
9
|
+
'/project/config.js': [
|
|
10
|
+
{
|
|
11
|
+
type: 'Hex High Entropy String',
|
|
12
|
+
line_number: 5,
|
|
13
|
+
hashed_secret: 'abc123',
|
|
14
|
+
is_verified: false,
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
'/project/src/api.ts': [
|
|
18
|
+
{
|
|
19
|
+
type: 'Base64 High Entropy String',
|
|
20
|
+
line_number: 12,
|
|
21
|
+
hashed_secret: 'def456',
|
|
22
|
+
is_verified: true,
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
type: 'Private Key',
|
|
26
|
+
line_number: 20,
|
|
27
|
+
hashed_secret: 'ghi789',
|
|
28
|
+
is_verified: false,
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const findings = parseDetectSecretsOutput(output, '/project');
|
|
35
|
+
expect(findings).toHaveLength(3);
|
|
36
|
+
|
|
37
|
+
expect(findings[0]!.ruleId).toBe('Hex High Entropy String');
|
|
38
|
+
expect(findings[0]!.file).toBe('config.js');
|
|
39
|
+
expect(findings[0]!.line).toBe(5);
|
|
40
|
+
expect(findings[0]!.message).not.toContain('verified');
|
|
41
|
+
|
|
42
|
+
expect(findings[1]!.ruleId).toBe('Base64 High Entropy String');
|
|
43
|
+
expect(findings[1]!.file).toBe('src/api.ts');
|
|
44
|
+
expect(findings[1]!.message).toContain('verified');
|
|
45
|
+
|
|
46
|
+
expect(findings[2]!.file).toBe('src/api.ts');
|
|
47
|
+
expect(findings[2]!.line).toBe(20);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('returns empty array for empty output', () => {
|
|
51
|
+
expect(parseDetectSecretsOutput('', '/project')).toEqual([]);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('returns empty array for empty results', () => {
|
|
55
|
+
const output = JSON.stringify({ version: '1.4.0', results: {} });
|
|
56
|
+
expect(parseDetectSecretsOutput(output, '/project')).toEqual([]);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { ExternalRunner, ExternalRunnerDeps, ExternalRunnerResult, RawExternalFinding } from './runner-port.js';
|
|
2
|
+
import { normalizeFilePath } from './path-utils.js';
|
|
3
|
+
|
|
4
|
+
interface DetectSecretsResult {
|
|
5
|
+
readonly results?: Record<string, readonly DetectSecretsFinding[]>;
|
|
6
|
+
readonly version?: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface DetectSecretsFinding {
|
|
10
|
+
readonly type: string;
|
|
11
|
+
readonly line_number: number;
|
|
12
|
+
readonly hashed_secret: string;
|
|
13
|
+
readonly is_verified?: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const createDetectSecretsRunner = (): ExternalRunner => Object.freeze({
|
|
17
|
+
name: 'detect-secrets',
|
|
18
|
+
run: async (deps: ExternalRunnerDeps): Promise<ExternalRunnerResult> => {
|
|
19
|
+
const startTime = Date.now();
|
|
20
|
+
const toolCmd = deps.toolPath ?? 'detect-secrets';
|
|
21
|
+
|
|
22
|
+
const result = await deps.runProcess(toolCmd, [
|
|
23
|
+
'scan',
|
|
24
|
+
'--all-files',
|
|
25
|
+
'--exclude-files', '\\.complior/|node_modules/|dist/|\\.git/',
|
|
26
|
+
], { timeout: 120_000, cwd: deps.projectPath });
|
|
27
|
+
|
|
28
|
+
const duration = Date.now() - startTime;
|
|
29
|
+
|
|
30
|
+
if (result.exitCode !== 0) {
|
|
31
|
+
return {
|
|
32
|
+
tool: 'detect-secrets',
|
|
33
|
+
version: '',
|
|
34
|
+
rawFindings: [],
|
|
35
|
+
duration,
|
|
36
|
+
exitCode: result.exitCode,
|
|
37
|
+
error: result.stderr.slice(0, 500),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const rawFindings = parseDetectSecretsOutput(result.stdout, deps.projectPath);
|
|
42
|
+
return {
|
|
43
|
+
tool: 'detect-secrets',
|
|
44
|
+
version: '',
|
|
45
|
+
rawFindings,
|
|
46
|
+
duration,
|
|
47
|
+
exitCode: result.exitCode,
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
export const parseDetectSecretsOutput = (stdout: string, projectPath: string): RawExternalFinding[] => {
|
|
53
|
+
if (!stdout.trim()) return [];
|
|
54
|
+
|
|
55
|
+
let parsed: DetectSecretsResult;
|
|
56
|
+
try {
|
|
57
|
+
parsed = JSON.parse(stdout) as DetectSecretsResult;
|
|
58
|
+
} catch {
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (!parsed.results) return [];
|
|
63
|
+
|
|
64
|
+
const findings: RawExternalFinding[] = [];
|
|
65
|
+
for (const [filePath, secrets] of Object.entries(parsed.results)) {
|
|
66
|
+
const relativePath = normalizeFilePath(filePath, projectPath);
|
|
67
|
+
|
|
68
|
+
for (const secret of secrets) {
|
|
69
|
+
findings.push({
|
|
70
|
+
ruleId: secret.type,
|
|
71
|
+
message: `${secret.type} detected${secret.is_verified ? ' (verified)' : ''}`,
|
|
72
|
+
severity: 'high',
|
|
73
|
+
file: relativePath,
|
|
74
|
+
line: secret.line_number,
|
|
75
|
+
category: 'secrets',
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return findings;
|
|
81
|
+
};
|