Skip to content

Commit

Permalink
Don't break codee with suggested fix (#425)
Browse files Browse the repository at this point in the history
The weak random Java rule currently suggests a fix that tells the user
to use the constructor insteead of getInstance method. As a result, the
NoSuchAlgorithmException doesn't get thrown. So the fix would create
code that no longer compiles.

This change now swaps the weak random algorithm with a strong one that
is known to exists for all platforms.

Signed-off-by: Eric Brown <eric.brown@securesauce.dev>
  • Loading branch information
ericwb authored Apr 14, 2024
1 parent 1d565b5 commit 08973e1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions precli/rules/java/stdlib/java_security_weak_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ def analyze_method_invocation(self, context: dict, call: Call) -> Result:

fixes = Rule.get_fixes(
context=context,
deleted_location=Location(node=call.node),
deleted_location=Location(node=argument.node),
description="Use SecureRandom without specifying an algorithm, "
"allowing the Java runtime to select the strongest available "
"algorithm.",
inserted_content="new SecureRandom()",
inserted_content='"DRBG"',
)
return Result(
rule_id=self.id,
Expand Down

0 comments on commit 08973e1

Please sign in to comment.