feat(core): brotli-compress .socket.facts.json on full-scan upload#219
Merged
Martin Torp (mtorp) merged 1 commit intoJun 2, 2026
Conversation
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
🚀 Preview package published! Install with: pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple socketsecurity==2.3.1.dev3Docker image: |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
Compress the reachability facts file to a `.socket.facts.json.br` multipart part before uploading it as part of a full scan. The Socket API transparently decompresses parts named exactly `.socket.facts.json.br` and stores plain JSON, so the stored result is unchanged while the on-the-wire payload shrinks by roughly 10-40x for typical facts files. This keeps large tier-1 reachability facts files under the API's per-file upload size cap. Previously an oversized facts file made the full-scan upload fail (surfaced as an HTTP 4xx/502 with the scan stuck and no report produced). - Compress at the upload boundary (Core.create_full_scan); the on-disk file is left untouched so local consumers still read plain .socket.facts.json. - Only files whose basename is exactly .socket.facts.json are compressed (the API matches that exact name); a custom --reach-output-file name and empty placeholder files are left as plain uploads. - Stream in 1 MiB chunks so large files aren't held fully in memory. - Never blocks an upload: any compression failure falls back to the plain file, and a partially-written .socket.facts.json.br is removed rather than left behind in the target directory. - Add brotli (CPython) / brotlicffi (PyPy) dependency.
9eb52f5 to
52a5a7e
Compare
Benjamin Barslev Nielsen (barslev)
approved these changes
Jun 2, 2026
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
Brotli-compress the reachability facts file (
.socket.facts.json) before it is uploaded as part of a full scan. The Socket API transparently decompresses any multipart part whose basename is exactly.socket.facts.json.brand stores it as plain.socket.facts.json, so the stored result is unchanged — but the on-the-wire payload shrinks dramatically (typically ~10–40×).Motivation
Large tier‑1 reachability facts files can exceed the API's per‑file upload size cap. When that happens the full‑scan upload fails (surfaced to the CLI as an HTTP 4xx/“502”), leaving the scan stuck with no report. Compressing on upload keeps even very large facts files well under the cap, relying on the API's existing transparent
.brdecompression.What changed
Core.create_full_scan), so it covers every full‑scan path (normal, diff, API‑mode,--only-facts-file, pre‑generated SBOMs)..socket.facts.jsonis left untouched — local consumers (SARIF/JSON output, tier‑1 finalize, alert selection) keep reading the plain file. Only the uploaded multipart part is swapped to a temporary.socket.facts.json.brsibling, which is deleted after upload..socket.facts.jsonis compressed (the API matches that exact name). A custom--reach-output-filename and empty baseline‑scan placeholder files are uploaded plain, as before.brotli(CPython) /brotlicffi(PyPy) dependency. Patch version bump2.3.0→2.3.1.Testing
tests/core/test_facts_compression.py): roundtrip, multipart‑entry rewrite, directory‑prefix preservation, empty‑file skip, custom‑name skip, and compression‑failure fallback. Full suite: 261 passed, 2 skipped.socketdevSDK +requestsmultipart encoder against a local capture server. Confirmed the server receives a part named exactly.socket.facts.json.brcontaining valid brotli that decompresses to the byte‑exact original facts JSON; the plain part is not sent; the temp file is cleaned up; the on‑disk file is preserved.Not exercised in CI: the live server‑side decompression round‑trip (depends on the deployed API) and a real reachability (Coana) run — the analysis/generation code path is unchanged by this PR.
🤖 Generated with Claude Code