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
This weakness is not covered by the automated black-box pentest. IntegSec pentesters cover it in a manual engagement.
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?
This weakness is not covered by the automated black-box pentest. IntegSec pentesters cover it in a manual engagement.
Related CWEs
Written and reviewed by
Michel Chamberland - Founder & CEO, IntegSec
CISSP, OSCP, OSCE, CEH, GIAC, CCSK · 20+ years in offensive security
Michel has spent 20+ years on offensive security teams including IBM X-Force Red and Trustwave SpiderLabs, leading penetration tests, red team engagements, and breach response for Fortune 500 customers. He is the founder of IntegSec and the architect of TurboPentest.
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 pentest