Skip to content

fix(economy): prevent code injection via currency symbol/name#163

Open
Niruhqs wants to merge 1 commit into
codebymitch:mainfrom
Niruhqs:fix/currency-symbol-code-injection
Open

fix(economy): prevent code injection via currency symbol/name#163
Niruhqs wants to merge 1 commit into
codebymitch:mainfrom
Niruhqs:fix/currency-symbol-code-injection

Conversation

@Niruhqs

@Niruhqs Niruhqs commented Jul 23, 2026

Copy link
Copy Markdown

Summary

The "Change Currency Symbol" / "Change Currency Name" modals in /economy dashboard only validate input length (1-3 / 1-20 chars), then interpolate 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 (3 characters, passes the length check) — breaks the generated JS syntax. Since bot.js is 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

  • Serialize the symbol/name with JSON.stringify() instead of raw template interpolation, so quotes/backslashes are always properly escaped in the generated source (defense in depth).
  • Add an explicit character whitelist (isSafeCurrencyInput) that rejects quotes, backslashes, and backticks up front, giving admins a clear validation error instead of relying solely on escaping.

Test plan

  • node --check on the modified file — syntax valid
  • Standalone repro script confirming the exact exploit payload (",a) is now rejected by validation, and that even bypassing validation, JSON.stringify() prevents the generated bot.js from breaking (verified new Function() still parses the patched output)
  • Confirmed normal inputs ($, , ¥, coins, gem) are unaffected and still produce valid output

🤖 Generated with Claude Code

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>
@Niruhqs
Niruhqs requested a review from codebymitch as a code owner July 23, 2026 21:02
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.

1 participant