Use content-type fast parse - #472
Conversation
|
@mcollina Is this something that would be useful? The perf benchmarks in the library itself show a substantial improvement: And when you skip parameters altogether it's much faster. I've also been working to switch over some other packages in jshttp to use |
|
Maybe a more representative version using 10x bump, and validation of it matching a valid MIME isn't useful because you already have the allowlist as |
mcollina
left a comment
There was a problem hiding this comment.
I think the behavior change can cause possible security issues, and I would hold for now.
|
@mcollina If you want the type to be validated like the existing code path, and we'd still have improved performance due to the skipping of parameters and improvements to the parser. Would that be suitable? Edit: It doesn't do that by default because an audit of usages showed they mostly validated twice (e.g. by using something like |
|
Just saw fastify/fast-content-type-parse#81, I can close this out. |
|
For context, I've been trying to find upstream dependents that forked from jshttp/pillarjs packages and find ways to merge them back inline for ecosystem performance and security. I'd love to try and continue that with Fastify if you want to land changes like the above into |
|
The problem is that much of the logic in Fastify assumes the media types are validated. We have been receiving a constant stream of media-type-related vulnerabilities at this point. We could theoretically move back to content-type, but out of caution we should that across the whole org and part of the next major. |
Preamble: I know
fast-content-type-parseis intended to be a Fastify fork ofcontent-typeand is likely forked for historical reasons, but I recently released acontent-type@2and the changes seemed relevant to this package. Mostly because there's no need to parse parameters at all.Changes
fast-content-type-parseto usecontent-typewithparameters: falseto extract thecontent-typeparameter.However, the parser in
content-typeno longer validates during parse (designed to be lenient/fast) so there is a minor behavior change with invalid MIME types. If you sent something likefooit would currently throw during.parsebut in this change it'll forwardfooalong.Checklist
npm run test && npm run benchmark --if-presentand the Code of conduct