mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Merge pull request #1271 from markshannon/python-fix-fp-http-prefix
Python: Fix false positive in 'Incomplete URL substring sanitization' query
This commit is contained in:
@@ -35,16 +35,18 @@ predicate incomplete_sanitization(Expr sanitizer, StrConst url) {
|
||||
(
|
||||
sanitizer.(Compare).compares(url, any(In i), _)
|
||||
or
|
||||
call_to_startswith(sanitizer, url)
|
||||
unsafe_call_to_startswith(sanitizer, url)
|
||||
or
|
||||
unsafe_call_to_endswith(sanitizer, url)
|
||||
)
|
||||
}
|
||||
|
||||
predicate call_to_startswith(Call sanitizer, StrConst url) {
|
||||
predicate unsafe_call_to_startswith(Call sanitizer, StrConst url) {
|
||||
sanitizer.getFunc().(Attribute).getName() = "startswith"
|
||||
and
|
||||
sanitizer.getArg(0) = url
|
||||
and
|
||||
not url.getText().regexpMatch("(?i)https?://[\\.a-z0-9-]+/.*")
|
||||
}
|
||||
|
||||
predicate unsafe_call_to_endswith(Call sanitizer, StrConst url) {
|
||||
|
||||
@@ -39,3 +39,12 @@ def safe2(request):
|
||||
if host and host.endswith(".example.com"):
|
||||
return redirect(target)
|
||||
|
||||
|
||||
@app.route('/some/path/good3')
|
||||
def safe3(request):
|
||||
target = request.args.get('target', '')
|
||||
target = urlparse(target)
|
||||
#Start url with https:// and ends with a / so must match the correct domain.
|
||||
if target and target.startswith("https://example.com/"):
|
||||
return redirect(target)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user