@@ -16,16 +16,14 @@ type Init = {
1616
1717const fetch = ( input : string | URL , init : Init = { } ) =>
1818 Effect . gen ( function * ( ) {
19- // Rules are matched against the URL that is requested, so `HTTPS://EVIL.COM` meets a rule for `https://evil.com/*`.
20- const parsed = URL . parse ( String ( input ) )
21- if ( parsed === null ) return yield * Effect . fail ( new TypeError ( `fetch received an invalid URL: ${ String ( input ) } ` ) )
22- if ( parsed . protocol === "file:" ) return yield * Effect . fail ( new Error ( "fetch cannot be used for filesystem access." ) )
19+ // Rules match the URL as written. The fragment is never sent, and would keep a rule for the exact URL from
20+ // matching.
21+ const url = String ( input ) . split ( "#" ) [ 0 ]
22+ const parsed = URL . parse ( url )
23+ if ( parsed ?. protocol === "file:" ) return yield * Effect . fail ( new Error ( "fetch cannot be used for filesystem access." ) )
2324 // Rules match the URL, so `https://user@evil.com` would slip past a rule for `https://evil.com/*`.
24- if ( parsed . username || parsed . password )
25+ if ( parsed ? .username || parsed ? .password )
2526 return yield * Effect . fail ( new TypeError ( "fetch cannot be used with credentials in the URL." ) )
26- // The fragment is never sent, and would keep a rule for the exact URL from matching.
27- parsed . hash = ""
28- const url = parsed . href
2927 const execution = yield * CodeModeExecution . Service
3028 const permission = yield * Permission . Service
3129 const source = { type : "tool" as const , messageID : execution . messageID , id : execution . id }
@@ -35,7 +33,7 @@ const fetch = (input: string | URL, init: Init = {}) =>
3533 action : "webfetch" ,
3634 resources : [ url ] ,
3735 save : [ "*" ] ,
38- metadata : display ( [ url , init ] ) ,
36+ metadata : display ( [ input , init ] ) ,
3937 sessionID : execution . sessionID ,
4038 agent : execution . agent ,
4139 source,
0 commit comments