Skip to content

Prevent infinite redirect for doc-router /doc[^/] #751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 23, 2025

Conversation

Noratrieb
Copy link
Member

Previously, it would just put the slice in the Location with no regards
for what was in there. If there was no slash after the /doc, it would
issue a relative redirect, which was still under /doc, causing an
infinite redirect.

  • /docs/std -> s/std
  • /docs/s/std -> s/s/std
  • /docs/s/s/s/std -> ...

We prevent this behavior here by only applying the /doc redirect if
there is a slash directly after it, causing the default /stable rewrite
fallback to be applied to everything else, which will in practice lead
to nice 404 page.

This should not break anything as all such queries currently run into
these loops, including plain /doc.

Making a change to this core part of infrastructure that I can't reasonably test locally scared me, so I just wrote a bunch of unit tests for the thing.

@Noratrieb
Copy link
Member Author

I discovered this because someone else found this and posted about it, seemingly because they made a typo and forgot the URLs or something like that.

@marcoieni
Copy link
Member

thanks for this. The change itself looks good. Regarding the tests, can you document how to run them?

@Noratrieb
Copy link
Member Author

There is a comment at the top of the tests that mentions it, just node --test test.mjs

@Noratrieb
Copy link
Member Author

wait what that comment got lost, I'll add it

@Noratrieb
Copy link
Member Author

It looks like my regression test for the issue also got lost, I'll need to redo that

@marcoieni marcoieni marked this pull request as draft July 21, 2025 13:29
@marcoieni
Copy link
Member

I converted the PR to draft so that it's clear that it's not ready to be reviewed yet 👍

@Noratrieb Noratrieb force-pushed the fix-infinite-doc-loop branch from d7ce21a to f4e93a0 Compare July 21, 2025 17:40
@Noratrieb
Copy link
Member Author

Ah no, I did make a regression test, just not as part of the table tests. I squashed the comment fix I made earlier into the commit and it should be ready now.

@Noratrieb Noratrieb marked this pull request as ready for review July 21, 2025 17:40
@marcoieni
Copy link
Member

also it would be great if you could run the test in CI.

@Noratrieb Noratrieb force-pushed the fix-infinite-doc-loop branch from f4e93a0 to db10ba7 Compare July 22, 2025 16:09
@Noratrieb
Copy link
Member Author

I updated the naming and added a new CI workflow based on the previous ones. It's hardly the greatest workflow but it just does the same as the existing ones.

...this test now fails though. it works for me locally. it looks like it redirects / to /stable. live https://doc.rust-lang.org/ seems to do the same, but the source code obviously redirects it to www.rust-lang.org??

@Noratrieb Noratrieb force-pushed the fix-infinite-doc-loop branch from 74ade05 to 2f50668 Compare July 22, 2025 16:17
@Noratrieb
Copy link
Member Author

Noratrieb commented Jul 22, 2025

oh, this was changed on master and my branch was outdated!

Previously, it would just put the slice in the Location with no regards
for what was in there. If there was no slash after the `/doc`, it would
issue a relative redirect, which was still under `/doc`, causing an
infinite redirect.

- /docs/std -> s/std
- /docs/s/std -> s/s/std
- /docs/s/s/s/std -> ...

We prevent this behavior here by only applying the `/doc` redirect if
there is a slash directly after it, causing the default /stable rewrite
fallback to be applied to everything else, which will in practice lead
to nice 404 page.

This should not break anything as all such queries currently run into
these loops, including plain `/doc`.
@Noratrieb Noratrieb force-pushed the fix-infinite-doc-loop branch from 2f50668 to 395acf0 Compare July 22, 2025 16:19
@marcoieni marcoieni merged commit 93a338d into rust-lang:master Jul 23, 2025
4 checks passed
@marcoieni
Copy link
Member

applied, thanks!

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.

2 participants