зеркало из https://github.com/github/codeql.git
Documentation
This commit is contained in:
Родитель
55fae2daaa
Коммит
b567ec875a
|
@ -26,6 +26,9 @@ class TrustBoundaryViolationSink extends DataFlow::Node {
|
|||
TrustBoundaryViolationSink() { sinkNode(this, "trust-boundary") }
|
||||
}
|
||||
|
||||
/**
|
||||
* A sanitizer for data that crosses a trust boundary.
|
||||
*/
|
||||
abstract class TrustBoundaryValidationSanitizer extends DataFlow::Node { }
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
public void doGet(HttpServletRequest request, HttpServletResponse response) {
|
||||
String username = request.getParameter("username");
|
||||
|
||||
if (validator.isValidInput("HTTP parameter", username, "username", 20, false)) {
|
||||
// GOOD: The input is sanitized before being written to the response.
|
||||
request.getSession().setAttribute("username", username);
|
||||
}
|
||||
}
|
|
@ -22,12 +22,21 @@
|
|||
|
||||
<recommendation>
|
||||
<p>
|
||||
Validate input coming from a user. For example, if a web application accepts a cookie from a user, then the
|
||||
application should validate the cookie before using it.
|
||||
In order to maintain a trust boundary, data from less trusted sources should be validated before being used.
|
||||
</p>
|
||||
</recommendation>
|
||||
|
||||
<example>
|
||||
<p>
|
||||
In the first (bad) example, the server accepts a parameter from the user and uses it to set the username without validation.
|
||||
</p>
|
||||
<sample src="examples/TrustBoundaryVulnerable.java" />
|
||||
|
||||
<p>
|
||||
In the second (good) example, the server validates the parameter before using it to set the username.
|
||||
</p>
|
||||
<sample src="examples/TrustBoundaryFixed.java" />
|
||||
|
||||
</example>
|
||||
|
||||
<references>
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
public void doGet(HttpServletRequest request, HttpServletResponse response) {
|
||||
String username = request.getParameter("username");
|
||||
|
||||
// BAD: The input is written to the response without being sanitized.
|
||||
request.getSession().setAttribute("username", username);
|
||||
}
|
Загрузка…
Ссылка в новой задаче