SEC595: Applied Data Science and AI/Machine Learning for Cybersecurity Professionals

Experience SANS training through course previews.
Learn MoreLet us help.
Contact usBecome a member for instant access to our free resources.
Sign UpWe're here to help.
Contact UsCWE-754 happens when "software does not check or improperly checks for unusual or exceptional conditions that are not expected to occur frequently during day to day operation of the software." [1]
Take the following snippet of Java code as an example:
private static final int ROLE_ADMIN = 0;
private static final int ROLE_USER = 1;
private static final int ROLE_GUEST = 2;
public static final int getRole() {
String s = lookupRoleInDatabase();
int role = 0;
try {
role = Integer.valueOf(s);
} catch (NumberFormatException e) {
// this shouldn't happen
}
return role;
}
In this case the developer does not expect a NumberFormatException to occur and simply swallows the Exception. This has the nasty side effect of granting admin access because the role variable has a default value of zero (i.e. ADMIN) and this default value is returned if a NumberFormatException is thrown.
Always check and handle exceptional conditions and always perform validation on inputs (even if they come from the database). Also, keep in mind that unusual or exceptional conditions aren't just related to exception handling. Ignoring return values can also lead to incorrect behavior [2].
Frank Kim is the Founder of ThinkSec, a security consulting and CISO advisory firm. He leads the Cybersecurity Leadership and Cloud Security curricula at SANS, as well as authors and instructs multiple SANS courses.
Read more about Frank Kim