Fix: make artifact filename rooting host-OS independent in FileArtifactService - #760
Open
AmaadMartin wants to merge 3 commits into
Open
Fix: make artifact filename rooting host-OS independent in FileArtifactService#760AmaadMartin wants to merge 3 commits into
AmaadMartin wants to merge 3 commits into
Conversation
added 3 commits
August 7, 2026 00:29
getArtifactDir guarded absolute filenames with path.isAbsolute, which follows the host platform. On POSIX it read 'C:\evil.txt' and '\evil.txt' as ordinary relative names, and it left backslash separators intact, so 'sub\file.txt' became one directory whose name contains a backslash instead of nesting. Parse the filename with path.win32 instead, which reports a root for a drive, a UNC share, a leading backslash and a leading slash on every platform, and rewrite backslashes to '/' before resolving. This matches PureWindowsPath handling in adk-python.
Cover the Windows drive, drive-relative and root-relative forms, the two traversal forms written with backslashes, and the nesting and round-trip of 'sub\file.txt'.
replaceAll('\\', '/') is the idiom the repo already uses for this in
dev/src/conformance, and ES2022 is in the lib list, so the one-line
helper and its doc comment are not needed.
This was referenced Aug 7, 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.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
N/A
Problem:
getArtifactDirrejects absolute artifact filenames withpath.isAbsolute, which follows the host platform. On POSIX it readsC:\evil.txtand\evil.txtas ordinary relative names, so one filename is an error on Windows and a valid artifact on Linux. It also leaves backslashes intact, sosub\file.txtbecomes a single directory whose name contains a backslash instead of nesting undersub/. An artifact store written on one operating system does not read back the same way on another.Solution: Parse the filename with
path.win32, which reports a non-empty root for a drive, the drive-relativeC:, a UNC share, a leading backslash and a leading/on every platform. Rewrite backslashes to/before resolving, sosub\file.txtnests exactly likesub/file.txtandsub\..\..\escape.txtreaches the existing containment check. This mirrorsPureWindowsPath(...).drive or .rootin adk-python. The public API, the two error messages and the containment check are unchanged.Notes:
a:b.txtis now rejected on POSIX, becausepath.win32readsa:as a drive. adk-python rejects it identically, and no fixture or sample in this repo uses such a name.asPosixPath. It splits onpath.sep, so it is a no-op for backslashes on POSIX. It is left alone, and the filename usesreplaceAll('\\', '/')inline, the idiom already used indev/src/conformance.core/src/artifacts/file_artifact_service.ts. Fix: consolidate path containment into one shared helper and stop over-rejecting '..'-prefixed artifact filenames #658 and Fix: stop rejecting every child when the containment base is the filesystem root (stacked on #658) #676 rewrite the containment check on the lines just below it; that work is independent, so this branch starts frommainand keeps the containment predicate as it is.Testing Plan
Please describe the tests that you ran to verify your changes. This is required for all PRs that are not small documentation or typo fixes.
Unit Tests:
[x] I have added or updated unit tests for my change.
[x] All unit tests pass locally.
Six tests were added to
core/test/artifacts/file_artifact_service_test.ts. No existing test was changed.New lines reach 100% line and branch coverage, measured with
--coverage.include='core/src/artifacts/file_artifact_service.ts'.Proof the tests can fail. I ran each new test against the unfixed code.
if (path.isAbsolute(cleanFilename))— 3 tests fail. The two driveforms report
promise resolved "+0" instead of rejecting. The\evil.txtcase reportsexpected [Function] to throw error including 'Absolute artifact filename \evil.txt …' but got 'Artifact filename \evil.txt escapes s…'.cleanFilename = cleanFilename.replaceAll('\\', '/');— 2 tests fail.nests a filename that uses Windows separatorsreportspromise rejected "Error: ENOENT: no such file or directory…" instead of resolving.rejects nested traversal expressed with Windows separatorsreportspromise resolved "+0" instead of rejecting.rejects traversal expressed with Windows separators(..\escape.txt)survives both mutations.
path.relativereturns the literal name..\escape.txt, which starts with.., so today the containment checkrejects it by coincidence. I kept the test as a regression pin, because the
coincidence disappears if the containment check becomes segment-wise.
CI passes on
ubuntu-latest,windows-latestandmacos-latest. The first tworuns failed on the known
app_loaderdiscovery timeout onmacos-latest, which#664 explains and fixes;
fail-fastthen cancelled the Windows leg. A rerun ofthe same commit is green on all three.
Manual End-to-End (E2E) Tests:
Please provide instructions on how to manually test your changes, including any necessary setup or configuration.
Run this on Linux or macOS after
npm install && npm run build:Observed on Node v22.22.2:
Checklist
[x] I have read the CONTRIBUTING.md document.
[x] I have performed a self-review of my own code.
[x] I have commented my code, particularly in hard-to-understand areas.
[x] I have added tests that prove my fix is effective or that my feature works.
[x] New and existing unit tests pass locally with my changes.