Skip to content
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

Conversation

martijnvdbrug
Copy link
Collaborator

@martijnvdbrug martijnvdbrug commented Jan 30, 2025

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:

  skip: (ctx) => {
    return !!ctx.request.http?.headers.get("x-skip-complexity")
  }

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

The same complex query with custom header
image

And, another test without a skip function specified.
image

Checklist

📌 Always:

  • I have set a clear title
  • My PR is small and contains a single feature
  • I have checked my own PR

👍 Most of the time:

  • I have added or updated test cases
  • I have updated the README if needed

Copy link

vercel bot commented Jan 30, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview Feb 11, 2025 1:26pm

@martijnvdbrug
Copy link
Collaborator Author

@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?

Copy link
Member

@michaelbromley michaelbromley left a 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.
Copy link
Member

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@michaelbromley Valid concern. Fixed :-)

@michaelbromley michaelbromley merged commit 0bef00b into vendure-ecommerce:minor Feb 11, 2025
31 checks passed
@michaelbromley
Copy link
Member

Thanks!

@github-actions github-actions bot locked and limited conversation to collaborators Feb 11, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants