A servlet keeps per-request data in a mutable field that every thread sees
What it finds
A servlet container creates one instance of a servlet and runs every request on it, each on its own thread. A field that a request writes is seen, and overwritten, by the requests running at the same time, which mixes up their data (CWE-362), as the servlet specification's notes on concurrency say.
Reported is a non-static, non-final field of a class that extends HttpServlet or GenericServlet. Fields that the container injects are left alone.
From the rule's source, servlet_instance_field.rs.
import javax.servlet.http.HttpServlet; class Counter extends HttpServlet { private int hits;tx0 reports: hits is shared by all requests private final String name = "counter"; private static int total;} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/java:shared-servlet-state" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/java:shared-servlet-state] reason="..."tx0 explain tx0/java:shared-servlet-state shows the same in the terminal. Found a false positive? Report it.