Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b567ec8

Browse files
committed
Documentation
1 parent 55fae2d commit b567ec8

4 files changed

Lines changed: 28 additions & 2 deletions

File tree

java/ql/lib/semmle/code/java/security/TrustBoundaryViolationQuery.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class TrustBoundaryViolationSink extends DataFlow::Node {
2626
TrustBoundaryViolationSink() { sinkNode(this, "trust-boundary") }
2727
}
2828

29+
/**
30+
* A sanitizer for data that crosses a trust boundary.
31+
*/
2932
abstract class TrustBoundaryValidationSanitizer extends DataFlow::Node { }
3033

3134
/**
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
public void doGet(HttpServletRequest request, HttpServletResponse response) {
2+
String username = request.getParameter("username");
3+
4+
if (validator.isValidInput("HTTP parameter", username, "username", 20, false)) {
5+
// GOOD: The input is sanitized before being written to the response.
6+
request.getSession().setAttribute("username", username);
7+
}
8+
}

java/ql/src/Security/CWE/CWE-501/TrustBoundaryViolation.qhelp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,21 @@
2222

2323
<recommendation>
2424
<p>
25-
Validate input coming from a user. For example, if a web application accepts a cookie from a user, then the
26-
application should validate the cookie before using it.
25+
In order to maintain a trust boundary, data from less trusted sources should be validated before being used.
2726
</p>
2827
</recommendation>
2928

3029
<example>
30+
<p>
31+
In the first (bad) example, the server accepts a parameter from the user and uses it to set the username without validation.
32+
</p>
33+
<sample src="examples/TrustBoundaryVulnerable.java" />
34+
35+
<p>
36+
In the second (good) example, the server validates the parameter before using it to set the username.
37+
</p>
38+
<sample src="examples/TrustBoundaryFixed.java" />
39+
3140
</example>
3241

3342
<references>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
public void doGet(HttpServletRequest request, HttpServletResponse response) {
2+
String username = request.getParameter("username");
3+
4+
// BAD: The input is written to the response without being sanitized.
5+
request.getSession().setAttribute("username", username);
6+
}

0 commit comments

Comments
 (0)