Skip to content

Infinite loop when middleware creates a 404 response #10735

@lilnasy

Description

@lilnasy

Astro Info

Astro                    v4.5.17
Node                     v20.11.1
System                   Windows (x64)
Package Manager          unknown
Output                   static
Adapter                  none
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

Quoting #8100 (comment)

...there is no way now to return any 404 in the middleware, it always ends up in an infinite loop, even if I create a static 404 page. I'm now forced to diverge from security best practices and return a 403 instead. This way there is no endless loop.

What's the expected result?

Server does NOT recursively call itself. Context: "Recursive rerouting" section of withastro/roadmap#681.

Link to Minimal Reproducible Example

return new Response(response.body, { ...response, status: 404 })
(skipped in #10084)
it.skip(
'dev server stays responsive',

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P5: urgentFix build-breaking bugs affecting most users, should be released ASAP (priority)feat: error pagesRelated to 404 and 500 handling (scope)feat: middlewareRelated to middleware (scope)regression

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions