nitrojs / nitro

Next Generation Server Toolkit. Create web servers with everything you need and deploy them wherever you prefer.
https://nitro.build
MIT License
6.2k stars 511 forks source link

Improve error for invalid URLs #717

Open Dante-dan opened 1 year ago

Dante-dan commented 1 year ago

Environment

nitropack: 1.0.0 nuxt3: 1.0.0 node: node18

Reproduction

nuxt3

pnpm build
pnpm preview

Describe the bug

invalid url will cause 500 error, because new URL() . It shoud be catch exception and throw not match 404.

sample URl : http://localhost:3000/.%AE/WEB-INF/esp_ldap_context.property

https://github.com/unjs/nitro/blob/8e06f2e4a65c6de0d2f2f3a5ef156ae3821ed60a/src/runtime/static.ts#L18~L22


// runtime/static.ts
  let id = decodeURIComponent(
    withLeadingSlash(
      withoutTrailingSlash(parseURL(event.node.req.url).pathname)
    )
  );

// [nuxt] [request error] [unhandled] [500] URI malformed

Additional context

No response

Logs

No response

cjpearson commented 2 months ago

I believe this has possibly been resolved with https://github.com/unjs/nitro/pull/1459. By using decodePath from ufo instead of decodeURIComponent errors with invalid URIs will be caught and ignored.

If this is the expected behavior rather than throwing a 404, I think this can be closed.