fix(economy): prevent code injection via currency symbol/name#163
Open
Niruhqs wants to merge 1 commit into
Open
fix(economy): prevent code injection via currency symbol/name#163Niruhqs wants to merge 1 commit into
Niruhqs wants to merge 1 commit into
Conversation
The "Change Currency Symbol"/"Change Currency Name" modals in /economy dashboard only validated input length, then interpolated the raw value directly into src/config/bot.js's source code via string templates before writing it to disk. A value containing a double quote (e.g. `",a`, which passes the 1-3 character length check) breaks the generated JS syntax, and since bot.js is imported at process startup, this corrupts the bot's central config file and prevents it from starting on the next restart until manually repaired. Fix: - Serialize the symbol/name with JSON.stringify() instead of raw template interpolation, so quotes/backslashes are always properly escaped in the generated source. - Add an explicit character whitelist (isSafeCurrencyInput) that rejects quotes, backslashes, and backticks up front, giving users a clear validation error instead of relying solely on the escaping to hold. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The "Change Currency Symbol" / "Change Currency Name" modals in
/economy dashboardonly validate input length (1-3 / 1-20 chars), then interpolate the raw value directly intosrc/config/bot.js's source code via string templates before writing it to disk.A value containing a double quote — e.g.
",a(3 characters, passes the length check) — breaks the generated JS syntax. Sincebot.jsis imported at process startup, this corrupts the bot's central config file and the bot fails to start on the next restart/redeploy until someone manually fixes the file.Fix
JSON.stringify()instead of raw template interpolation, so quotes/backslashes are always properly escaped in the generated source (defense in depth).isSafeCurrencyInput) that rejects quotes, backslashes, and backticks up front, giving admins a clear validation error instead of relying solely on escaping.Test plan
node --checkon the modified file — syntax valid",a) is now rejected by validation, and that even bypassing validation,JSON.stringify()prevents the generatedbot.jsfrom breaking (verifiednew Function()still parses the patched output)$,€,¥,coins,gem) are unaffected and still produce valid output🤖 Generated with Claude Code