Expose SRI analysis as an importable library API (#18)#22
Merged
Conversation
Lift the SRI scanning logic out of the standalone scripts/sri_parser.py script and into the published package as domain_security_analyzer.sri, so consumers (e.g. tpcrm-findings-scanner) can reuse it instead of reimplementing Subresource Integrity parsing. - Add domain_security_analyzer/sri.py with SRIParser, UnsafeResource, and a scan_url() convenience function returning the structured report (per-resource integrity/crossorigin values, machine-readable reason codes, observed CSP headers, and compensating-control detection). - Re-export SRIParser/UnsafeResource/scan_url from the package __init__. - Reduce scripts/sri_parser.py to a thin CLI wrapper that imports the core logic, preserving `python scripts/sri_parser.py <url>`. - Add tests/test_sri.py (network-free) covering each reason code, CSP compensating-control logic, and the public API surface. - Document the importable API in the README SRI section. Closes the in-repo portion of #18; cross-repo wiring (having tpcrm-findings-scanner depend on this package and documenting the detect-vs-dispute boundary in both READMEs) remains tracked there. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XYvSCw1sjoG2AHbLPCsX7S
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes the in-repo portion of #18: lift the SRI scanning logic out of the standalone
scripts/sri_parser.pyand into the published package asdomain_security_analyzer.sri, so consumers (e.g.tpcrm-findings-scanner) canpip install domain-security-analyzerand reuse it instead of reimplementing Subresource Integrity parsing.Changes
domain_security_analyzer/sri.py—SRIParser, theUnsafeResourcedataclass, and the convenience function named in the issue:integrity/crossoriginvalues, machine-readablereasons(missing-integrity,invalid-integrity-hash,mixed-invalid-hashes,non-https-resource,missing-crossorigin), observedContent-Security-Policyheaders, and whether a restrictive one is present as a compensating control.scripts/sri_parser.py→ thin CLI wrapper that imports the core logic from the package.python scripts/sri_parser.py <url>and all its flags are unchanged (verified--help).SRIParser/UnsafeResource/scan_urlfromdomain_security_analyzer.tests/test_sri.py— 14 network-free tests covering each reason code, the CSP compensating-control logic, scheme normalization, and the public API surface.Verification
domain_security_analyzer/sri.pyships inside it.from domain_security_analyzer.sri import scan_urland the package-level re-export resolve to the same object.SRIParserfrom the new module.Out of scope (stays tracked on #18)
The remaining checkboxes need the other repo, which isn't in this session's scope:
tpcrm-findings-scannerdepend on this package.So #18 stays open for that cross-repo wiring; this PR delivers the importable API it depends on.
🤖 Generated with Claude Code
Generated by Claude Code