-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Java: add CSRF query #18288
base: main
Are you sure you want to change the base?
Java: add CSRF query #18288
Conversation
java/ql/lib/semmle/code/java/security/CsrfUnprotectedRequestTypeQuery.qll
Fixed
Show fixed
Hide fixed
java/ql/lib/semmle/code/java/security/CsrfUnprotectedRequestTypeQuery.qll
Fixed
Show fixed
Hide fixed
java/ql/lib/semmle/code/java/security/CsrfUnprotectedRequestTypeQuery.qll
Fixed
Show fixed
Hide fixed
java/ql/src/experimental/Security/CWE/CWE-089/MyBatisMapperXmlSqlInjection.ql
Fixed
Show fixed
Hide fixed
java/ql/test/query-tests/security/CWE-352/CsrfUnprotectedRequestTypeTest.ql
Fixed
Show fixed
Hide fixed
java/ql/test/query-tests/security/CWE-352/CsrfUnprotectedRequestTypeTest.ql
Fixed
Show fixed
Hide fixed
java/ql/test/query-tests/security/CWE-352/CsrfUnprotectedRequestTypeTest.ql
Fixed
Show fixed
Hide fixed
java/ql/test/query-tests/security/CWE-352/CsrfUnprotectedRequestTypeTest.ql
Fixed
Show fixed
Hide fixed
java/ql/test/query-tests/security/CWE-352/CsrfUnprotectedRequestTypeTest.ql
Fixed
Show fixed
Hide fixed
ff0477c
to
13753dd
Compare
QHelp previews: java/ql/src/Security/CWE/CWE-352/CsrfUnprotectedRequestType.qhelpHTTP request type unprotected from CSRFWhen you set up a web server to receive a request from a client without any mechanism for verifying that it was intentionally sent, then it is vulnerable to attack. An attacker can trick a client into making an unintended request to the web server that will be treated as an authentic request. This can be done via a URL, image load, XMLHttpRequest, etc. and can result in exposure of data or unintended code execution. RecommendationWhen handling requests, make sure any requests that change application state are protected from Cross Site Request Forgery (CSRF). Some application frameworks, such as Spring, provide default CSRF protection for HTTP request types that may change application state, such as POST. Other HTTP request types, such as GET, should not be used for actions that change the state of the application, since these request types are not default-protected from CSRF by the framework. ExampleThe following example shows a Spring request handler using a GET request for a state-changing action. Since a GET request does not have default CSRF protection in Spring, this type of request should not be used when modifying application state. Instead use one of Spring's default-protected request types, such as POST. // BAD - a GET request should not be used for a state-changing action like transfer
@RequestMapping(value="transfer", method=RequestMethod.GET)
public boolean transfer(HttpServletRequest request, HttpServletResponse response){
return doTransfer(request, response);
} // GOOD - use a POST request for a state-changing action
@RequestMapping(value="transfer", method=RequestMethod.POST)
public boolean transfer(HttpServletRequest request, HttpServletResponse response){
return doTransfer(request, response);
} References
|
c217d7f
to
3d14e16
Compare
2472aad
to
695eca6
Compare
…lt-protected from CSRF
…lib so importable, and fix experimental files broken by the move
… sql-injection nodes)
…pdate queries like select
695eca6
to
b56a8d8
Compare
sinkMethodCall.getASuccessor() = pragma[only_bind_into](sinkMethod) and | ||
sourceMethod.getASuccessor+() = pragma[only_bind_into](sinkMethodCall) and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added pragma[only_bind_into]
here to fix performance. Let me know if there is a better way to resolve this performance problem.
// exclude SQL `execute` calls that do not update database | ||
if | ||
sinkMethod.asMethod() instanceof SqlInjectionDatabaseUpdateMethod and | ||
sinkMethod.asMethod().hasName("execute") | ||
then | ||
exists(SqlExecuteFlow::PathNode executeSink | SqlExecuteFlow::flowPath(_, executeSink) | | ||
sinkMethodCall.asCall() = executeSink.getNode().asExpr().(Argument).getCall() | ||
) | ||
else any() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know if there is a better way to handle this exclusion.
Description
Adds a query for CSRF vulnerabilities caused by using HTTP request types that are not default-protected by a given framework for apparent state-changing actions. Supports Spring and Stapler frameworks for now. State-changing actions are determined heuristically based on whether the request handling method updates a database or whether its name suggests that it might change application state. Due to the heuristic nature of determining state changes, this is a low precision query.
Consideration
Pull Request checklist
All query authors
.qhelp
. See the documentation in this repository.Internal query authors only
.ql
,.qll
, or.qhelp
files. See the documentation (internal access required).