Skip to content

fix(bot): use crypto.randomInt for giveaway winners, suppress ReDoS false positive - #811

Merged
LucasSantana-Dev merged 1 commit into
mainfrom
fix/sonar-giveaway-crypto
May 6, 2026
Merged

LucasSantana-Dev merged 1 commit into
mainfrom
fix/sonar-giveaway-crypto

Conversation

@LucasSantana-Dev

Copy link
Copy Markdown
Owner

Summary

  • Replace Math.floor(Math.random() * entries.length) with crypto.randomInt(entries.length) (Node.js built-in CSPRNG) for giveaway winner selection — fixes SonarCloud S2245 (Weak Cryptography hotspot)
  • Add // NOSONAR: S5852 comment on /(\d+)([hmd])/g regex — \d+ and [hmd] are non-overlapping character classes with no catastrophic backtracking path (false positive)

Why

Three SonarCloud security hotspots in giveaway.ts are causing the SonarCloud Code Analysis check to fail on main after PR #805 merged. This PR resolves all three.

Test plan

  • CI passes (lint, type-check, build, tests)
  • SonarCloud re-scans and Quality Gate passes
  • SonarCloud Code Analysis check turns green on main

…alse positive

Replace Math.random() with crypto.randomInt() for CSPRNG-backed winner
selection. Suppress S5852 on non-backtracking regex /(\d+)([hmd])/g.
@vercel

vercel Bot commented May 6, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lucky Ready Ready Preview, Comment May 6, 2026 0:19am

Request Review

@coderabbitai

coderabbitai Bot commented May 6, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@LucasSantana-Dev has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 43 minutes and 54 seconds before requesting another review.

To continue reviewing without waiting, purchase usage credits in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7723b402-9076-48b5-be63-201a5c2e3c31

📥 Commits

Reviewing files that changed from the base of the PR and between 7af920b and f7789e8.

📒 Files selected for processing (1)
  • packages/bot/src/functions/general/commands/giveaway.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/sonar-giveaway-crypto

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud

sonarqubecloud Bot commented May 6, 2026

Copy link
Copy Markdown

@LucasSantana-Dev
LucasSantana-Dev merged commit 024013b into main May 6, 2026
12 checks passed
LucasSantana-Dev added a commit that referenced this pull request May 13, 2026
…alse positive (#811)

Replace Math.random() with crypto.randomInt() for CSPRNG-backed winner
selection. Suppress S5852 on non-backtracking regex /(\d+)([hmd])/g.
@LucasSantana-Dev
LucasSantana-Dev deleted the fix/sonar-giveaway-crypto branch May 14, 2026 02:02

This branch was successfully deployed

1 active deployment
Preview — f7789e8e Deployed May 6, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant