Repository navigation
Fix symlink path traversal and unsafe revert --clean deletions (v1.0.2) - #5
Merged
Merged
Conversation
- Confine config-derived output paths physically via lstat/realpath against the real project root; reject symlinked output files and directory symlinks that escape the root; write with O_NOFOLLOW and re-validate after mkdir. - revert --clean now deletes only files verified as TailClass output; foreign files, scanned sources, symlinks and directories are preserved and reported via cleanupSkipped/stderr. - Add src/fs-safety.js, regression tests in test/path-safety.test.js, docs/schema/type updates, and bump version to 1.0.2. Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
- Explicitly distinguish allowed directory symlinks (inside root) from symlinked output files, which are now rejected even when the link points inside the root, even with --force or a CLI path. - Clarify CHANGELOG, README, SECURITY.md, config schema, TS types and CLI --help; make runtime errors say how to migrate and stop suggesting --output for this case. - Add regression tests for the inside-root symlink case and for --clean never unlinking a symlink. Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
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
Security release v1.0.2. Fixes the two vulnerabilities reported during follow-up testing of the 1.0.1 hardening:
outputCss,dictionaryFileandmanifestFilewere confined by a lexicalpath.resolve()check only. A cloned repo containing e.g.assets -> ../../outsidecould makeapply/listwrite — orrevert --cleandelete — files outside the project root.revert --cleancould delete non-TailClass files (High).--cleanunconditionally deleted whatever the configured CSS/manifest paths pointed at, including hand-written stylesheets, unrelated JSON, source files, and outside files reachable via a symlink.What changed
Physical path confinement
src/fs-safety.js: every existing component of an output path islstated and resolved withrealpathagainst the real project root. Symlinks that leave the root (or are broken) are rejected; writes useO_NOFOLLOW, re-validate after creating parent directories, and deletions only ever remove regular files.src/config.js:resolveWritablePath()now defaults to treating an unspecified path source as untrusted, and gainedwriteResolvedFile()/unlinkResolvedFile()so all output writes and--cleandeletions go through the checked resolver.validateOutputPath()applies the same physical check at config load time..tailclass-backup/, the auto-discovered dictionary, source rewrites andinit. Explicit CLI paths outside the root are still honoured.revert --cleanownership--no-commentsCSS)@applyrules matching an owned revert manifest. Manifests must carry TailClass markers and a plausiblemappingsrecord.cleanupSkippedplus a stderr warning (also in--jsonmode).--forcenever relaxes this.generator: "TailClass"andmanifestPath, so clean can still find real output after a config change.revertProject()returnscleanedFilesandcleanupSkipped.Behavior change (documented explicitly)
--force, and even for an explicit CLI path. 1.0.1 followed such links on write and unlinked them on--clean. Symlinked directories that resolve inside the root remain supported.outputCss/dictionaryFile/manifestFileat the real file. Documented inCHANGELOG.md,README.md,SECURITY.md, the config JSON schema,types/index.d.ts, CLI--helpand the runtime error itself (which no longer suggests the invalid--outputworkaround).Version & docs
package.jsonandsrc/version.js→1.0.2; changelog, security policy (new guarantees + supported-version table), README examples, schema descriptions, TS declarations, CLI help and release-workflow example updated.v1.0.2tag was created, so the publish workflow has not been triggered.Verification
npm run check→ lint passes, 66/66 tests (16 new regression tests intest/path-safety.test.js: symlink escapes, inside-root symlink rejection, ownership checks, markerless CSS, scanned-source protection, CLI paths, version pinning).npm run demopasses.npm pack --dry-runproducestailclass-1.0.2.tgzand includessrc/fs-safety.js.Review notes
cleanedFiles,cleanupSkipped); existing callers are unaffected.resolveConfig(so evenscanrejects them), matching the existing behavior for../traversal.