Deno: fetch panicked when accepting file scheme url

Created on 19 Feb 2020  路  9Comments  路  Source: denoland/deno

```fetch.js
fetch("file:///path/to/file")


RUST_BACKTRACE=1 deno -A fetch.js
thread 'main' panicked at 'called Option::unwrap() on a None value', /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libcore/macros/mod.rs:15:40
stack backtrace:
0: ::fmt
1: core::fmt::write
2: std::io::Write::write_fmt
3: std::panicking::default_hook::{{closure}}
4: std::panicking::default_hook
5: std::panicking::rust_panic_with_hook
6: rust_begin_unwind
7: core::panicking::panic_fmt
8: core::panicking::panic
9: deno::permissions::DenoPermissions::check_net_url
10: deno::ops::fetch::op_fetch
11: deno::state::State::core_op::{{closure}}
12: deno_core::ops::OpRegistry::call
13: deno_core::isolate::Isolate::dispatch_op
14: deno_core::bindings::send
15: >::mapping::c_fn
16: _ZN2v88internal25FunctionCallbackArguments4CallENS0_15CallHandlerInfoE
17: _ZN2v88internal12_GLOBAL__N_119HandleApiCallHelperILb0EEENS0_11MaybeHandleINS0_6ObjectEEEPNS0_7IsolateENS0_6HandleINS0_10HeapObjectEEESA_NS8_INS0_20FunctionTemplateInfoEEENS8_IS4_EENS0_16BuiltinArgumentsE
18: _ZN2v88internalL26Builtin_Impl_HandleApiCallENS0_16BuiltinArgumentsEPNS0_7IsolateE
note: Some details are omitted, run with RUST_BACKTRACE=full for a verbose backtrace.
fatal runtime error: failed to initiate panic, error 5
[1] 95204 abort RUST_BACKTRACE=1 deno -A fetch.js
```

Most helpful comment

And discussed in #2150, Chrome allows it with a flag. Yes, it is for security issues in browsers, but I think the expectations in Deno are there as a server workload to just follow the Deno security model and allow it. It should respect the allow-read flag though versus the allow-net flag, IMO.

All 9 comments

Should file url be valid for fetch? 馃

Ref #2150. fetch shouldn't accept file:// URLs - it should error out in TS without calling Rust.

Is there a reason fetch shouldn't accept file urls?

@ry It's not a http server. I thought browsers generated responses around files and it would work but I just tried fetching relatively from a file:/// URL in chrome and it says it's not supported.

Fetch API cannot load file:///C:/Users/Nayeem/documents/3.png. URL scheme "file" is not supported.

@ry It's not a http server. I thought browsers generated responses around files and it would work but I just tried fetching relatively from a file:/// URL in chrome and it says it's not supported.

Fetch API cannot load file:///C:/Users/Nayeem/documents/3.png. URL scheme "file" is not supported.

~It does work in Firefox though if you are on a file:// origin if I remember right. I'll test that in a second.~

__Edit:__ It doesn't work in FF anymore by default. Only with a flag. https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors/CORSRequestNotHttp

And discussed in #2150, Chrome allows it with a flag. Yes, it is for security issues in browsers, but I think the expectations in Deno are there as a server workload to just follow the Deno security model and allow it. It should respect the allow-read flag though versus the allow-net flag, IMO.

has anyone claim this issue?

Note: same happen when using data: scheme.

Fixed in #4085, let's keep discussion of fetching file:// URLs in #2150

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ry picture ry  路  3Comments

benjamingr picture benjamingr  路  3Comments

ry picture ry  路  3Comments

doutchnugget picture doutchnugget  路  3Comments

JosephAkayesi picture JosephAkayesi  路  3Comments