Implement static code analysis rule to analyse weak encryption algorithm usage#602
Implement static code analysis rule to analyse weak encryption algorithm usage#602daneshk merged 2 commits intoballerina-platform:masterfrom nureka-rodrigo:master
Conversation
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #602 +/- ##
=========================================
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. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull Request Overview
This PR implements a static code analysis rule to flag the use of weak encryption algorithms (AES ECB/CBC) in Ballerina code. It updates configuration files, defines a new rule in the rules configuration, refactors the crypto rule into an enum, and adds a corresponding analyzer and tests to enforce the rule.
Reviewed Changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| gradle.properties | Bumps the version for the balScan dependency. |
| compiler-plugin/src/main/resources/rules.json | Introduces a new vulnerability rule for weak encryption algorithm usage. |
| compiler-plugin/src/main/java/io/ballerina/stdlib/crypto/compiler/staticcodeanalyzer/CryptoRule.java | Refactors the crypto rule into an enum for better organization. |
| compiler-plugin/src/main/java/io/ballerina/stdlib/crypto/compiler/staticcodeanalyzer/CryptoCodeAnalyzer.java | Sets up the analyzer to trigger on function call syntax nodes. |
| compiler-plugin/src/main/java/io/ballerina/stdlib/crypto/compiler/staticcodeanalyzer/CryptoCipherAlgorithmAnalyzer.java | Implements the logic to detect weak cipher function invocations and scan import declarations. |
| compiler-plugin/src/main/java/io/ballerina/stdlib/crypto/compiler/CryptoCompilerPlugin.java | Updates the compiler plugin to register the new code analyzer using the scanner context. |
| Remaining test files | Add test cases and expected outputs to validate the rule’s behavior. |



Purpose
Fixes: ballerina-platform/ballerina-library#7940
Description
The analyzer is triggered when a
FUNCTION_CALLnode is encountered in the syntax tree.It checks for a
QualifiedNameReferenceNodewith any prefixes used for the crypto module (both defaultcryptoand any custom prefixes) and identifierencryptAesEcborencryptAesCbc.On match, the analyzer reports the vulnerability.
Checklist