Skip to content

assets.fetch: every redirect held to the policy, a repeated id ignored before it is refused - #284

Open
kvnloo wants to merge 1 commit into
meshy-dev:mainfrom
kvnloo:swarm/t1-assets-redirect
Open

kvnloo wants to merge 1 commit into
meshy-dev:mainfrom
kvnloo:swarm/t1-assets-redirect

Conversation

@kvnloo

@kvnloo kvnloo commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Two fixes to renderer/src/assets.rs (#283).

Redirects skipped the policy. AssetFetcher::new built its agent with max_redirects(5), and ureq follows those itself. It checks the scheme on a hop only when https_only is set, which it wasn't (ureq 3.5.2 run.rs:155). So the policy only saw the first address. Under the default https_only(), an https:// address that answers 302 Location: http://… was downloaded over plain http. A custom with_policy check was skipped on every hop after the first in the same way.

The fetcher now follows redirects itself, one hop at a time. The agent is built with max_redirects(0). Each Location is resolved against the address that answered it (absolute, //host, /path, or a path relative to it) and checked by the policy. More than 5 redirects is refused. The with_agent doc now asks for max_redirects(0) for the same reason. Redirects an app's own agent follows are still that agent's to check.

A repeated id that gets refused broke the first request's tracking. Take an assets.fetch whose id is already under way but which is refused at once (no url, an address the policy refuses, a path outside cache/). It sent its refusal under that id, and poll took it as the running download's answer. The running entry was dropped, so a later assets.cancel no longer reached it and one more queued download started. The game also got two answers for the id. The duplicate-id check now runs before the refusals, so the second request is ignored, as a valid duplicate already was.

Tests (cargo test --lib assets: 5 pass):

  • redirects_resolve_from_the_answering_address: how a Location resolves.
  • redirects_are_held_to_the_policy: runs against a local server. A redirect relative to the path and one from the root are followed. A redirect to an address the policy refuses and a redirect loop are both refused, with nothing written. A repeated id with a file:// url is ignored, and the first request is answered once. With the per-hop check removed, this test fails.

RUNTIME.md "Assets" is updated to match.

Not changed, but worth noting: two requests with different ids for the same path that run at once both write <path>.part. They share the temp file, so a body from one url can end up recorded under the other's sha256. Fixing that needs a per-path lock or a unique part name. I left it to you to decide whether that's worth doing.

🤖 Generated with Claude Code

…d before it is refused

The default agent followed up to 5 redirects itself, so the policy saw only the first address: under the default
https_only, an https:// address answering 302 to http:// was downloaded over http. The fetcher now follows redirects
itself (agent max_redirects(0)), one at a time, each Location resolved against the address that answered and checked
by the policy; more than 5 is refused. with_agent's doc asks for max_redirects(0) for the same reason.

A request under an id already under way that would be refused at once (no url, a refused address, a path out of
cache/) answered with that id, and poll took the answer for the running download's: its entry dropped (cancel no
longer reached it, one more slot started) and the game got two answers. The id check now comes first.

Tests: redirect resolution (absolute, //, /, beside, query); a local server's redirects beside the path and from the
root followed, one to a refused address and a loop refused with nothing written, a repeated id with a file:// url
ignored. The new test fails with the per-hop check removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant