fix: path traversal in design serve /api/reload — arbitrary file read#752
Open
Gonzih wants to merge 1 commit intogarrytan:mainfrom
Open
fix: path traversal in design serve /api/reload — arbitrary file read#752Gonzih wants to merge 1 commit intogarrytan:mainfrom
Gonzih wants to merge 1 commit intogarrytan:mainfrom
Conversation
POST /api/reload accepts a { html: "/path/to/file.html" } body and
reads that file with fs.readFileSync() without path validation.
Any path the caller controls gets read and served via GET /.
Attack: POST /api/reload {"html": "/etc/passwd"}
→ GET / returns the contents of /etc/passwd
Fix: validate that the reload path resolves within the same directory
as the original HTML file passed to serve(). Paths outside that
directory are rejected with 403. Uses path.resolve() to canonicalize
before comparison.
Closes garrytan#672
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.
The Bug
`POST /api/reload` in `design/src/serve.ts` accepts a JSON body with an arbitrary `html` path and reads it with no validation:
```typescript
const newHtmlPath = body.html;
if (!newHtmlPath || !fs.existsSync(newHtmlPath)) { ... } // existence check only
htmlContent = fs.readFileSync(newHtmlPath, "utf-8"); // reads anything
```
The design server binds to localhost, but the Chrome extension (or any local process) can POST to it. Attack:
```
POST /api/reload {"html": "/etc/passwd"}
GET / → returns contents of /etc/passwd
```
Issue #672.
Fix
Validate that the reload path resolves within the same directory as the original HTML file. Paths outside are rejected with 403. The agent only ever reloads variant files in the same output directory — legitimate use is unaffected.
sent from mStack