websec-validator 0.14.0__tar.gz → 0.15.0__tar.gz
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.
- {websec_validator-0.14.0/src/websec_validator.egg-info → websec_validator-0.15.0}/PKG-INFO +109 -7
- {websec_validator-0.14.0 → websec_validator-0.15.0}/README.md +108 -6
- {websec_validator-0.14.0 → websec_validator-0.15.0}/pyproject.toml +4 -1
- websec_validator-0.15.0/src/websec_validator/agenthook.py +146 -0
- websec_validator-0.15.0/src/websec_validator/attest.py +279 -0
- websec_validator-0.15.0/src/websec_validator/attribution.py +214 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/cli.py +404 -26
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/extractors/__init__.py +14 -3
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/extractors/agent_config.py +32 -11
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/extractors/base.py +48 -3
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/extractors/dependencies.py +99 -2
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/extractors/stack.py +10 -2
- websec_validator-0.15.0/src/websec_validator/feedback.py +168 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/findings.py +5 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/formats.py +3 -0
- websec_validator-0.15.0/src/websec_validator/gate.py +175 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/hooks.py +158 -1
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/recon.py +3 -2
- websec_validator-0.15.0/src/websec_validator/registry.py +254 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/scanners.py +86 -4
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/schemas/ledger.schema.json +34 -1
- {websec_validator-0.14.0 → websec_validator-0.15.0/src/websec_validator.egg-info}/PKG-INFO +109 -7
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator.egg-info/SOURCES.txt +16 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator.egg-info/entry_points.txt +1 -0
- websec_validator-0.15.0/tests/test_agent_hook.py +192 -0
- websec_validator-0.15.0/tests/test_agent_hosts.py +119 -0
- websec_validator-0.15.0/tests/test_analysis_scope.py +166 -0
- websec_validator-0.15.0/tests/test_attest.py +156 -0
- websec_validator-0.15.0/tests/test_attribution.py +146 -0
- websec_validator-0.15.0/tests/test_feedback.py +175 -0
- websec_validator-0.15.0/tests/test_gate_and_bypass_record.py +193 -0
- websec_validator-0.15.0/tests/test_gate_command.py +150 -0
- websec_validator-0.15.0/tests/test_gitleaks_worktree.py +193 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_read_boundary.py +22 -1
- websec_validator-0.15.0/tests/test_registry_existence.py +197 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/LICENSE +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/setup.cfg +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/__init__.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/baseline.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/briefing.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/calibration.json +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/calibration.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/constitution.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/corpus.json +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/coverage.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/dast_ingest.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/dast_predict.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/diffscope.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/dynamic.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/enrichment.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/extractors/auth.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/extractors/authz.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/extractors/authz_dataflow.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/extractors/client_exposure.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/extractors/client_integrity.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/extractors/crypto_usage.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/extractors/django_urls.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/extractors/graphql.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/extractors/iac_ci.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/extractors/integrations.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/extractors/llm_security.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/extractors/pii_exposure.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/extractors/policy_consistency.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/extractors/profiles.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/extractors/routes.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/extractors/schemas.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/extractors/sql_flow.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/extractors/surface.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/extractors/syntax.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/extractors/tenant.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/extractors/transport_security.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/extractors/upload_security.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/extractors/webext.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/fixprompt.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/fpfilter.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/graph_enrich.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/install.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/intel.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/inventory.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/mcp_server.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/openapi.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/probes.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/proof.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/repairs.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/report.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/research/control-scope-cases.json +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/research/example.json +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/research/profile-cases.json +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/research.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/rules/error-stack-disclosure.yml +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/rules/insecure-default-secret.yml +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/sarif_ingest.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/schemas/coverage.schema.json +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/schemas/facts.schema.json +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/templates/probes/_lib.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/templates/probes/appsync-cswsh.sh +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/templates/probes/appsync-introspection.sh +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/templates/probes/appsync-subscription-bola.sh +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/templates/probes/bola-cross-tenant.sh +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/templates/probes/bola-write-verbs.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/templates/probes/client-integrity-checklist.sh +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/templates/probes/compare-roles.sh +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/templates/probes/dlp-bypass-offline.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/templates/probes/entitlement-abuse.sh +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/templates/probes/error-disclosure-probe.sh +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/templates/probes/forged-token.sh +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/templates/probes/hs256-brute-force.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/templates/probes/jwt-attacks.sh +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/templates/probes/mass-assignment.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/templates/probes/password-reuse.sh +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/templates/probes/pii-output-diff.sh +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/templates/probes/race-conditions.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/templates/probes/rate-limit-burst.sh +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/templates/probes/s3-assess.sh +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/templates/probes/ssrf-probes.sh +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/templates/probes/unauth-baseline.sh +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/templates/probes/upload-matrix.sh +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/templates/probes/webhook-forgery.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/templates/reports/FINDINGS-SUMMARY.md.template +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/templates/reports/access-control-matrix.md.template +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/templates/reports/findings-triage.md.template +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/templates/reports/pentest-handover-brief.md.template +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/templates/reports/per-tool-FINDINGS.md.template +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator/testplan.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator.egg-info/dependency_links.txt +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/src/websec_validator.egg-info/top_level.txt +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_action_contracts.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_adoption_contracts.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_agent_launch_specs.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_assurance_regressions.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_auth_control_scope.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_constitution.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_control_scope_research.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_coverage.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_crypto_comparisons.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_dast_ingest.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_dast_predict.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_detector_precision.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_diffscope.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_django_routes.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_enrichment.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_entitlement_webext.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_evidence_verdicts.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_extension_controls.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_fixprompt_fpfilter.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_formats.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_graph_enrich.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_hardening.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_hooks.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_hooks_contracts.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_install.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_install_contracts.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_intel.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_inventory.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_lifecycle.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_mcp.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_mcp_security.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_openapi.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_output_boundaries.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_pentest_regressions.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_profiles.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_proof_revisions.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_public_precision.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_read_performance.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_recon.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_remaining_control_scope.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_research.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_research_cli.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_sarif_ingest.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_sarif_workbench.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_scanner_contracts.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_source_budget.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_sql_flow.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_stack_metadata.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_testplan.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_transport_pii_scope.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_transport_stack_scope.py +0 -0
- {websec_validator-0.14.0 → websec_validator-0.15.0}/tests/test_workbench_cli.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: websec-validator
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.15.0
|
|
4
4
|
Summary: Defensive, local-first security recon that briefs your AI coding agent on your own codebase — read-only by default (code in, artifacts out): facts + tailored probe scripts, no LLM, no server, no running app.
|
|
5
5
|
Author: Ricardo Accioly
|
|
6
6
|
License: MIT
|
|
@@ -351,6 +351,100 @@ required tools when `scan: true`. Outputs expose `run-directory`, `sarif-file` a
|
|
|
351
351
|
Keep the reviewed action checkout separate from untrusted target source. Pin a reviewed 0.14.0-or-later commit when adopting these changes; the historical v0.13.0 tag
|
|
352
352
|
does not include them.
|
|
353
353
|
|
|
354
|
+
**Audit evidence — `websec attest`.** Projects an existing run into a per-control evidence table.
|
|
355
|
+
It computes nothing and asserts nothing.
|
|
356
|
+
|
|
357
|
+
```bash
|
|
358
|
+
websec attest # latest run, human-readable
|
|
359
|
+
websec attest --format json
|
|
360
|
+
websec attest --format in-toto # UNSIGNED Statement — sign it with your own key
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
**Gaps are listed before evidence**, in the data and in the output, because a table that leads with
|
|
364
|
+
coverage invites absence to read as satisfaction. On a typical run, 5 of 12 rows have no websec
|
|
365
|
+
evidence at all — most of these controls are organisational and the artifact says so.
|
|
366
|
+
|
|
367
|
+
It renders no verdict, score, percentage or badge, and the word "compliant" does not appear in any
|
|
368
|
+
output format (there is a test). Compliance is an attribute of an assessed *entity*, determined by a
|
|
369
|
+
qualified assessor and evidenced by their report — PCI SSC FAQ 1258: *"no single product can provide
|
|
370
|
+
PCI DSS compliance"*. Three things are declared non-goals in the artifact itself: approver
|
|
371
|
+
independence (it lives in the forge's approval record), rollback, and PCI 6.4.2 runtime protection.
|
|
372
|
+
The output also states that the local gate is bypassable and that its bypass record is not
|
|
373
|
+
exhaustive.
|
|
374
|
+
|
|
375
|
+
Citations are exact, because the obvious ones are wrong. EU DORA change management is **Commission
|
|
376
|
+
Delegated Regulation (EU) 2024/1774 Art. 17** (the RTS under DORA Art. 9(4)(e)); DORA Art. 17 itself
|
|
377
|
+
is incident management. There is **no SOX article** for ITGC — the domains come from SEC Release
|
|
378
|
+
33-8810 §II.A.2.d. PCI DSS **6.2.3 permits automated review**, and **6.2.3.1 is conditional** on
|
|
379
|
+
choosing manual review, so websec is deliberately not offered against it.
|
|
380
|
+
|
|
381
|
+
The in-toto Statement is unsigned by design: a websec-signed attestation would only attest that
|
|
382
|
+
websec ran. Sign it with your own key and identity and it becomes verifiable.
|
|
383
|
+
|
|
384
|
+
**Dependency existence — `websec run --network` (opt-in).** Offline checks cannot tell whether a
|
|
385
|
+
declared package actually exists, which is the AI-hallucinated-dependency surface.
|
|
386
|
+
|
|
387
|
+
```bash
|
|
388
|
+
websec run . --network-dry-run # print the exact names that WOULD be sent; sends nothing
|
|
389
|
+
websec run . --network # HEAD registry.npmjs.org / pypi.org; ~2.8s for 52 deps
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
Only bare package **names** are sent — never versions, paths or repository identity. Suppression is
|
|
393
|
+
applied **offline, before any request**: names this repo publishes (via the real workspace graph),
|
|
394
|
+
scopes bound to a private registry in `.npmrc`/`.yarnrc.yml`, and pip `index-url` overrides. A
|
|
395
|
+
private name that reaches a public registry cannot be un-sent, and a 404 on an internal name tells
|
|
396
|
+
an attacker which name to squat.
|
|
397
|
+
|
|
398
|
+
A 404 is split by offline lockfile evidence: `resolved` + `integrity` means the package once
|
|
399
|
+
existed, so it is `dependency-unpublished-or-removed` (a package pulled for malware looks exactly
|
|
400
|
+
like this) rather than `dependency-nonexistent`. Findings are MEDIUM/LOW-confidence and do **not**
|
|
401
|
+
fail `--fail-on` unless you also pass `--fail-on-network` — the UNKNOWN rate is outside your
|
|
402
|
+
control, so gating on it would make registry uptime a dependency of shipping. UNKNOWN is recorded
|
|
403
|
+
as a coverage gap, never as clean.
|
|
404
|
+
|
|
405
|
+
**A 200 is not evidence of safety.** A squatter who has already registered the hallucinated name
|
|
406
|
+
also returns 200 — that is the successful attack, not the clean case.
|
|
407
|
+
|
|
408
|
+
**Agent-loop gate — `websec gate` and `websec hooks install --agent`.** Scanning at the merge
|
|
409
|
+
request makes a finding a backlog item; scanning on the edit that caused it makes it a retry the
|
|
410
|
+
agent fixes immediately.
|
|
411
|
+
|
|
412
|
+
```bash
|
|
413
|
+
websec gate # the files you just changed, ~0.3s, exit 1 if blocking
|
|
414
|
+
websec gate --fail-on high # default is medium (see below)
|
|
415
|
+
websec hooks install --agent # PostToolUse hook: runs the gate on every file the agent writes
|
|
416
|
+
websec hooks status --agent
|
|
417
|
+
websec hooks uninstall --agent
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
`gate` scopes the **analysis**, not just the report: `--only` narrows what is read and matched
|
|
421
|
+
(~13x faster than a full pass), while the tree is still walked in full so stack detection, ignore
|
|
422
|
+
policy and fixture classification are unchanged. Its default scope is the **working tree** —
|
|
423
|
+
tracked modifications plus untracked files — because agent edits are uncommitted and a three-dot
|
|
424
|
+
`base...HEAD` diff would see nothing. It writes no artifacts, publishes no run directory and never
|
|
425
|
+
advances an accepted baseline.
|
|
426
|
+
|
|
427
|
+
The default threshold is **medium, not high**: command injection and SSRF on agent-written code are
|
|
428
|
+
frequently rated MEDIUM, so a HIGH default would miss the main case. `--min-confidence` filters
|
|
429
|
+
low-confidence leads for teams that measure them as noisy; there is no confidence floor by default,
|
|
430
|
+
because in the loop a false block costs one turn while a miss ships.
|
|
431
|
+
|
|
432
|
+
Three deliberate properties of the hook:
|
|
433
|
+
|
|
434
|
+
- It **fails open, loudly**. If the gate cannot run, the hook exits 0 and says on stderr that the
|
|
435
|
+
edit was *not* security-checked. A check that blocks every edit when broken gets uninstalled, and
|
|
436
|
+
then there is no check at all. A pass means "nothing blocking was found", never "this was verified".
|
|
437
|
+
- It does **not** honour `WEBSEC_SKIP_HOOK`, unlike the git guardrail below. The agent can set an
|
|
438
|
+
environment variable in a Bash call, so an env escape hatch here would be one the agent operates.
|
|
439
|
+
- It is **developer ergonomics, not a compliance control.** Settings files are editable by the user
|
|
440
|
+
and, in a repository the agent can write to, by the agent. Only managed policy settings deployed
|
|
441
|
+
through device management are genuinely unbypassable. This hook catches mistakes early; it cannot
|
|
442
|
+
evidence that it ran for every change, and should not be presented as though it could. For
|
|
443
|
+
enforcement, run `websec run --fail-on …` as a required status check.
|
|
444
|
+
|
|
445
|
+
A scoped pass is a fast retry signal, not a review: it does not consult cross-file evidence outside
|
|
446
|
+
the scope, and a clean result does not mean the repository is clean. Keep running the full pass.
|
|
447
|
+
|
|
354
448
|
**Local guardrail — `websec hooks`.** Advisory and gating runs have separate responsibilities:
|
|
355
449
|
|
|
356
450
|
```bash
|
|
@@ -422,6 +516,8 @@ read policy; an unrelated working directory no longer contributes implicit suppr
|
|
|
422
516
|
|
|
423
517
|
```bash
|
|
424
518
|
websec capabilities # offline profile/check/limitation matrix
|
|
519
|
+
websec feedback --fingerprint <fp> --verdict false-positive \
|
|
520
|
+
--reason "behind an nginx auth_request" # report a wrong detector; metadata-only, sends nothing
|
|
425
521
|
websec intel status # offline freshness and provenance
|
|
426
522
|
websec intel refresh # explicit public FIRST/CISA downloads
|
|
427
523
|
websec intel reassess --ledger prior-ledger.json --out reassessment.json
|
|
@@ -527,7 +623,7 @@ add the matching dated changelog and migration guidance, and validate the combin
|
|
|
527
623
|
In the 0.x series, feature additions or incompatible contracts increment the minor version.
|
|
528
624
|
|
|
529
625
|
After reviewing current main and overlapping PRs, merge the approved release PR only after its
|
|
530
|
-
required CI checks pass. The resulting main commit subject must be `release: v0.
|
|
626
|
+
required CI checks pass. The resulting main commit subject must be `release: v0.15.0` for this
|
|
531
627
|
release. [release-tag.yml](.github/workflows/release-tag.yml) validates that subject against the
|
|
532
628
|
package version, creates the matching tag/GitHub Release, and explicitly dispatches
|
|
533
629
|
[publish.yml](.github/workflows/publish.yml) at that tag. A version edit alone does not publish.
|
|
@@ -543,12 +639,18 @@ omit an independent version field. Check both sources when diagnosing stale inst
|
|
|
543
639
|
|
|
544
640
|
## Status / roadmap
|
|
545
641
|
|
|
546
|
-
Version 0.
|
|
642
|
+
Version 0.15.0 provides 22 recon extractors, eleven optional scanner entries, nine named profiles,
|
|
547
643
|
SARIF import/export, bounded source/query analysis, explicit coverage and lifecycle evidence,
|
|
548
|
-
intelligence/research commands, and opt-in agent/hook/CI adoption.
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
644
|
+
intelligence/research commands, and opt-in agent/hook/CI adoption. It adds an in-loop security gate
|
|
645
|
+
(`websec gate` and a `PostToolUse` hook), analysis scoping with `--only`, an opt-in dependency
|
|
646
|
+
existence check (`--network`), run attribution with graded assurance, recorded gate verdicts and
|
|
647
|
+
hook bypasses, and an audit-evidence projection (`websec attest`). These are scoped review tools;
|
|
648
|
+
manual profiles, unknown routes, dynamic behavior and unsupported syntax remain limitations. The
|
|
649
|
+
in-loop gate is developer ergonomics, not a control, and `attest` reports evidence without
|
|
650
|
+
rendering a compliance verdict.
|
|
651
|
+
|
|
652
|
+
The [0.14.0 migration guide](docs/MIGRATING-0.14.0.md) explains schema 2.0 and gate/artifact
|
|
653
|
+
changes. 0.15.0 is additive and needs no migration.
|
|
552
654
|
The [remaining-work specification](specs/001-continuous-security-improvement/spec.md) consolidates
|
|
553
655
|
unresolved gaps and acceptance tests so overlapping old-base PRs do not become competing roadmaps.
|
|
554
656
|
Existing runtime probes are opt-in; their earlier isolated results are not current deployment proofs.
|
|
@@ -322,6 +322,100 @@ required tools when `scan: true`. Outputs expose `run-directory`, `sarif-file` a
|
|
|
322
322
|
Keep the reviewed action checkout separate from untrusted target source. Pin a reviewed 0.14.0-or-later commit when adopting these changes; the historical v0.13.0 tag
|
|
323
323
|
does not include them.
|
|
324
324
|
|
|
325
|
+
**Audit evidence — `websec attest`.** Projects an existing run into a per-control evidence table.
|
|
326
|
+
It computes nothing and asserts nothing.
|
|
327
|
+
|
|
328
|
+
```bash
|
|
329
|
+
websec attest # latest run, human-readable
|
|
330
|
+
websec attest --format json
|
|
331
|
+
websec attest --format in-toto # UNSIGNED Statement — sign it with your own key
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
**Gaps are listed before evidence**, in the data and in the output, because a table that leads with
|
|
335
|
+
coverage invites absence to read as satisfaction. On a typical run, 5 of 12 rows have no websec
|
|
336
|
+
evidence at all — most of these controls are organisational and the artifact says so.
|
|
337
|
+
|
|
338
|
+
It renders no verdict, score, percentage or badge, and the word "compliant" does not appear in any
|
|
339
|
+
output format (there is a test). Compliance is an attribute of an assessed *entity*, determined by a
|
|
340
|
+
qualified assessor and evidenced by their report — PCI SSC FAQ 1258: *"no single product can provide
|
|
341
|
+
PCI DSS compliance"*. Three things are declared non-goals in the artifact itself: approver
|
|
342
|
+
independence (it lives in the forge's approval record), rollback, and PCI 6.4.2 runtime protection.
|
|
343
|
+
The output also states that the local gate is bypassable and that its bypass record is not
|
|
344
|
+
exhaustive.
|
|
345
|
+
|
|
346
|
+
Citations are exact, because the obvious ones are wrong. EU DORA change management is **Commission
|
|
347
|
+
Delegated Regulation (EU) 2024/1774 Art. 17** (the RTS under DORA Art. 9(4)(e)); DORA Art. 17 itself
|
|
348
|
+
is incident management. There is **no SOX article** for ITGC — the domains come from SEC Release
|
|
349
|
+
33-8810 §II.A.2.d. PCI DSS **6.2.3 permits automated review**, and **6.2.3.1 is conditional** on
|
|
350
|
+
choosing manual review, so websec is deliberately not offered against it.
|
|
351
|
+
|
|
352
|
+
The in-toto Statement is unsigned by design: a websec-signed attestation would only attest that
|
|
353
|
+
websec ran. Sign it with your own key and identity and it becomes verifiable.
|
|
354
|
+
|
|
355
|
+
**Dependency existence — `websec run --network` (opt-in).** Offline checks cannot tell whether a
|
|
356
|
+
declared package actually exists, which is the AI-hallucinated-dependency surface.
|
|
357
|
+
|
|
358
|
+
```bash
|
|
359
|
+
websec run . --network-dry-run # print the exact names that WOULD be sent; sends nothing
|
|
360
|
+
websec run . --network # HEAD registry.npmjs.org / pypi.org; ~2.8s for 52 deps
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
Only bare package **names** are sent — never versions, paths or repository identity. Suppression is
|
|
364
|
+
applied **offline, before any request**: names this repo publishes (via the real workspace graph),
|
|
365
|
+
scopes bound to a private registry in `.npmrc`/`.yarnrc.yml`, and pip `index-url` overrides. A
|
|
366
|
+
private name that reaches a public registry cannot be un-sent, and a 404 on an internal name tells
|
|
367
|
+
an attacker which name to squat.
|
|
368
|
+
|
|
369
|
+
A 404 is split by offline lockfile evidence: `resolved` + `integrity` means the package once
|
|
370
|
+
existed, so it is `dependency-unpublished-or-removed` (a package pulled for malware looks exactly
|
|
371
|
+
like this) rather than `dependency-nonexistent`. Findings are MEDIUM/LOW-confidence and do **not**
|
|
372
|
+
fail `--fail-on` unless you also pass `--fail-on-network` — the UNKNOWN rate is outside your
|
|
373
|
+
control, so gating on it would make registry uptime a dependency of shipping. UNKNOWN is recorded
|
|
374
|
+
as a coverage gap, never as clean.
|
|
375
|
+
|
|
376
|
+
**A 200 is not evidence of safety.** A squatter who has already registered the hallucinated name
|
|
377
|
+
also returns 200 — that is the successful attack, not the clean case.
|
|
378
|
+
|
|
379
|
+
**Agent-loop gate — `websec gate` and `websec hooks install --agent`.** Scanning at the merge
|
|
380
|
+
request makes a finding a backlog item; scanning on the edit that caused it makes it a retry the
|
|
381
|
+
agent fixes immediately.
|
|
382
|
+
|
|
383
|
+
```bash
|
|
384
|
+
websec gate # the files you just changed, ~0.3s, exit 1 if blocking
|
|
385
|
+
websec gate --fail-on high # default is medium (see below)
|
|
386
|
+
websec hooks install --agent # PostToolUse hook: runs the gate on every file the agent writes
|
|
387
|
+
websec hooks status --agent
|
|
388
|
+
websec hooks uninstall --agent
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
`gate` scopes the **analysis**, not just the report: `--only` narrows what is read and matched
|
|
392
|
+
(~13x faster than a full pass), while the tree is still walked in full so stack detection, ignore
|
|
393
|
+
policy and fixture classification are unchanged. Its default scope is the **working tree** —
|
|
394
|
+
tracked modifications plus untracked files — because agent edits are uncommitted and a three-dot
|
|
395
|
+
`base...HEAD` diff would see nothing. It writes no artifacts, publishes no run directory and never
|
|
396
|
+
advances an accepted baseline.
|
|
397
|
+
|
|
398
|
+
The default threshold is **medium, not high**: command injection and SSRF on agent-written code are
|
|
399
|
+
frequently rated MEDIUM, so a HIGH default would miss the main case. `--min-confidence` filters
|
|
400
|
+
low-confidence leads for teams that measure them as noisy; there is no confidence floor by default,
|
|
401
|
+
because in the loop a false block costs one turn while a miss ships.
|
|
402
|
+
|
|
403
|
+
Three deliberate properties of the hook:
|
|
404
|
+
|
|
405
|
+
- It **fails open, loudly**. If the gate cannot run, the hook exits 0 and says on stderr that the
|
|
406
|
+
edit was *not* security-checked. A check that blocks every edit when broken gets uninstalled, and
|
|
407
|
+
then there is no check at all. A pass means "nothing blocking was found", never "this was verified".
|
|
408
|
+
- It does **not** honour `WEBSEC_SKIP_HOOK`, unlike the git guardrail below. The agent can set an
|
|
409
|
+
environment variable in a Bash call, so an env escape hatch here would be one the agent operates.
|
|
410
|
+
- It is **developer ergonomics, not a compliance control.** Settings files are editable by the user
|
|
411
|
+
and, in a repository the agent can write to, by the agent. Only managed policy settings deployed
|
|
412
|
+
through device management are genuinely unbypassable. This hook catches mistakes early; it cannot
|
|
413
|
+
evidence that it ran for every change, and should not be presented as though it could. For
|
|
414
|
+
enforcement, run `websec run --fail-on …` as a required status check.
|
|
415
|
+
|
|
416
|
+
A scoped pass is a fast retry signal, not a review: it does not consult cross-file evidence outside
|
|
417
|
+
the scope, and a clean result does not mean the repository is clean. Keep running the full pass.
|
|
418
|
+
|
|
325
419
|
**Local guardrail — `websec hooks`.** Advisory and gating runs have separate responsibilities:
|
|
326
420
|
|
|
327
421
|
```bash
|
|
@@ -393,6 +487,8 @@ read policy; an unrelated working directory no longer contributes implicit suppr
|
|
|
393
487
|
|
|
394
488
|
```bash
|
|
395
489
|
websec capabilities # offline profile/check/limitation matrix
|
|
490
|
+
websec feedback --fingerprint <fp> --verdict false-positive \
|
|
491
|
+
--reason "behind an nginx auth_request" # report a wrong detector; metadata-only, sends nothing
|
|
396
492
|
websec intel status # offline freshness and provenance
|
|
397
493
|
websec intel refresh # explicit public FIRST/CISA downloads
|
|
398
494
|
websec intel reassess --ledger prior-ledger.json --out reassessment.json
|
|
@@ -498,7 +594,7 @@ add the matching dated changelog and migration guidance, and validate the combin
|
|
|
498
594
|
In the 0.x series, feature additions or incompatible contracts increment the minor version.
|
|
499
595
|
|
|
500
596
|
After reviewing current main and overlapping PRs, merge the approved release PR only after its
|
|
501
|
-
required CI checks pass. The resulting main commit subject must be `release: v0.
|
|
597
|
+
required CI checks pass. The resulting main commit subject must be `release: v0.15.0` for this
|
|
502
598
|
release. [release-tag.yml](.github/workflows/release-tag.yml) validates that subject against the
|
|
503
599
|
package version, creates the matching tag/GitHub Release, and explicitly dispatches
|
|
504
600
|
[publish.yml](.github/workflows/publish.yml) at that tag. A version edit alone does not publish.
|
|
@@ -514,12 +610,18 @@ omit an independent version field. Check both sources when diagnosing stale inst
|
|
|
514
610
|
|
|
515
611
|
## Status / roadmap
|
|
516
612
|
|
|
517
|
-
Version 0.
|
|
613
|
+
Version 0.15.0 provides 22 recon extractors, eleven optional scanner entries, nine named profiles,
|
|
518
614
|
SARIF import/export, bounded source/query analysis, explicit coverage and lifecycle evidence,
|
|
519
|
-
intelligence/research commands, and opt-in agent/hook/CI adoption.
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
615
|
+
intelligence/research commands, and opt-in agent/hook/CI adoption. It adds an in-loop security gate
|
|
616
|
+
(`websec gate` and a `PostToolUse` hook), analysis scoping with `--only`, an opt-in dependency
|
|
617
|
+
existence check (`--network`), run attribution with graded assurance, recorded gate verdicts and
|
|
618
|
+
hook bypasses, and an audit-evidence projection (`websec attest`). These are scoped review tools;
|
|
619
|
+
manual profiles, unknown routes, dynamic behavior and unsupported syntax remain limitations. The
|
|
620
|
+
in-loop gate is developer ergonomics, not a control, and `attest` reports evidence without
|
|
621
|
+
rendering a compliance verdict.
|
|
622
|
+
|
|
623
|
+
The [0.14.0 migration guide](docs/MIGRATING-0.14.0.md) explains schema 2.0 and gate/artifact
|
|
624
|
+
changes. 0.15.0 is additive and needs no migration.
|
|
523
625
|
The [remaining-work specification](specs/001-continuous-security-improvement/spec.md) consolidates
|
|
524
626
|
unresolved gaps and acceptance tests so overlapping old-base PRs do not become competing roadmaps.
|
|
525
627
|
Existing runtime probes are opt-in; their earlier isolated results are not current deployment proofs.
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "websec-validator"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.15.0"
|
|
8
8
|
description = "Defensive, local-first security recon that briefs your AI coding agent on your own codebase — read-only by default (code in, artifacts out): facts + tailored probe scripts, no LLM, no server, no running app."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.11"
|
|
@@ -38,6 +38,9 @@ Issues = "https://github.com/raccioly/websec-validator/issues"
|
|
|
38
38
|
|
|
39
39
|
[project.scripts]
|
|
40
40
|
websec = "websec_validator.cli:main"
|
|
41
|
+
# PostToolUse agent-loop hook. A console script rather than `python -m …` so the plugin's
|
|
42
|
+
# hooks.json does not have to guess an interpreter path.
|
|
43
|
+
websec-agent-hook = "websec_validator.agenthook:main"
|
|
41
44
|
websec-mcp = "websec_validator.mcp_server:serve"
|
|
42
45
|
|
|
43
46
|
[tool.setuptools]
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"""PostToolUse hook — run the security gate INSIDE the agent loop, on the file just written.
|
|
2
|
+
|
|
3
|
+
This is the piece the whole `gate` work exists for. Scanning at the merge request makes a finding a
|
|
4
|
+
backlog item; scanning on the edit that caused it makes it a retry the agent can act on immediately.
|
|
5
|
+
|
|
6
|
+
WHY PostToolUse AND NOT PreToolUse. PreToolUse is the only event that can cancel a write — but at
|
|
7
|
+
PreToolUse the file does not exist yet, so there is nothing to scan. Scanning the proposed content
|
|
8
|
+
would mean re-implementing every edit shape (Edit, MultiEdit, Write, notebook cells) and scanning a
|
|
9
|
+
tree state that never existed on disk. PostToolUse runs after the write, sees the real file in its
|
|
10
|
+
real place, and can still stop the loop before the next model call.
|
|
11
|
+
|
|
12
|
+
HOW IT BLOCKS. Exit code 2. The harness shows the hook's stderr to the model, which is exactly the
|
|
13
|
+
retry signal we want: the model reads the finding and its remediation and fixes it on the next turn.
|
|
14
|
+
Exit 0 means pass and stays silent.
|
|
15
|
+
|
|
16
|
+
FAIL OPEN, LOUDLY. If the gate itself errors — bad install, missing interpreter, unreadable repo —
|
|
17
|
+
the hook exits 0 and writes a warning to stderr. A security check that blocks every edit when it is
|
|
18
|
+
broken gets uninstalled within the hour, and then there is no check at all. This is a deliberate
|
|
19
|
+
trade and it is stated in the docs rather than hidden: a PASS from this hook means "nothing blocking
|
|
20
|
+
was found", never "this code was verified".
|
|
21
|
+
|
|
22
|
+
NO BYPASS ENV. Unlike the git guardrail, this hook deliberately does NOT honour WEBSEC_SKIP_HOOK.
|
|
23
|
+
The agent can set an environment variable in a Bash call, so an env-var escape hatch here would be
|
|
24
|
+
an escape hatch the agent can operate on its own.
|
|
25
|
+
|
|
26
|
+
NOT A COMPLIANCE CONTROL. Hooks configured in user or project settings are editable — by the user
|
|
27
|
+
and, in a repository the agent can write to, by the agent. They are genuinely unbypassable only via
|
|
28
|
+
managed policy settings deployed through device management. This hook is developer ergonomics: it
|
|
29
|
+
catches mistakes early. It cannot evidence that it ran for every change, and must never be
|
|
30
|
+
presented as though it could.
|
|
31
|
+
"""
|
|
32
|
+
from __future__ import annotations
|
|
33
|
+
|
|
34
|
+
import json
|
|
35
|
+
import os
|
|
36
|
+
import subprocess
|
|
37
|
+
import sys
|
|
38
|
+
from pathlib import Path
|
|
39
|
+
|
|
40
|
+
# The gate measures ~0.3s on a one-file change. The hook runs it IN-PROCESS, so the outer bound is
|
|
41
|
+
# the harness's own hook timeout (30s in the shipped configuration) rather than one we impose here.
|
|
42
|
+
GIT_TIMEOUT_SECONDS = 10
|
|
43
|
+
_MAX_STDIN = 1_000_000
|
|
44
|
+
|
|
45
|
+
# Only suffixes a detector actually reads. Anything else exits immediately — the common case is a
|
|
46
|
+
# markdown or JSON edit, and the hook must cost nothing there.
|
|
47
|
+
ANALYZABLE = {".py", ".js", ".jsx", ".mjs", ".cjs", ".ts", ".tsx", ".mts", ".cts", ".go", ".rb",
|
|
48
|
+
".php", ".java", ".cs", ".sql", ".tf", ".sh", ".bash", ".vue", ".svelte", ".astro",
|
|
49
|
+
".env", ".yml", ".yaml"}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _payload() -> dict:
|
|
53
|
+
"""PostToolUse sends its event as JSON on stdin. Malformed input is not our problem to fix."""
|
|
54
|
+
try:
|
|
55
|
+
raw = sys.stdin.read(_MAX_STDIN)
|
|
56
|
+
except Exception:
|
|
57
|
+
return {}
|
|
58
|
+
try:
|
|
59
|
+
data = json.loads(raw) if raw.strip() else {}
|
|
60
|
+
except ValueError:
|
|
61
|
+
return {}
|
|
62
|
+
return data if isinstance(data, dict) else {}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def edited_paths(event: dict) -> list[str]:
|
|
66
|
+
"""Absolute paths this tool call wrote. Edit/Write/MultiEdit all carry `file_path`."""
|
|
67
|
+
tool_input = event.get("tool_input")
|
|
68
|
+
if not isinstance(tool_input, dict):
|
|
69
|
+
return []
|
|
70
|
+
out = []
|
|
71
|
+
for key in ("file_path", "notebook_path"):
|
|
72
|
+
value = tool_input.get(key)
|
|
73
|
+
if isinstance(value, str) and value.strip():
|
|
74
|
+
out.append(value)
|
|
75
|
+
return out
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _repo_root(start: Path) -> Path | None:
|
|
79
|
+
try:
|
|
80
|
+
proc = subprocess.run(["git", "-C", str(start), "rev-parse", "--show-toplevel"],
|
|
81
|
+
capture_output=True, text=True,
|
|
82
|
+
timeout=GIT_TIMEOUT_SECONDS)
|
|
83
|
+
except Exception:
|
|
84
|
+
return None
|
|
85
|
+
if proc.returncode != 0:
|
|
86
|
+
return None
|
|
87
|
+
root = proc.stdout.strip()
|
|
88
|
+
return Path(root) if root else None
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def run(event: dict | None = None, *, env: dict | None = None) -> int:
|
|
92
|
+
"""Return the process exit code: 0 = pass or not applicable, 2 = blocking findings."""
|
|
93
|
+
env = os.environ if env is None else env
|
|
94
|
+
event = _payload() if event is None else event
|
|
95
|
+
|
|
96
|
+
paths = [p for p in edited_paths(event) if Path(p).suffix.lower() in ANALYZABLE]
|
|
97
|
+
if not paths:
|
|
98
|
+
return 0 # a docs or config edit costs nothing
|
|
99
|
+
|
|
100
|
+
cwd = event.get("cwd") or env.get("CLAUDE_PROJECT_DIR") or os.getcwd()
|
|
101
|
+
root = _repo_root(Path(cwd)) or Path(cwd)
|
|
102
|
+
|
|
103
|
+
relative = []
|
|
104
|
+
for raw in paths:
|
|
105
|
+
try:
|
|
106
|
+
relative.append(Path(raw).resolve().relative_to(Path(root).resolve()).as_posix())
|
|
107
|
+
except (ValueError, OSError):
|
|
108
|
+
continue # written outside the repo: not ours to gate
|
|
109
|
+
if not relative:
|
|
110
|
+
return 0
|
|
111
|
+
|
|
112
|
+
# IN-PROCESS, not a subprocess. Two reasons, both learned the hard way:
|
|
113
|
+
# * a subprocess exiting 1 for "module not found" is indistinguishable from the gate exiting 1
|
|
114
|
+
# for "blocking findings", so a BROKEN check read as a FINDING and blocked the loop;
|
|
115
|
+
# * it avoids a second interpreter start (~0.2s) on every edit.
|
|
116
|
+
# The harness's own hook timeout is the outer guard.
|
|
117
|
+
try:
|
|
118
|
+
from . import findings as _findings, gate as _gate, recon as _recon
|
|
119
|
+
from . import __version__ as _version
|
|
120
|
+
facts = _recon.build_facts(Path(root), _version, only=relative)
|
|
121
|
+
ledger = _findings.build_ledger(facts, None)
|
|
122
|
+
result = _gate.verdict(ledger, facts, env.get("WEBSEC_GATE_FAIL_ON", "medium"),
|
|
123
|
+
scope_source="agent-hook",
|
|
124
|
+
min_confidence=env.get("WEBSEC_GATE_MIN_CONFIDENCE", "low"))
|
|
125
|
+
except Exception as error:
|
|
126
|
+
# FAIL OPEN, LOUDLY. A security check that blocks every edit when it is broken gets
|
|
127
|
+
# uninstalled within the hour, and then there is no check at all.
|
|
128
|
+
print(f"[websec] gate could not run ({type(error).__name__}: {error}) — NOT blocking. "
|
|
129
|
+
"This edit was not security-checked.", file=sys.stderr)
|
|
130
|
+
return 0
|
|
131
|
+
|
|
132
|
+
if not result.get("passed"):
|
|
133
|
+
# Exit 2 is what the harness shows to the model. This text IS the retry signal.
|
|
134
|
+
sys.stderr.write(_gate.render_text(result).strip() + "\n")
|
|
135
|
+
sys.stderr.write("\nThis check ran on the file you just edited. Fix the finding above, or "
|
|
136
|
+
"explain why it is a false positive.\n")
|
|
137
|
+
return 2
|
|
138
|
+
return 0
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def main() -> int:
|
|
142
|
+
return run()
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
if __name__ == "__main__":
|
|
146
|
+
raise SystemExit(main())
|