Skip to content

fix: validate saved URLs before navigation in restoreState#751

Open
Gonzih wants to merge 1 commit intogarrytan:mainfrom
Gonzih:fix/restore-state-url-validation
Open

fix: validate saved URLs before navigation in restoreState#751
Gonzih wants to merge 1 commit intogarrytan:mainfrom
Gonzih:fix/restore-state-url-validation

Conversation

@Gonzih
Copy link
Copy Markdown

@Gonzih Gonzih commented Apr 1, 2026

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

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant