Skip to content

404 with not encoded URI path parameter #1884

@Eomm

Description

@Eomm

🐛 Bug Report

If I send a wrong path parameter without appling an encodedURI I get a 404 response and a warn:

{"level":30,"time":1570179820901,"pid":21956,"hostname":"MSPIGOLON5591","reqId":3,"req":{"method":"GET","url":"/%25what%","remotePort":53476},"msg":"incoming request","v":1}
{"level":40,"time":1570179820902,"pid":21956,"hostname":"MSPIGOLON5591","reqId":3,"msg":"the default handler for 404 did not catch this, this is likely a fastify bug, please report it","v":1}
{"level":40,"time":1570179820902,"pid":21956,"hostname":"MSPIGOLON5591","reqId":3,"msg":"ÔööÔöÇÔöÇ / (ACL|BIND|CHECKOUT|CONNECT|COPY|DELETE|GET|HEAD|LINK|LOCK|M-SEARCH|MERGE|MKACTIVITY|MKCALENDAR|MKCOL|MOVE|NOTIFY|OPTIONS|PATCH|POST|PROPFIND|PROPPATCH|PURGE|PUT|REBIND|REPORT|SEARCH|SOURCE|SUBSCRIBE|TRACE|UNBIND|UNLINK|UNLOCK|UNSUBSCRIBE)\n    ÔööÔöÇÔöÇ * (ACL|BIND|CHECKOUT|CONNECT|COPY|DELETE|GET|HEAD|LINK|LOCK|M-SEARCH|MERGE|MKACTIVITY|MKCALENDAR|MKCOL|MOVE|NOTIFY|OPTIONS|PATCH|POST|PROPFIND|PROPPATCH|PURGE|PUT|REBIND|REPORT|SEARCH|SOURCE|SUBSCRIBE|TRACE|UNBIND|UNLINK|UNLOCK|UNSUBSCRIBE)\n","v":1}

To Reproduce

const fastify = require('fastify')({ logger: true })
fastify.get('/:strangeId', (req, reply) => {
  reply.send({ strangeId: req.params.strangeId })
})
fastify.listen(3000)
curl -X GET   http://localhost:3000/%what%   -H 'Accept: */*'   -H 'Accept-Encoding: gzip, deflate'   
-H 'Connection: keep-alive'   -H 'Host: localhost:3000'   -H 'User-Agent: PostmanRuntime/7.17.1'

All work with an encoded path param:

curl -X GET   http://localhost:3000/%25what%25   -H 'Accept: */*'   -H 'Accept-Encoding: gzip, deflate'   
-H 'Connection: keep-alive'   -H 'Host: localhost:3000'   -H 'User-Agent: PostmanRuntime/7.17.1'

Expected behaviour

I wouldn't expect a 404.

With a plain server, the URL is:

{ req: '/%what%' }
{ req: '/%25what%25' }
const http = require('http')
const server = http.createServer(function manageResponse (req, res) {
  console.log({ req: req.url })
  res.end('hello')
})
server.listen(3000)

Your Environment

  • node version: 12
  • fastify version: 2.9
  • os: Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugConfirmed bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions