-
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
WIP: Python: CORS Bypass #16814
WIP: Python: CORS Bypass #16814
Conversation
Hello porcupineyhairs 👋 In the meantime, feel free to make changes to the pull request. If you'd like to maximize payout for your this and future submissions, here are a few general guidelines, that we might take into consideration when reviewing a submission.
Please note that these are guidelines, not rules. Since we have a lot of different types of submissions, the guidelines might vary for each submission. Happy hacking! |
@RasmusWL The bounty application for this Pr is already closed. Do you plan on merging this soon? |
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.
Hello
In addition to the above style warnings, there are compilation errors due to the path-problem
query kind expecting the nodes selected in the alert to be PathNode
s rather than DataFlow::Node
s, as so:
from DataFlow::Node source, DataFlow::Node sink | ||
where | ||
CorsFlow::flow(source, sink) and | ||
( | ||
maybeInteresting(source.asCfgNode()) | ||
or | ||
maybeInteresting(sink.asCfgNode()) | ||
) | ||
select source, source, sink, | ||
"Potentially incorrect string comparision which could lead to a CORS bypass." |
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.
from DataFlow::Node source, DataFlow::Node sink | |
where | |
CorsFlow::flow(source, sink) and | |
( | |
maybeInteresting(source.asCfgNode()) | |
or | |
maybeInteresting(sink.asCfgNode()) | |
) | |
select source, source, sink, | |
"Potentially incorrect string comparision which could lead to a CORS bypass." | |
from CorsFlow::PathNode source, CorsFlow::PathNode sink | |
where | |
CorsFlow::flowPath(source, sink) and | |
( | |
maybeInteresting(source.getNode().asCfgNode()) | |
or | |
maybeInteresting(sink.getNode().asCfgNode()) | |
) | |
select source, source, sink, | |
"Potentially incorrect string comparison which could lead to a CORS bypass." |
This PR adds a query to detect a Cross Origin Resource Sharing(CORS) policy bypass due to an incorrect check. This PR attempts to detect the vulnerability pattern found in CVE-2022-3457 ```python if request.method in ['POST', 'PUT', 'PATCH', 'DELETE']: origin = request.headers.get('Origin', None) if origin and not origin.startswith(request.base): raise cherrypy.HTTPError(403, 'Unexpected Origin header') ``` In this case, a value obtained from a header is compared using `startswith` call. This comparision is easily bypassed resulting in a CORS bypass. Given that similar bugs have been found in other languages as well, I think this PR would be a great addition to the exisitng python query pack. The databases for CVE-2022-3457 can be downloaded from ``` https://filetransfer.io/data-package/i4Mfepls#link https://file.io/V67T4SSgmExF ```
0b58040
to
f86570f
Compare
@joefarebrother Sorry for the delay. Changes done. I have also included Qhelp and tests now. |
QHelp previews: python/ql/src/experimental/Security/CWE-346/CorsBypass.qhelpCross Origin Resource Sharing(CORS) Policy BypassCross-origin resource sharing policy may be bypassed due to incorrect checks like the RecommendationUse a more stronger check to test for CORS policy bypass. ExampleMost Python frameworks provide a mechanism for testing origins and performing CORS checks. For example, consider the code snippet below, import cherrypy
def bad():
request = cherrypy.request
validCors = "domain.com"
if request.method in ['POST', 'PUT', 'PATCH', 'DELETE']:
origin = request.headers.get('Origin', None)
if origin.startswith(validCors):
print("Origin Valid") This can be prevented by comparing the origin in a manner shown below. import cherrypy
def good():
request = cherrypy.request
validOrigin = "domain.com"
if request.method in ['POST', 'PUT', 'PATCH', 'DELETE']:
origin = request.headers.get('Origin', None)
if origin == validOrigin:
print("Origin Valid") References
|
This PR adds a query to detect a Cross Origin Resource Sharing(CORS) policy bypass due to an incorrect check.
This PR attempts to detect the vulnerability pattern found in CVE-2022-3457
In this case, a value obtained from a header is compared using
startswith
call. This comparision is easily bypassed resulting in a CORS bypass. Given that similar bugs have been found in other languages as well, I think this PR would be a great addition to the exisitng python query pack.The databases for CVE-2022-3457 can be downloaded from