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

fix(core): do not create empty header entries in routeRules #539

Merged
merged 2 commits into from
Nov 4, 2024

Conversation

vejja
Copy link
Collaborator

@vejja vejja commented Oct 24, 2024

Types of changes

  • Bug fix (a non-breaking change which fixes an issue)
  • New feature (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

Fixes #538

The getHeadersApplicableToAllRessources was previously returning an empty object {} when no eligible entry was found, which resulted in an empty headers: {} entry in the routeRules registry.

This could trigger a deployment failure in some Nitro presets (e.g. Vercel).

This PR ensures that no headers entry is created in the corresponding routeRule in that case, fixing the bug described in #538.

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes (if not applicable, please state why)

@vejja vejja self-assigned this Oct 24, 2024
Copy link

vercel bot commented Oct 24, 2024

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

Name Status Preview Comments Updated (UTC)
nuxt-security ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 25, 2024 9:44am

@vejja vejja changed the base branch from main to chore/2.1.0 October 24, 2024 15:32
@vejja vejja requested a review from Baroshem October 24, 2024 15:36
@maxdzin
Copy link

maxdzin commented Oct 24, 2024

@vejja I tried to make a build of this branch locally (dev:build) and it failed with this error:

Error: ENOENT: no such file or directory, open './.nuxt/server.headers'

Am I missing something?

@vejja
Copy link
Collaborator Author

vejja commented Oct 24, 2024

@vejja I tried to make a build of this branch locally (dev:build) and it failed with this error:

Error: ENOENT: no such file or directory, open './.nuxt/server.headers'

Am I missing something?

I think you are building the playground and hitting the prerenderedHeaders hook. Strange thing that it couldn't write to ./.nuxt/server.headers...
Anyway, just do prepack instead to build the module distributable

@maxdzin
Copy link

maxdzin commented Oct 24, 2024

@vejja Yes, I did prepack as well and it fails with this error:

ERROR  failed to resolve "extends":"./.nuxt/tsconfig.json" in /.../nuxt-security/tsconfig.json

It could be something due to the environment.

@vejja
Copy link
Collaborator Author

vejja commented Oct 24, 2024

@maxdzin here is the build for the local tests. Let me know !
dist.zip

@maxdzin
Copy link

maxdzin commented Oct 24, 2024

@vejja Nice! Thank you
I tried that and confirm that it working well. The headers were passed as expected.

Copy link
Owner

@Baroshem Baroshem left a comment

Choose a reason for hiding this comment

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

One small suggestion, apart from that ready to be merged :)

src/utils/headers.ts Outdated Show resolved Hide resolved
Co-authored-by: Jakub Andrzejewski <[email protected]>
@Baroshem Baroshem merged commit 71a4f0d into chore/2.1.0 Nov 4, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Vercel deployment bug caused by per-route security config
3 participants