fix(bootstrap): reject path-traversal in filer-controlled primary_doc - #214
Open
sroussey wants to merge 1 commit into
Open
fix(bootstrap): reject path-traversal in filer-controlled primary_doc#214sroussey wants to merge 1 commit into
sroussey wants to merge 1 commit into
Conversation
The Feed-tarball writer composed cache paths as `<raw>/accessiondocs/<cik10>/<accNoDash>-<primary_doc>` where `primary_doc` comes straight from the EDGAR submissions API — a value under the filer's control. A hostile filer could set `primary_doc` to something like `../../../etc/edgar-attacker` and steer the writer (and the symmetric `readCachedDoc` reader on the forms path) anywhere the process could reach on disk. Add `src/util/accessionDocPath.ts` with two small helpers, `sanitizePrimaryDoc` (rejects empty, `..`, `.`, any path separator, NUL, or leading `/`) and `assertInsideDir` (belt-and-braces resolved-path containment check). Both writer (`BootstrapAccessionDocsTask.writeFiling`, which now warns and falls through to the full-submission `.txt` fallback on a rejected name) and reader (`ProcessAccessionDocFormTask.readCachedDoc`, which treats an unsafe name as a silent cache miss) go through them before touching any composed path. Unit tests cover the sanitizer plus a containment case; an integration test drives the writer end-to-end with an attacker-controlled `primary_doc` and asserts nothing escapes the cik directory.
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
The Feed-tarball writer composed accession-doc cache paths as
<raw>/accessiondocs/<cik10>/<accNoDash>-<primary_doc>whereprimary_docis a filer-authored field on the EDGAR submissions API.Nothing rejected
.., absolute paths, path separators, or NUL bytes,so a hostile filer could steer both the writer
(
BootstrapAccessionDocsTask.writeFiling) and the symmetric reader(
ProcessAccessionDocFormTask.readCachedDoc) anywhere on disk theprocess could reach — arbitrary-file write and arbitrary-file read.
Fix
New
src/util/accessionDocPath.tsexposes two named helpers used byboth paths before any composed path touches the filesystem:
sanitizePrimaryDoc(name)— trims and rejects an empty string,.,.., any/or\, NUL, or a leading/, returning the basenameotherwise.
assertInsideDir(fullPath, dir)— belt-and-braces containment checkon the resolved paths.
Writer:
writeFilingsanitizesprimary_doc; on rejection it logs awarning naming the cik / accession / offending value and falls through
to the full-submission
.txtfallback under the cik directory ratherthan aborting the whole day.
assertInsideDirruns on both the primaryand full-submission paths as a second gate.
Reader:
readCachedDocsanitizes the fileName; an unsafe name is asilent cache miss (the caller falls back to the normal network fetch,
matching the ENOENT branch).
assertInsideDirguards the composed path.Test plan
src/util/accessionDocPath.test.ts: sanitizer rejects../../../etc/edgar-attacker,/etc/passwd,evil\0.htm, backslash,and empty; accepts and trims
wf-form4.xml.assertInsideDiraccepts a normal join and rejects a
..-escaping composed path.BootstrapAccessionDocsTask.test.ts:seeded filing with
primary_doc: "../../../../../etc/edgar-attacker"writes only the full-submission
.txtunder the cik dir(
docsWritten === 1), nothing lands at/etc/edgar-attackeror theraw root's parent, and a warning naming the filing plus the offending
value is emitted.
bunx vitest run src/util/accessionDocPath.test.ts src/task/bootstrap/BootstrapAccessionDocsTask.test.ts src/task/forms/ProcessAccessionDocFormTask.cache.test.ts— 19 passed.npx tsc --noEmit— clean on the touched files (the onepre-existing
feedTarball.tserror is unrelated and present onmain).Generated by Claude Code