126 Commits
Author SHA1 Message Date
Bartek Iwańczuk b85412369e fix(permissions): check resolved IP against import deny list (#36486)
`--deny-import` is matched against the specifier's hostname before any
DNS lookup, so a module whose hostname resolves to a denied address loads
anyway. Public wildcard DNS services make this trivial to reach —
`127.0.0.1.nip.io` resolves to `127.0.0.1`, defeating `--deny-import=127.0.0.1` — but no
DNS control is needed at all, since any record pointing at a denied address
works.

The module fetcher's HTTP client now uses the permissioned connector
`fetch()` already goes through, so every resolved address is checked against the
import deny list before a socket is opened. This is the post-resolution check
`check_net_resolved` performs for `--deny-net`, applied to the import
deny list instead. The client is built from a deny-only permissions container
rather than the factory's root one, because building that resolves the main module,
which needs the file fetcher. Modules already in the HTTP cache are still
loaded without this check, since no connection is made for them.
2026-08-12 13:54:17 +02:00
Nathan Whitaker fbe07f1a79 fix(http): preserve stripped headers across redirects (#36360)
## Summary

- keep redirect request headers as chain state instead of rebuilding
them from the original request on every hop
- ensure an `Authorization` header removed by redirect handling remains
absent on subsequent hops
- add a deterministic multi-hop test using ephemeral local listeners

## Behavior

Same-origin redirects and same-host HTTP-to-HTTPS upgrades continue
forwarding `Authorization`. Host or port changes and HTTPS-to-HTTP
transitions remove it for the remainder of the redirect chain.

## Tests

- `./tools/format.js`
- `cargo test -p deno test_http_client_redirect_does_not_restore_auth
--lib`
- `cargo test -p deno test_should_strip_auth_on_redirect --lib`
- `cargo test -p deno test_http_client_download_redirect --lib`
- `cargo check -p deno --lib`
- `cargo build -p deno --bin deno`
2026-07-31 13:46:05 -07:00
Bartek Iwańczuk 197dfcae86 fix(ext/fetch): keep content-encoding and content-length on decompressed responses (#35124)
When fetch transparently decompressed a gzip or brotli response body,
the
client also removed the content-encoding, content-length, and
transfer-encoding headers from the response. Per the fetch spec,
handling
content codings only decodes the body and leaves the header list as
received, which is what browsers and Node.js (undici) do. Code that
inspects response headers (for example to detect that a server
compressed
the response) behaved differently in Deno than everywhere else.

The headers are now preserved as received from the server. Since the
kept
content-length describes the encoded body rather than the decoded
stream,
the CLI download progress bar no longer uses it as a total when a
content-encoding header is present. Existing tests asserting the
stripping
behavior were updated to assert the preserved headers instead.

Fixes #20548
2026-06-13 07:58:01 +00:00
David Sherret 39a07b283e refactor: force a reason on clippy overrides (#32761) 2026-03-16 12:41:51 +00:00
Daniil Sivak bbd5282f84 fix(npm): support npmrc certfile + keyfile (#32655)
This PR implements the missing support for `certfile` and `keyfile`
options. Now when both are set, it creates an HTTP client with the
client certificate attached.
2026-03-12 12:54:58 +00:00
9d246e77dd fix(npm): retain authorization header on http->https redirect (#29878)
Fixes #29869.

## Summary

When an npm registry is configured with `http://` in `.npmrc` and the
server
redirects to `https://`, the authorization header was being stripped.
This
happened because the previous origin-based check (`url.origin() !=
new_url.origin()`)
treated scheme changes as cross-origin, since `url::Origin` includes the
scheme.

This caused 401 errors for private registries like GitHub Packages when
configured with `http://` URLs.

---------

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-12 11:16:14 +00:00
Nathan Whitaker 95140c38e4 perf(install): move HTTP decompression for registry requests off the async event loop (#32400)
Bypass the tower-http `Decompression` middleware for npm registry
requests and instead decompress gzip on a blocking thread. This prevents
large packument decompression from blocking other HTTP/2 streams on the
event loop.

This right now doesn't have a huge impact but after a later PR to get
more parallelism of downloads it makes a difference
2026-03-02 14:40:28 +00:00
Kenta Moriuchi 8193cf96c4 chore: Happy New Year 2026 (#31748) 2026-01-08 16:28:43 +01:00
Felipe Cardozo 355d8994b2 fix: fetch fd leak (#31375)
Solution for: https://github.com/denoland/deno/issues/31080

Modern reqwest (0.12+) can safely share clients across tokio runtimes.
Because it uses the current runtime's executor instead of spawning
background threads.
Using a single shared client prevents resource leaks when worker threads
terminate.

## Context
It seems that we started to use one client per thread because hyper and
reqwest was not safe to share across tokio runtimes
(https://github.com/denoland/deno/pull/23699). But seems it's fixed at
latest reqwest versions
(https://github.com/seanmonstar/reqwest/issues/1148#issuecomment-3120048532).

This PR is using one client again, as we now already use the version of
reqwest with this fix.
2025-11-21 23:27:04 -03:00
Nathan Whitaker 9379a74e08 chore: update to edition 2024 (#29923) 2025-07-02 17:59:39 -07:00
David Sherret 539e41b8d4 fix(npm): respect etag for npm packument caching (#29130)
Stores the etag in a `_deno.etag` property on the json object of the
packument.
2025-05-02 09:49:05 -04:00
David Sherret 57dd66ec3d refactor: move denort to separate crate (#27688)
This slightly degrades the performance of CJS export analysis on
subsequent runs because I changed it to no longer cache in the DENO_DIR
with this PR (denort now properly has no idea about the DENO_DIR). We'll
have to change it to embed this data in the binary and that will also
allow us to get rid of swc in denort (will do that in a follow-up PR).
2025-01-17 20:39:29 +00:00
David Sherret 093f3ba565 refactor(npm): extract out some npm fs resolution code from the cli (#27607)
Moves the npm fs resolvers into the deno_resolution crate.

This does not entirely move things out, but is a step in that direction.
2025-01-09 12:10:07 -05:00
Leo KettmeirandDavid Sherret ea30e188a8 refactor: update deno_core for error refactor (#26867)
Closes #26171

---------

Co-authored-by: David Sherret <dsherret@gmail.com>
2025-01-08 14:52:32 -08:00
Kenta Moriuchi 8fb073d7b4 chore: Happy New Year 2025 (#27509) 2024-12-31 19:12:39 +00:00
David Sherret ac7b33a340 chore: cargo fmt - turn on group_imports=StdExternalCrate (#26646) 2024-12-31 12:13:39 -05:00
Sean McArthur b1c685f4b7 fix(ext/fetch): retry some http/2 errors (#27417)
This brings some of the HTTP/2 retry behavior from reqwest to
`ext/fetch`. It will retry very specific HTTP/2 errors once, if the body
is able to be used again.

Closes #27332
2024-12-18 23:04:29 +01:00
David Sherret 95928c46eb refactor: extract out FileFetcher to deno_cache_dir (#27263) 2024-12-16 23:39:40 +00:00
Marvin HagemeisterandBartek Iwańczuk 5f0bb3c6f4 fix: .npmrc settings not being passed to install/add command (#26473)
We weren't passing the resolved npmrc settings to the install commands.
This lead us to always fall back to the default registry url instead of
using the one from npmrc.

Fixes https://github.com/denoland/deno/issues/26139
Fixes https://github.com/denoland/deno/issues/26033
Fixes https://github.com/denoland/deno/issues/25924
Fixes https://github.com/denoland/deno/issues/25822
Fixes https://github.com/denoland/deno/issues/26152

---------

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2024-10-24 20:03:56 +02:00
Nathan Whitaker 7c3c13cecf fix(install): retry downloads of registry info / tarballs (#26278)
Fixes #26085.

Adds a basic retry utility with some defaults, starts off with a 100ms
wait, then 250ms, then 500ms

I've applied the retry in the http client, reusing an existing function,
so this also applies to retrying downloads of deno binaries in `upgrade`
and `compile`. I can make a separate function that doesn't retry so this
doesn't affect `upgrade` and `compile`, but it seemed desirable to have
retries there too, so I left it in.
2024-10-15 16:46:42 -07:00
Bartek IwańczukandDivy Srivastava 2bb013f9ba refactor: version module exports a single const struct (#25014)
This commit rewrites the internal `version` module that exported
various information about the current executable. Instead of exporting
several consts, we are now exporting a single const structure that 
contains all the necessary information.

This is the first step towards cleaning up how we use this information
and should allow us to use SUI to be able to patch this information
in already produced binary making it easier to cut new releases.

---------

Co-authored-by: Divy Srivastava <dj.srivastava23@gmail.com>
2024-08-15 23:47:16 +02:00
Yusuke Tanaka 4e4c96bf66 fix(ext/fetch): include URL and error details on fetch failures (#24910)
This commit improves error messages that `fetch` generates on failure.

Fixes #24835
2024-08-07 23:18:33 -07:00
Bartek Iwańczuk fe64cbd88b fix(upgrade): fallback to Content-Length header for progress bar (#24923)
If the "size hint" does not provide a value, fall back to using a
"Content-Length" header.
2024-08-07 09:16:27 +00:00
Bartek IwańczukandSean McArthur 7b33623b1d Reland "refactor(fetch): reimplement fetch with hyper instead of reqwest" (#24593)
Originally landed in
https://github.com/denoland/deno/commit/f6fd6619e708a515831f707438368d81b0c9aa56.
Reverted in https://github.com/denoland/deno/pull/24574.

This reland contains a fix that sends "Accept: */*" header for calls made
from "FileFetcher". Absence of this header made downloading source code
from JSR broken. This is tested by ensuring this header is present in the
test server that servers JSR packages.

---------

Co-authored-by: Sean McArthur <sean@seanmonstar.com>
2024-07-18 01:37:31 +02:00
Ryan Dahl e0cfc9da39 Revert "refactor(fetch): reimplement fetch with hyper instead of reqwest (#24237)" (#24574)
This reverts commit f6fd6619e7.

I'm seeing a difference between canary and 1.45.2. In
`deno-docs/reference_gen` I can't download dax when running `deno task
types`

```
~/src/deno-docs/reference_gen# deno upgrade --canary
Looking up latest canary version
Found latest version f6fd6619e7
Downloading https://dl.deno.land/canary/f6fd6619e708a515831f707438368d81b0c9aa56/deno-aarch64-apple-darwin.zip
Deno is upgrading to version f6fd6619e7
Archive:  /var/folders/9v/kys6gqns6kl8nksyn4l1f9v40000gn/T/.tmpb5lDnq/deno.zip
  inflating: deno
Upgraded successfully

~/src/deno-docs/reference_gen# deno -v
deno 1.45.2+f6fd661

~/src/deno-docs/reference_gen# rm -rf /Users/ry/Library/Caches/deno

~/src/deno-docs/reference_gen# deno task types
Task types deno task types:deno && deno task types:node
Task types:deno deno run --allow-read --allow-write --allow-run --allow-env --allow-sys deno-docs.ts
error: JSR package manifest for '@david/dax' failed to load. expected value at line 1 column 1
    at file:///Users/ry/src/deno-docs/reference_gen/deno-docs.ts:2:15

~/src/deno-docs/reference_gen# deno upgrade --version 1.45.2
Downloading https://github.com/denoland/deno/releases/download/v1.45.2/deno-aarch64-apple-darwin.zip
Deno is upgrading to version 1.45.2
Archive:  /var/folders/9v/kys6gqns6kl8nksyn4l1f9v40000gn/T/.tmp3R7uhF/deno.zip
  inflating: deno
Upgraded successfully

~/src/deno-docs/reference_gen# rm -rf /Users/ry/Library/Caches/deno

~/src/deno-docs/reference_gen# deno task types
Task types deno task types:deno && deno task types:node
Task types:deno deno run --allow-read --allow-write --allow-run --allow-env --allow-sys deno-docs.ts
Task types:node deno run --allow-read --allow-write=. --allow-env --allow-sys node-docs.ts
```
2024-07-13 21:08:23 +00:00
Sean McArthurandBartek Iwańczuk f6fd6619e7 refactor(fetch): reimplement fetch with hyper instead of reqwest (#24237)
This commit re-implements `ext/fetch` and all dependent crates
using `hyper` and `hyper-util`, instead of `reqwest`.

The reasoning is that we want to have greater control and access
to low level `hyper` APIs when implementing `fetch` API as well
as `node:http` module.

---------

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2024-07-13 00:51:37 +02:00
Bartek Iwańczuk 8db420d552 chore: upgrade to reqwest 0.12.4 and rustls 0.22 (#24388)
Reland of https://github.com/denoland/deno/pull/24056 that doesn't
suffer from the problem that was discovered in
https://github.com/denoland/deno/pull/24261.

It uses upgraded `hyper` and `hyper-util` that fixed the previous
problem in https://github.com/hyperium/hyper/pull/3691.
2024-07-02 02:09:47 +02:00
Bartek Iwańczuk b94707af7d Revert "chore: upgrade to reqwest 0.12.4 and rustls 0.22 (#24056)" (#24262)
This reverts commit fb31eaa9ca.

Reverting because users reported spurious errors when downloading
dependencies - https://github.com/denoland/deno/issues/24260.

Closes https://github.com/denoland/deno/issues/24260
2024-06-19 16:09:17 +02:00
fb31eaa9ca chore: upgrade to reqwest 0.12.4 and rustls 0.22 (#24056)
This commit updates Deno to use `reqwest` at 0.12.4
and `rustls` at 0.22. Other related crates were updated
as well to match versions accepted by `reqwest` and `rustls`.

Note: we are not using the latest available `rustls` yet,
but this upgrade was non-trivial already, so a bump to
0.23 for `rustls` will be done in a separate commit.

Closes #23370

---------

Signed-off-by: Ryan Dahl <ry@tinyclouds.org>
Signed-off-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Co-authored-by: Ryan Dahl <ry@tinyclouds.org>
Co-authored-by: Divy Srivastava <dj.srivastava23@gmail.com>
2024-06-13 22:41:26 +02:00
David Sherret 566adb7c0a fix(npm): use configured auth for tarball urls instead of scope auth (#24111)
Deno was using the scope auth for the tarball urls, which is not always
correct. We are going to do a release immediately for this issue.
2024-06-05 21:24:52 +00:00
David Sherret 3341c50b6a refactor: don't share reqwest::HttpClient across tokio runtimes (#24092)
This also fixes several issues where we weren't properly creating http
clients with the user's settings.
2024-06-03 21:17:08 +00:00
Bartek Iwańczuk 959739f609 FUTURE: initial support for .npmrc file (#23560)
This commit adds initial support for ".npmrc" files.

Currently we only discover ".npmrc" files next to "package.json" files
and discovering these files in user home dir is left for a follow up.

This pass supports "_authToken" and "_auth" configuration
for providing authentication.

LSP support has been left for a follow up PR.

Towards https://github.com/denoland/deno/issues/16105
2024-05-23 23:26:23 +02:00
David Sherret 7e72f3af61 chore: update copyright to 2024 (#21753) 2024-01-01 19:58:21 +00:00
585cf2de89 feat(unstable): tar up directory with deno.json (#21228)
Co-authored-by: David Sherret <dsherret@gmail.com>
Co-authored-by: Luca Casonato <lucacasonato@yahoo.com>
Co-authored-by: Luca Casonato <hello@lcas.dev>
2023-11-23 23:38:07 +00:00
Leo Kettmeir 3e03865d89 feat(unstable): add more options to Deno.createHttpClient (#17385) 2023-05-21 03:43:54 +02:00
David Sherret 913176313b perf: lazily create RootCertStore (#18938) 2023-05-01 16:42:05 -04:00
David Sherret fb021d7cef refactor: remove usages of map_or / map_or_else (#18212)
These methods are confusing because the arguments are backwards. I feel
like they should have never been added to `Option<T>` and that clippy
should suggest rewriting to
`map(...).unwrap_or(...)`/`map(...).unwrap_or_else(|| ...)`

https://github.com/rust-lang/rfcs/issues/1025
2023-03-15 17:46:36 -04:00
Kamil Ogórek 5778e1196e feat(install): follow redirects for urls with no path (#17449)
This change makes absolute urls, that contain no path like `deno install
https://my-cli.io` to follow redirects and extract the name from it.

It allows modifies `test_util` server listener on port `4550`
(`REDIRECT_ABSOLUTE_PORT`) to allow for specifying `redirect_to` query
param, that fill use that value for it's next redirect.

Fixes https://github.com/denoland/deno/issues/17409
2023-02-10 10:11:11 -05:00
David SherretandBartek Iwańczuk f5840bdcd3 chore: upgrade to Rust 1.67 (#17548)
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2023-01-27 10:43:16 -05:00
Yiyu LinandDivy Srivastava fd85f840cd refactor: clean up unwrap and clone (#17282)
Co-authored-by: Divy Srivastava <dj.srivastava23@gmail.com>
2023-01-15 09:36:46 +05:30
David Sherret 10e4b2e140 chore: update copyright year to 2023 (#17247)
Yearly tradition of creating extra noise in git.
2023-01-02 21:00:42 +00:00
David Sherret 2ff27a1f93 fix: hide progress bars when showing permission prompt (#17130)
Also adds download bytes progress when downloading remote specifiers.

Closes #16860
2022-12-19 14:31:19 -05:00
David Sherret 4a64ca8501 chore: fix recent regression with deno upgrade not handling redirects (#17045) 2022-12-14 08:47:18 -05:00
Bartek IwańczukandDavid Sherret 8c026dab92 feat: improve download progress bar (#16984)
Co-authored-by: David Sherret <dsherret@gmail.com>
2022-12-12 20:52:10 -05:00
David Sherret 653aebfa1a fix: respect the --quiet flag in more cases (#16998) 2022-12-09 10:54:24 -05:00
David Sherret 763d492ed6 fix(npm): use an http client with connection pool (#16705)
Should make downloading npm packages faster and more reliable.
2022-11-18 17:28:14 -05:00
David Sherret 1464b756a4 refactor: move out test files from root testdata directory into sub directories (#15949) 2022-09-19 10:32:21 -04:00
Ben Noordhuis b1b418b81a chore: fix clippy warnings (#15944)
Stop allowing clippy::derive-partial-eq-without-eq and fix warnings
about deriving PartialEq without also deriving Eq.

In one case I removed the PartialEq because it a) wasn't necessary,
and b) sketchy because it was comparing floating point numbers.

IMO, that's a good argument for enforcing the lint rule, because it
would most likely have been caught during review if it had been enabled.
2022-09-19 10:25:03 +02:00
Mathias Lafeldt 3f0dcd3b80 docs: turn bare URLs into clickable links (#15347) 2022-07-30 12:20:29 +02:00
David Sherret 53dac7451b chore: remove all pub(crate)s from the cli crate (#14083) 2022-03-23 09:54:22 -04:00