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

Skip to content

Commit f58590c

Browse files
committed
Trust Boundary Work
1 parent 2aba425 commit f58590c

5 files changed

Lines changed: 66 additions & 0 deletions

File tree

java/ql/lib/semmle/code/java/frameworks/Servlets.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,3 +397,7 @@ class GetServletResourceAsStreamMethod extends Method {
397397
this.hasName("getResourceAsStream")
398398
}
399399
}
400+
401+
class HttpServletSession extends RefType {
402+
HttpServletSession() { this.hasQualifiedName("javax.servlet.http", "HttpSession") }
403+
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class TrustBoundaryViolationSink extends DataFlow::Node {
2424
TrustBoundaryViolationSink() { sinkNode(this, "trust-boundary") }
2525
}
2626

27+
abstract class TrustBoundaryValidationSanitizer extends DataFlow::Node { }
28+
2729
/**
2830
* Taint tracking for data that crosses a trust boundary.
2931
*/
@@ -34,6 +36,15 @@ module TrustBoundaryConfig implements DataFlow::ConfigSig {
3436
n2.asExpr().(MethodAccess).getQualifier() = n1.asExpr()
3537
}
3638

39+
predicate isBarrier(DataFlow::Node node) {
40+
node instanceof TrustBoundaryValidationSanitizer or
41+
node.getType() instanceof HttpServletSession or
42+
node.asExpr()
43+
.(MethodAccess)
44+
.getMethod()
45+
.hasQualifiedName("javax.servlet.http", "HttpServletRequest", "getMethod")
46+
}
47+
3748
predicate isSink(DataFlow::Node sink) { sink instanceof TrustBoundaryViolationSink }
3849
}
3950

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
<qhelp>
5+
<overview>
6+
<p>
7+
A trust boundary violation occurs when a value is passed from a less trusted context to a more trusted context.
8+
</p>
9+
10+
<p>
11+
For example, a value that is generated by a less trusted source, such as a user, may be passed to a more trusted
12+
source, such as a system process. If the less trusted source is malicious, then the value may be crafted to
13+
exploit the more trusted source.
14+
</p>
15+
16+
<p>
17+
Trust boundary violations are often caused by a failure to validate input. For example, if a web application
18+
accepts a cookie from a user, then the application should validate the cookie before using it. If the cookie is
19+
not validated, then the user may be able to craft a malicious cookie that exploits the application.
20+
</p>
21+
</overview>
22+
23+
<recommendation>
24+
<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.
27+
</p>
28+
</recommendation>
29+
30+
<example>
31+
</example>
32+
33+
<references>
34+
<li>
35+
Wikipedia: <a href="http://en.wikipedia.org/wiki/Trust_boundary">Trust boundary</a>.
36+
</li>
37+
</references>
38+
39+
</qhelp>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import java.io.IOException;
2+
import javax.servlet.http.HttpServlet;
3+
import javax.servlet.http.HttpServletRequest;
4+
import javax.servlet.http.HttpServletResponse;
5+
6+
public class TrustBoundaryViolations extends HttpServlet {
7+
public void doGet(HttpServletRequest request, HttpServletResponse response) {
8+
String input = request.getParameter("input");
9+
10+
request.getSession().setAttribute("input", input); // $ hasTaintFlow
11+
}
12+
}

java/ql/test/query-tests/security/CWE-501/options

Whitespace-only changes.

0 commit comments

Comments
 (0)