CWE-481: Assigning instead of Comparing
The code uses an operator for assignment when the intention was to perform a comparison.
How it's found
Assigning instead of Comparing is a specific, narrowly defined instance of a broader pattern. Testers confirm it with targeted code review and a proof-of-concept input that exercises the exact code path this weakness describes.
In many languages the compare statement is very close in appearance to the assignment statement and are often confused. This bug is generally the result of a typo and usually causes obvious problems with program execution. If the comparison is in an if statement, the if statement will usually evaluate the value of the right-hand side of the predicate.
Vulnerable vs. safe
System.out.println("Performing processing");doSomethingImportant();
System.out.println("Not Valid, do not perform processing");return;
if (isValid = true) {}else {}public void checkValid(boolean isValid) {}System.out.println("Performing processing");doSomethingImportant();
System.out.println("Not Valid, do not perform processing");return;
if (isValid) {}else {}public void checkValid(boolean isValid) {}Consequences
- Alter Execution Logic
Mitigations
- Implementation: Place constants on the left. If one attempts to assign a constant with a variable, the compiler will produce an error.
Where this fits in a TurboPentest engagement
TurboPentest's agentic pentest is powerful and covers a broad range of issues automatically. This particular class is best confirmed in a manual IntegSec engagement, where human pentesters apply deeper methodology and a larger context window than any automated pass.
Frequently asked questions
What is CWE-481?
The code uses an operator for assignment when the intention was to perform a comparison.
How do you find Assigning instead of Comparing?
Assigning instead of Comparing is a specific, narrowly defined instance of a broader pattern. Testers confirm it with targeted code review and a proof-of-concept input that exercises the exact code path this weakness describes.
What is the impact of CWE-481?
Alter Execution Logic
Does TurboPentest test for Assigning instead of Comparing?
TurboPentest's agentic pentest is powerful and covers a broad range of issues automatically. This particular class is best confirmed in a manual IntegSec engagement, where human pentesters apply deeper methodology and a larger context window than any automated pass.
Related CWEs
Find these issues before an attacker does
TurboPentest runs an agentic AI pentest against your target and reports findings with proof, from $99 per target.
Start a $99 pentest