Skip to content

Comments

Add static analysis rule to detect unsecure random number usage#605

Merged
ThisaruGuruge merged 2 commits intoballerina-platform:masterfrom
nureka-rodrigo:master
Sep 22, 2025
Merged

Add static analysis rule to detect unsecure random number usage#605
ThisaruGuruge merged 2 commits intoballerina-platform:masterfrom
nureka-rodrigo:master

Conversation

@nureka-rodrigo
Copy link
Contributor

Implemented a new static code analysis rule that checks for the usage of unsecure random number generation in the context of cryptographic functions. This includes identifying calls to random:createIntInRange() for initialization vectors in AES-GCM and AES-ECB functions. Additionally, updated related files and tests to support this new rule.

Purpose

Fixes: ballerina-platform/ballerina-library#8258

Examples

Checklist

  • Linked to an issue
  • Updated the changelog
  • Added tests
  • Updated the spec
  • Checked native-image compatibility

Implemented a new static code analysis rule that checks for the usage of unsecure random number generation in the context of cryptographic functions. This includes identifying calls to random:createIntInRange() for initialization vectors in AES-GCM and AES-ECB functions. Additionally, updated related files and tests to support this new rule.
@codecov
Copy link

codecov bot commented Sep 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.22%. Comparing base (e31899d) to head (7175c23).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##             master     #605   +/-   ##
=========================================
  Coverage     82.22%   82.22%           
  Complexity      239      239           
=========================================
  Files            29       29           
  Lines          1367     1367           
  Branches        190      190           
=========================================
  Hits           1124     1124           
  Misses          197      197           
  Partials         46       46           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Updated the file paths in rule<x>.json to use relative paths instead of absolute paths. This change improves portability and ensures that the rules can be used in different environments without modification.
@sonarqubecloud
Copy link

Copy link
Member

@ThisaruGuruge ThisaruGuruge left a comment

Choose a reason for hiding this comment

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

LGTM

@ThisaruGuruge ThisaruGuruge merged commit f394936 into ballerina-platform:master Sep 22, 2025
8 checks passed
TharmiganK pushed a commit that referenced this pull request Oct 21, 2025
* Add static analysis rule to detect unsecure random number usage

Implemented a new static code analysis rule that checks for the usage of unsecure random number generation in the context of cryptographic functions. This includes identifying calls to random:createIntInRange() for initialization vectors in AES-GCM and AES-ECB functions. Additionally, updated related files and tests to support this new rule.

* Refactor file paths in static analysis rules to be relative

Updated the file paths in rule<x>.json to use relative paths instead of absolute paths. This change improves portability and ensures that the rules can be used in different environments without modification.

(cherry picked from commit f394936)
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.

Implement static analysis rule "Secure random number generators should not output predictable values" in Crypto module

2 participants