Skip to content

Comments

Enhance static code analyzer rule to support positional and named password arguments#1425

Closed
nureka-rodrigo wants to merge 12 commits intoballerina-platform:masterfrom
nureka-rodrigo:master
Closed

Enhance static code analyzer rule to support positional and named password arguments#1425
nureka-rodrigo wants to merge 12 commits intoballerina-platform:masterfrom
nureka-rodrigo:master

Conversation

@nureka-rodrigo
Copy link

Purpose

Fixes: ballerina-platform/ballerina-library#8103

Description

This PR includes below improvements.

  • Updated SecurePasswordAnalyzer to detect empty passwords in both named and positional arguments for MySQL client initialization.
  • Refactored analyzer logic for improved accuracy and maintainability.
  • Added support for custom MySQL import prefixes.
  • Updated test resources and expected outputs to cover new cases.
  • Bumped balScanVersion to 0.10.0 and used scan-tool's test API to perform testing.

Checklist

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

@nureka-rodrigo nureka-rodrigo changed the title Enhance static code analyzer rule to support positional and named pas… Enhance static code analyzer rule to support positional and named password arguments Jul 18, 2025
@nureka-rodrigo nureka-rodrigo changed the title Enhance static code analyzer rule to support positional and named password arguments Enhance the existing scan rule to support positional and named password arguments Jul 18, 2025
@nureka-rodrigo nureka-rodrigo changed the title Enhance the existing scan rule to support positional and named password arguments Enhance static code analyzer rule to support positional and named password arguments Jul 18, 2025
Comment on lines +125 to +126
return namedArgument.argumentName().toString().trim().equals(PASSWORD)
&& namedArgument.expression().toString().trim().equals("\"\"");
Copy link
Member

Choose a reason for hiding this comment

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

Can't we use the Semantic API for this?

Copy link
Author

Choose a reason for hiding this comment

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

As far as I know, the SemanticModel is primarily used to find references and usages of a given Node or Symbol. In this case, I am looking for a NamedArgumentNode with 'PASSWORD' as the argument name.

Copy link
Member

Choose a reason for hiding this comment

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

You can access the parameters of a function using the MethodSymbol class.

I am suggesting this because that the toString, trim, etc. are not that readable, while using the Semantic API, you can easily, and cleanly check these. Check this example as well.

Copy link
Author

@nureka-rodrigo nureka-rodrigo Sep 24, 2025

Choose a reason for hiding this comment

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

@ThisaruGuruge I tried, but I wasn’t able to do this using the Semantic API. In the case of password = "test123", using semanticModel.symbol(passwordArgument) always returns empty.

Copy link
Member

Choose a reason for hiding this comment

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

You probably cannot validate the values using the Semantic API, my suggestion was to use it for types and names.

Copy link
Author

Choose a reason for hiding this comment

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

@ThisaruGuruge Shall we go with the current implementation?

@codecov
Copy link

codecov bot commented Sep 9, 2025

Codecov Report

❌ Patch coverage is 0% with 48 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.48%. Comparing base (5cbfcbc) to head (87844d5).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...ler/staticcodeanalyzer/SecurePasswordAnalyzer.java 0.00% 44 Missing ⚠️
...b/mysql/compiler/staticcodeanalyzer/MySQLRule.java 0.00% 2 Missing ⚠️
...er/staticcodeanalyzer/MySQLStaticCodeAnalyzer.java 0.00% 1 Missing ⚠️
...mysql/compiler/staticcodeanalyzer/RuleFactory.java 0.00% 1 Missing ⚠️

❌ Your project check has failed because the head coverage (72.48%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1425      +/-   ##
============================================
- Coverage     74.43%   72.48%   -1.96%     
  Complexity      125      125              
============================================
  Files            27       27              
  Lines           669      687      +18     
  Branches        128      136       +8     
============================================
  Hits            498      498              
- Misses          122      140      +18     
  Partials         49       49              

☔ 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.

@ThisaruGuruge
Copy link
Member

PR build is failing. @nureka-rodrigo can you please check?

Introduces a new Ballerina file 'custom_prefix.bal' under rule1 test resources and updates the expected output to include a vulnerability finding for insecure database password usage. This enhances test coverage for custom import prefixes in the static code analyzer.
@daneshk
Copy link
Member

daneshk commented Feb 20, 2026

This is already addressed in the PR #1427

@daneshk daneshk closed this Feb 20, 2026
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.

Enhance ballerinax/mysql static code analyzer rule to support positional and named password arguments

3 participants