fix: validate saved URLs before navigation in restoreState#751
Open
Gonzih wants to merge 1 commit intogarrytan:mainfrom
Open
fix: validate saved URLs before navigation in restoreState#751Gonzih wants to merge 1 commit intogarrytan:mainfrom
Gonzih wants to merge 1 commit intogarrytan:mainfrom
Conversation
restoreState() restored page URLs from the browse state file (~/.gstack/browse.json) without validation. The state file is user-writable and persists across sessions. A tampered or maliciously crafted state file could navigate the browser to: - file:// URIs (read local files) - cloud metadata endpoints (169.254.169.254) - javascript: URIs validateNavigationUrl() is already imported and used by goto commands. Apply the same validation here before restoring saved page URLs. Invalid URLs are skipped gracefully with a log message. Closes garrytan#674
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
`restoreState()` in `browser-manager.ts` navigates to URLs from the saved state file without validation:
```typescript
if (saved.url) {
await page.goto(saved.url, { ... }); // no validation
}
```
The state file (`~/.gstack/browse.json`) is user-writable and persists across sessions. A tampered state file could navigate the browser to `file://` URIs, cloud metadata endpoints, or `javascript:` URIs on the next session start.
Issue #674.
Fix
Call `validateNavigationUrl(saved.url)` before navigation. This function is already imported and used for the `goto` command — the same protection should apply to session restoration. Invalid URLs are skipped with a log message, leaving a blank page instead.
sent from mStack