Custom Rules Guide
Chapter 4: Dataflow Analyzer Rules
This works fine if these are the only rules used to analyze the program. However, if you use the
default Secure Coding Rulepacks to scan the program, Fortify Static Code Analyzer might report
unintended issues. For example, Fortify Static Code Analyzer might report input from HTTP
parameters reaching shareData(), or input from getSecret()being used in a SQL query, even
though these usages are safe.
For these rules to work more precisely, you can introduce a new taint flag (SECRET) to the source and
sink rules. The source rule would add the SECRET taint flag, and the sink rule would check for the
presence of the SECRET taint flag.
This solves half of the problem; the sink at shareData()only reports input from getSecret()and
not from other sources. However, input from getSecret()might unintentionally trigger the
reporting of issues at other sinks, because those sinks do not explicitly check against the absence of
the new SECRET taint flag. This example demonstrates the benefit of specific taint flags. By declaring
the SECRET taint flag as specific, taint from the getSecret()source is prevented from interacting
with existing sinks in unintended ways. Sinks that do not explicitly check for the specific taint flag
SECRET ignore the taint from getSecret().
Taint Flag Behavior
It can be challenging to understand the exact behavior of sinks in the presence of different types of
taint. For any sink that does not explicitly check for the presence or absence of any specific taint flag
in the taint flag set, Fortify Static Code Analyzer automatically adds a check to ensure that the taint
flag set is not specific. A taint flag set is specific if it contains one or more specific taint flags and does
not contain any general taint flags.
Taint Path
The Dataflow Analyzer reports a vulnerability when it finds one or more taint paths between a source
and a sink in the application.
A taint path contains a sequence of method calls, stores (assignment variables or fields), and loads
(reads from variables or fields). It denotes a path along which tainted data propagates from a taint
source point to a taint sink point. In fact, because a program can contain loops or recursion, there can
be an infinite number of paths. The Dataflow Analyzer cannot consider all taint paths from a source to
a sink due to performance implications. However, it does consider every path that has a unique set of
taint flags applied to it. Some of the taint flags indicate that something is validated, which means that
the Dataflow Analyzer does not report an issue on that path. If another path exists on which the data
is not validated, Dataflow Analyzer reports an issue.
Validation Constructs
One of the most basic rule-writing tasks is to write rules for validation constructs such as validation
functions. You can do this by either writing a passthrough or cleanse rule. The rule that is appropriate
depends on the circumstances.
In cases where the function completely validates the input for all cases, a complete cleanse rule (which
removes all taint) is appropriate. In most cases, it is preferable to add a taint flag to the taint path to
indicate that a certain type of validation was performed.
Micro Focus Fortify Static Code Analyzer (23.1.0)
Page 54 of 157