-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Feat: Allow skipping complexity check in Harden Plugin #3340
Feat: Allow skipping complexity check in Harden Plugin #3340
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@michaelbromley Not sure why tests are failing, HardenPlugin doesn't seem to be included in any e2e tests. Someone else broke the minor branch maybe? |
packages/harden-plugin/src/middleware/query-complexity-plugin.ts
Outdated
Show resolved
Hide resolved
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.
Great addition. I made a suggestion on the naming/documentation.
@@ -79,4 +80,16 @@ export interface HardenPluginOptions { | |||
* @default 'prod' | |||
*/ | |||
apiMode?: 'dev' | 'prod'; | |||
/** | |||
* @description | |||
* Allows you to skip the complexity check for certain requests. |
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 think we should note that the ctx
is not the RequestContext
object here, since I think a lot of people will make that assumption based on typical Vendure patterns.
Maybe even rename it to context
to make it even more explicit.
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.
@michaelbromley Valid concern. Fixed :-)
|
Thanks! |
Description
We are using the Harden Plugin, but would like to be able to skip the complexity check for storefront SSR builds.
This PR introduces an optional
skip
function, inspired by express-rate-limit, that allows the consumer to skip certain requests.Screenshots below we're tested with the following config:
This skips the complexity check when the header
x-skip-complexity
is present. In production use, you would check for a token or something.Breaking changes
No
Screenshots
Complex query without header
![image](https://private-user-images.githubusercontent.com/6604455/408040702-39672baf-af3a-445f-afee-2d3678044142.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkzNjQ3NTUsIm5iZiI6MTczOTM2NDQ1NSwicGF0aCI6Ii82NjA0NDU1LzQwODA0MDcwMi0zOTY3MmJhZi1hZjNhLTQ0NWYtYWZlZS0yZDM2NzgwNDQxNDIucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxMiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTJUMTI0NzM1WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NTJmMjMzNGZlZDFiMTAxNDMwNjVmZGVlNGI2MzE0OTljOTRmM2M0NzlhNjUxNGFmYWRjZDc2MzY0MDY0M2Q0MyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.1KSiQVujuHgFUnFE-gPZI7mB1p7f7RJUeZKtWlbJw90)
The same complex query with custom header
![image](https://private-user-images.githubusercontent.com/6604455/408040877-6fdf20b6-2934-4fe0-bbed-9224a8076548.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkzNjQ3NTUsIm5iZiI6MTczOTM2NDQ1NSwicGF0aCI6Ii82NjA0NDU1LzQwODA0MDg3Ny02ZmRmMjBiNi0yOTM0LTRmZTAtYmJlZC05MjI0YTgwNzY1NDgucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxMiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTJUMTI0NzM1WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9M2YyYmVmZGFlMDcyYzAxYTJhMzFmYTFhOTNlODgyNGFkY2U4MzVlOWNiMDUyMTU0MDg5ZGM3NTI1MDM4ZWM3NSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.gmKs11ACcQV2668pjTtefDzAa2uI9JTf5i0L-cT-AQA)
And, another test without a
![image](https://private-user-images.githubusercontent.com/6604455/408041076-ff82205a-bdd3-466d-9a7b-a82956f213f3.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkzNjQ3NTUsIm5iZiI6MTczOTM2NDQ1NSwicGF0aCI6Ii82NjA0NDU1LzQwODA0MTA3Ni1mZjgyMjA1YS1iZGQzLTQ2NmQtOWE3Yi1hODI5NTZmMjEzZjMucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxMiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTJUMTI0NzM1WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YTE5YjUwOTgzZjliYjU0MmFiMDU5OTdlYzVkOWVkMGY3ZDFhMzRlZjc3MWNkMWUxNjIxMmY2OTRlMWFkZWEwYSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.O3uM8YepStty_8PuNmYOQlHyzDtZjYlTVP2nh2sMSvY)
skip
function specified.Checklist
📌 Always:
👍 Most of the time: