fix: block local/private URL scraping in scrape tool#1052
Open
stablegenius49 wants to merge 1 commit intoItzCrazyKns:masterfrom
Open
fix: block local/private URL scraping in scrape tool#1052stablegenius49 wants to merge 1 commit intoItzCrazyKns:masterfrom
stablegenius49 wants to merge 1 commit intoItzCrazyKns:masterfrom
Conversation
Contributor
There was a problem hiding this comment.
3 issues found across 1 file
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/lib/agents/search/researcher/actions/scrapeURL.ts">
<violation number="1" location="src/lib/agents/search/researcher/actions/scrapeURL.ts:65">
P1: IPv4-mapped IPv6 filtering can be bypassed with hex/compressed forms (e.g. `::ffff:7f00:1`), allowing local/private SSRF targets.</violation>
<violation number="2" location="src/lib/agents/search/researcher/actions/scrapeURL.ts:133">
P1: DNS lookup errors are swallowed in the URL safety check, causing fail-open behavior where unvalidated URLs may still be fetched.</violation>
<violation number="3" location="src/lib/agents/search/researcher/actions/scrapeURL.ts:152">
P1: DNS pre-validation is decoupled from the actual fetch connection target, leaving a DNS rebinding TOCTOU SSRF bypass path.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| redirectCount = 0, | ||
| ): Promise<Response> => { | ||
| const safeURL = await assertSafeScrapeURL(rawURL); | ||
| const res = await fetch(safeURL, { redirect: 'manual' }); |
Contributor
There was a problem hiding this comment.
P1: DNS pre-validation is decoupled from the actual fetch connection target, leaving a DNS rebinding TOCTOU SSRF bypass path.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/lib/agents/search/researcher/actions/scrapeURL.ts, line 152:
<comment>DNS pre-validation is decoupled from the actual fetch connection target, leaving a DNS rebinding TOCTOU SSRF bypass path.</comment>
<file context>
@@ -17,6 +28,147 @@ You should only call this tool when the user has specifically requested informat
+ redirectCount = 0,
+): Promise<Response> => {
+ const safeURL = await assertSafeScrapeURL(rawURL);
+ const res = await fetch(safeURL, { redirect: 'manual' });
+
+ if (res.status >= 300 && res.status < 400) {
</file context>
| } | ||
|
|
||
| if (normalized.startsWith('::ffff:')) { | ||
| return isBlockedIPAddress(normalized.slice('::ffff:'.length)); |
Contributor
There was a problem hiding this comment.
P1: IPv4-mapped IPv6 filtering can be bypassed with hex/compressed forms (e.g. ::ffff:7f00:1), allowing local/private SSRF targets.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/lib/agents/search/researcher/actions/scrapeURL.ts, line 65:
<comment>IPv4-mapped IPv6 filtering can be bypassed with hex/compressed forms (e.g. `::ffff:7f00:1`), allowing local/private SSRF targets.</comment>
<file context>
@@ -17,6 +28,147 @@ You should only call this tool when the user has specifically requested informat
+ }
+
+ if (normalized.startsWith('::ffff:')) {
+ return isBlockedIPAddress(normalized.slice('::ffff:'.length));
+ }
+
</file context>
Comment on lines
+133
to
+141
| } catch (error: any) { | ||
| if ( | ||
| error instanceof Error && | ||
| error.message.startsWith( | ||
| 'Refusing to access local or private network URL:', | ||
| ) | ||
| ) { | ||
| throw error; | ||
| } |
Contributor
There was a problem hiding this comment.
P1: DNS lookup errors are swallowed in the URL safety check, causing fail-open behavior where unvalidated URLs may still be fetched.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/lib/agents/search/researcher/actions/scrapeURL.ts, line 133:
<comment>DNS lookup errors are swallowed in the URL safety check, causing fail-open behavior where unvalidated URLs may still be fetched.</comment>
<file context>
@@ -17,6 +28,147 @@ You should only call this tool when the user has specifically requested informat
+ `Refusing to access local or private network URL: ${rawURL}`,
+ );
+ }
+ } catch (error: any) {
+ if (
+ error instanceof Error &&
</file context>
Suggested change
| } catch (error: any) { | |
| if ( | |
| error instanceof Error && | |
| error.message.startsWith( | |
| 'Refusing to access local or private network URL:', | |
| ) | |
| ) { | |
| throw error; | |
| } | |
| } catch (error: any) { | |
| if ( | |
| error instanceof Error && | |
| error.message.startsWith( | |
| 'Refusing to access local or private network URL:', | |
| ) | |
| ) { | |
| throw error; | |
| } | |
| throw new Error( | |
| `Unable to verify URL safety via DNS lookup for ${rawURL}: ${error instanceof Error ? error.message : String(error)}`, | |
| ); | |
| } |
9 tasks
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.
Summary
scrape_urlrequests to localhost, private IP ranges, and hostnames that resolve to local/private addressesFixes #949.
Testing
./node_modules/.bin/eslint src/lib/agents/search/researcher/actions/scrapeURL.ts./node_modules/.bin/tsc --noEmitSummary by cubic
Block scraping of localhost and private network URLs in the
scrape_urltool to prevent SSRF and unsafe requests. Only HTTP(S) targets are allowed, with validated and limited redirects. Fixes #949.localhost, loopback, and private IP ranges (IPv4/IPv6), plus common local TLDs.scrape_urltool used for user-requested page summaries.Written for commit b56ac10. Summary will update on new commits.