-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
perf(kit): update env expansion regex to match nitro #30766
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
perf(kit): update env expansion regex to match nitro #30766
Conversation
|
@nuxt/kit
@nuxt/rspack-builder
nuxt
@nuxt/schema
@nuxt/vite-builder
@nuxt/webpack-builder
commit: |
CodSpeed Performance ReportMerging #30766 will not alter performanceComparing Summary
|
WalkthroughThe pull request introduces changes to the runtime configuration handling in the Nuxt project. Specifically, the modifications focus on the environment variable expansion mechanism in the The new regex pattern The changes aim to improve the robustness of runtime configuration handling by providing more precise environment variable parsing and comprehensive test coverage. ✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (2)
packages/kit/src/runtime-config.ts (1)
97-97
: Excellent security enhancement to prevent ReDoS attacks!The regex change from using a lazy quantifier (
.*?
) to a negated character class ([^{}]*
) is a robust solution that:
- Prevents catastrophic backtracking
- Ensures correct parsing of environment variables
- Maintains linear-time matching performance
Consider documenting this security enhancement in the codebase, particularly noting that nested environment variables are intentionally disallowed.
packages/kit/src/runtime-config.test.ts (1)
9-62
: Add security-focused test casesThe test suite thoroughly covers the functional aspects, but would benefit from additional test cases that verify the security enhancements:
Add these test cases to the
testCases
array:const testCases = [ + { + description: 'should safely handle nested braces attempts', + runtimeConfig: { + nested: '{{FOO{{BAR}}}}', + deep: '{{FOO}}{{BAR}}', + }, + envExpansion: true, + env: { + FOO: 'foo', + BAR: 'bar', + 'FOO{{BAR': 'nested', + }, + expected: { + nested: '{{FOO{{BAR}}}}', + deep: 'foobar', + }, + }, + { + description: 'should handle malicious input patterns', + runtimeConfig: { + evil: '{{' + 'a'.repeat(1000) + '}}', + }, + envExpansion: true, + env: {}, + expected: { + evil: '{{' + 'a'.repeat(1000) + '}}', + }, + }, // ... existing test cases ]
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/kit/src/runtime-config.test.ts
(1 hunks)packages/kit/src/runtime-config.ts
(1 hunks)
🔇 Additional comments (1)
packages/kit/src/runtime-config.test.ts (1)
64-76
: LGTM! Well-structured test suite.The test implementation using
it.each
is clean and maintainable. Good use ofafterEach
to clean up environment variables.
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.
thank you! ❤️
🔗 Linked issue
Resolves #30263
Appropriate PR for Nitro nitrojs/nitro#3037
📚 Description
The current Regex for env expansion feature is vulnerable according to Devina ReDos checker.

This Enhancement makes the Regex safe with keeping functionality.
