-
Notifications
You must be signed in to change notification settings - Fork 3.7k
feat(desktop): SSRF hardening + shared @sim/security/ssrf (re-home of #5763) #5784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6d42cc8
feat: re-home @sim/security/ssrf + sim SSRF dedup onto dev (clean core)
waleedlatif1 4597fcb
feat(desktop): re-integrate SSRF guard + hardening onto rewritten dev
waleedlatif1 1fff071
chore(desktop): biome format install-local.ts (pre-existing dev lint …
waleedlatif1 6303465
refactor: apply audit cleanup (reuse + simplify)
waleedlatif1 66df587
refactor: /simplify pass + review fixes
waleedlatif1 aa6e587
fix(desktop): swallow late DNS rejection after the SSRF lookup timeou…
waleedlatif1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
|
|
||
| const { mockLookup } = vi.hoisted(() => ({ mockLookup: vi.fn() })) | ||
|
|
||
| vi.mock('node:dns/promises', () => ({ | ||
| default: { lookup: mockLookup }, | ||
| })) | ||
|
|
||
| import { checkAgentUrl, isBlockedRequestUrl } from '@/main/browser-agent/url-guard' | ||
|
|
||
| describe('checkAgentUrl', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
| mockLookup.mockResolvedValue([{ address: '93.184.216.34', family: 4 }]) | ||
| }) | ||
|
|
||
| it('rejects non-http(s) schemes without resolving', async () => { | ||
| const result = await checkAgentUrl('file:///etc/passwd') | ||
| expect(result.ok).toBe(false) | ||
| expect(mockLookup).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it('rejects malformed URLs', async () => { | ||
| expect((await checkAgentUrl('not a url')).ok).toBe(false) | ||
| }) | ||
|
|
||
| it('blocks private IP literals without resolving', async () => { | ||
| expect((await checkAgentUrl('http://127.0.0.1/')).ok).toBe(false) | ||
| expect((await checkAgentUrl('http://169.254.169.254/latest/meta-data')).ok).toBe(false) | ||
| expect((await checkAgentUrl('http://10.0.0.5/')).ok).toBe(false) | ||
| expect((await checkAgentUrl('http://[::1]/')).ok).toBe(false) | ||
| expect(mockLookup).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it('allows public IP literals without resolving', async () => { | ||
| expect((await checkAgentUrl('https://8.8.8.8/')).ok).toBe(true) | ||
| expect(mockLookup).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it('allows hostnames that resolve to public addresses', async () => { | ||
| const result = await checkAgentUrl('https://example.com/page') | ||
| expect(result.ok).toBe(true) | ||
| expect(mockLookup).toHaveBeenCalledWith('example.com', { all: true, verbatim: true }) | ||
| }) | ||
|
|
||
| it('blocks hostnames that resolve to a private address (DNS rebinding)', async () => { | ||
| mockLookup.mockResolvedValue([{ address: '10.1.2.3', family: 4 }]) | ||
| expect((await checkAgentUrl('https://rebind.evil.test/')).ok).toBe(false) | ||
| }) | ||
|
|
||
| it('blocks when any resolved address is private', async () => { | ||
| mockLookup.mockResolvedValue([ | ||
| { address: '93.184.216.34', family: 4 }, | ||
| { address: '192.168.0.9', family: 4 }, | ||
| ]) | ||
| expect((await checkAgentUrl('https://mixed.test/')).ok).toBe(false) | ||
| }) | ||
|
|
||
| it('fails closed when DNS resolution fails', async () => { | ||
| mockLookup.mockRejectedValue(new Error('ENOTFOUND')) | ||
| expect((await checkAgentUrl('https://nope.invalid/')).ok).toBe(false) | ||
| }) | ||
|
|
||
| it('fails closed when the DNS lookup exceeds the deadline', async () => { | ||
| vi.useFakeTimers() | ||
| try { | ||
| mockLookup.mockReturnValue(new Promise(() => {})) // never resolves | ||
| const pending = checkAgentUrl('https://slow.test/') | ||
| await vi.advanceTimersByTimeAsync(5_000) | ||
| expect((await pending).ok).toBe(false) | ||
| } finally { | ||
| vi.useRealTimers() | ||
| } | ||
| }) | ||
| }) | ||
|
|
||
| describe('isBlockedRequestUrl', () => { | ||
| it('blocks literal private/reserved hosts', () => { | ||
| expect(isBlockedRequestUrl('http://169.254.169.254/latest/meta-data')).toBe(true) | ||
| expect(isBlockedRequestUrl('http://127.0.0.1:8080/x')).toBe(true) | ||
| expect(isBlockedRequestUrl('https://[fd00::1]/')).toBe(true) | ||
| }) | ||
|
|
||
| it('allows public literals and hostnames (classified at nav time)', () => { | ||
| expect(isBlockedRequestUrl('https://8.8.8.8/')).toBe(false) | ||
| expect(isBlockedRequestUrl('https://example.com/x')).toBe(false) | ||
| }) | ||
|
|
||
| it('does not throw on malformed input', () => { | ||
| expect(isBlockedRequestUrl('::::')).toBe(false) | ||
| }) | ||
| }) |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.