-
-
Notifications
You must be signed in to change notification settings - Fork 98
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
opt to validate incoming data before proxy is executed #312
opt to validate incoming data before proxy is executed #312
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
index.js
Outdated
if (opts.preValidation === undefined && opts.proxyPayloads !== false) { | ||
fastify.addContentTypeParser('application/json', bodyParser) | ||
fastify.addContentTypeParser('*', bodyParser) | ||
} | ||
|
||
if (opts.preValidation) { | ||
fastify.addHook('preValidation', opts.preValidation) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we not proxy Payloads if preValidation is set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
req.body
is not parsed and comes as aIncomingMessage
stream if:
fastify.addContentTypeParser('application/json', bodyParser)
fastify.addContentTypeParser('*', bodyParser)
condition is executed, as described here: #86 (comment)
actually, the payload is passed in this case, see:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm -1 to add this option.
This can be achieved with the following:
app.register(async function (app) {
app.addHook('preValidation', ...)
app.register(httpProxy, {
proxyPayloads: false
})
})
Could you add that to the documentation instead?
I did now, I still think what you want to achieve can be done with the approach I described in #312 (review). Note that I set
I assembled that a long time ago, I might have been mistaken in adding this.
The snippet in #312 (review) adds it only to the proxied routes. |
I still find adding But it's indeed up to the team. Feel free to close the PR if you decide that it's not the preferable way. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Can you fix the failing tests? |
I wish! I can see that tests are failing for node 18 on ubuntu agent and are hardly related to the change:
But the same is happening for me locally on the could you please advise how it could be fixed, @mcollina ? |
For whatever reason this is actually breaking websocket support as this test PR is passing: #315 |
This PR didn't trigger unit tests though, there are only two checks. I'm positive main branch have the issue |
Verified, it's a problem. |
please rebase, I've fixed it |
Listen only to IPv4 network for websockets tests (fastify#316)
Co-authored-by: Uzlopak <[email protected]>
4f2e199
to
8ab3717
Compare
Nice! Respect Sir. Rebase is done |
@@ -31,6 +31,7 @@ declare namespace fastifyHttpProxy { | |||
proxyPayloads?: boolean; | |||
preHandler?: preHandlerHookHandler; | |||
beforeHandler?: preHandlerHookHandler; | |||
preValidation?: preValidationHookHandler; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a test for this type in https://github.com/fastify/fastify-http-proxy/blob/master/types/index.test-d.ts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed here: 0c0e505
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Excellent work! I can't wait to use it. Mind pushing a new release? Thanks! |
Hi. Can we get a release for this? I saw |
Released as 9.3.0 👍🏼 |
[](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [@fastify/http-proxy](https://togithub.com/fastify/fastify-http-proxy) | [`9.2.1` -> `9.3.0`](https://renovatebot.com/diffs/npm/@fastify%2fhttp-proxy/9.2.1/9.3.0) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>fastify/fastify-http-proxy (@​fastify/http-proxy)</summary> ### [`v9.3.0`](https://togithub.com/fastify/fastify-http-proxy/releases/tag/v9.3.0) [Compare Source](https://togithub.com/fastify/fastify-http-proxy/compare/v9.2.1...v9.3.0) #### What's Changed - Listen only to IPv4 network for websockets tests by [@​mcollina](https://togithub.com/mcollina) in [https://github.com/fastify/fastify-http-proxy/pull/316](https://togithub.com/fastify/fastify-http-proxy/pull/316) - opt to validate incoming data before proxy is executed by [@​kovalenp](https://togithub.com/kovalenp) in [https://github.com/fastify/fastify-http-proxy/pull/312](https://togithub.com/fastify/fastify-http-proxy/pull/312) - build(deps-dev): bump [@​typescript-eslint/eslint-plugin](https://togithub.com/typescript-eslint/eslint-plugin) from 5.62.0 to 6.2.1 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/fastify/fastify-http-proxy/pull/318](https://togithub.com/fastify/fastify-http-proxy/pull/318) - build(deps-dev): bump tsd from 0.28.1 to 0.29.0 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/fastify/fastify-http-proxy/pull/320](https://togithub.com/fastify/fastify-http-proxy/pull/320) - perf: use `node:` prefix to bypass require.cache call for builtins by [@​Fdawgs](https://togithub.com/Fdawgs) in [https://github.com/fastify/fastify-http-proxy/pull/321](https://togithub.com/fastify/fastify-http-proxy/pull/321) - build(deps-dev): bump express-http-proxy from 1.6.3 to 2.0.0 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/fastify/fastify-http-proxy/pull/323](https://togithub.com/fastify/fastify-http-proxy/pull/323) - test(websocket): optimize split param by [@​Fdawgs](https://togithub.com/Fdawgs) in [https://github.com/fastify/fastify-http-proxy/pull/326](https://togithub.com/fastify/fastify-http-proxy/pull/326) - keep query params on proxy by [@​dancastillo](https://togithub.com/dancastillo) in [https://github.com/fastify/fastify-http-proxy/pull/325](https://togithub.com/fastify/fastify-http-proxy/pull/325) - chore(package): explicitly declare js module type by [@​Fdawgs](https://togithub.com/Fdawgs) in [https://github.com/fastify/fastify-http-proxy/pull/327](https://togithub.com/fastify/fastify-http-proxy/pull/327) #### New Contributors - [@​kovalenp](https://togithub.com/kovalenp) made their first contribution in [https://github.com/fastify/fastify-http-proxy/pull/312](https://togithub.com/fastify/fastify-http-proxy/pull/312) - [@​dancastillo](https://togithub.com/dancastillo) made their first contribution in [https://github.com/fastify/fastify-http-proxy/pull/325](https://togithub.com/fastify/fastify-http-proxy/pull/325) **Full Changelog**: fastify/fastify-http-proxy@v9.2.1...v9.3.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/redwoodjs/redwood). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40Ni4wIiwidXBkYXRlZEluVmVyIjoiMzcuNDYuMCIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
[](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [@fastify/http-proxy](https://togithub.com/fastify/fastify-http-proxy) | [`9.2.1` -> `9.3.0`](https://renovatebot.com/diffs/npm/@fastify%2fhttp-proxy/9.2.1/9.3.0) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>fastify/fastify-http-proxy (@​fastify/http-proxy)</summary> ### [`v9.3.0`](https://togithub.com/fastify/fastify-http-proxy/releases/tag/v9.3.0) [Compare Source](https://togithub.com/fastify/fastify-http-proxy/compare/v9.2.1...v9.3.0) #### What's Changed - Listen only to IPv4 network for websockets tests by [@​mcollina](https://togithub.com/mcollina) in [https://github.com/fastify/fastify-http-proxy/pull/316](https://togithub.com/fastify/fastify-http-proxy/pull/316) - opt to validate incoming data before proxy is executed by [@​kovalenp](https://togithub.com/kovalenp) in [https://github.com/fastify/fastify-http-proxy/pull/312](https://togithub.com/fastify/fastify-http-proxy/pull/312) - build(deps-dev): bump [@​typescript-eslint/eslint-plugin](https://togithub.com/typescript-eslint/eslint-plugin) from 5.62.0 to 6.2.1 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/fastify/fastify-http-proxy/pull/318](https://togithub.com/fastify/fastify-http-proxy/pull/318) - build(deps-dev): bump tsd from 0.28.1 to 0.29.0 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/fastify/fastify-http-proxy/pull/320](https://togithub.com/fastify/fastify-http-proxy/pull/320) - perf: use `node:` prefix to bypass require.cache call for builtins by [@​Fdawgs](https://togithub.com/Fdawgs) in [https://github.com/fastify/fastify-http-proxy/pull/321](https://togithub.com/fastify/fastify-http-proxy/pull/321) - build(deps-dev): bump express-http-proxy from 1.6.3 to 2.0.0 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/fastify/fastify-http-proxy/pull/323](https://togithub.com/fastify/fastify-http-proxy/pull/323) - test(websocket): optimize split param by [@​Fdawgs](https://togithub.com/Fdawgs) in [https://github.com/fastify/fastify-http-proxy/pull/326](https://togithub.com/fastify/fastify-http-proxy/pull/326) - keep query params on proxy by [@​dancastillo](https://togithub.com/dancastillo) in [https://github.com/fastify/fastify-http-proxy/pull/325](https://togithub.com/fastify/fastify-http-proxy/pull/325) - chore(package): explicitly declare js module type by [@​Fdawgs](https://togithub.com/Fdawgs) in [https://github.com/fastify/fastify-http-proxy/pull/327](https://togithub.com/fastify/fastify-http-proxy/pull/327) #### New Contributors - [@​kovalenp](https://togithub.com/kovalenp) made their first contribution in [https://github.com/fastify/fastify-http-proxy/pull/312](https://togithub.com/fastify/fastify-http-proxy/pull/312) - [@​dancastillo](https://togithub.com/dancastillo) made their first contribution in [https://github.com/fastify/fastify-http-proxy/pull/325](https://togithub.com/fastify/fastify-http-proxy/pull/325) **Full Changelog**: fastify/fastify-http-proxy@v9.2.1...v9.3.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/redwoodjs/redwood). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40Ni4wIiwidXBkYXRlZEluVmVyIjoiMzcuNDYuMCIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Provide an option to preValidate incoming data (check out: #311)
Checklist
npm run test
andnpm run benchmark
and the Code of conduct