Repository navigation
fix: count a guard only when it examines what the sink receives - #136
Merged
Merged
Conversation
Closed
2 of 3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #135. This is the rule the #98 measurement led to. It comes after the model fixes #129, #131 and #133, so the verdicts it changes are all real vulnerabilities.
Rule
A dominating guard used to make a flow a hotspot as soon as it read any value the flow's origin fed.
if request.method == 'POST':therefore loweredos.system(request.POST['cmd'])to a hotspot (MEDIUM confidence), and almost every Django or Flask view starts with such a check.A guard now makes a flow a hotspot only when it examines what the sink receives. The engine walks from the condition down its operands, and does not descend into an object when the guard only reads another attribute or item of it than the flow does. The guard still counts, as before, when it:
if cmd:,len(cmd) < 10,cmd in allowed());if req.data:beforereq.data);form.is_valid(),allowed(q.lower()));Proofs and authorization guards are unchanged.
Commits
test: record the verdict of taint findings in the regression snapshotschanges no behaviour. Snapshots used to record file, line, rule and function only, so a verdict change never showed up in review. All 19 are re-recorded: 28 vulnerabilities and 28 hotspots.test: …adds 8 refutation cases:fix: …holds the rule, the usage guide, the CHANGELOG, and the snapshot diff: exactly the 10 verdicts below.The 10 findings raised to HIGH, each reviewed
authentication/views.py:57sql-injectionrequest.method == 'POST'User.objects.raw(query)withquery = "... '%s' ..." % (username, password)fromrequest.POSTsqli/views.py:57sql-injectionrequest.method == 'POST'Student.create(conn, data['name']), which runs"VALUES ('%(name)s')" % ...mitre.py:242command-injectionrequest.method == "POST"command_out("nmap " + request.POST.get('ip')), run withshell=Trueviews.py:430command-injectionrequest.method=="POST"subprocess.Popen("dig {}".format(domain), shell=True)views.py:214insecure-deserializationrequest.user.is_authenticatedpickle.loads(base64.b64decode(request.COOKIES['token']))views.py:560insecure-deserialization + exploitable-vulnerabilityrequest.user.is_authenticatedyaml.load(request.FILES["file"], yaml.Loader)on PyYAML 5.1views.py:584exploitable-vulnerabilityrequest.method == "POST"Image.open(request.FILES["file"])on a vulnerable Pillowviews.py:927path-traversalrequest.user.is_authenticatedopen(os.path.join(dirname, request.POST["blog"]))views.py:963ssrfrequest.method == "POST"requests.get(request.POST["url"])The seven model false positives that an earlier version of this rule would have raised were fixed first: #129, #131 and #133. Two healthchecks login flows (
hc/accounts/views.py:170and281) stay hotspots. They passrequestwhole into_check_2fa, whosereversesanitizer is not applied through the summary (#134).Verification
pytest: 1065 passed.ruff check src testsandmypyare clean.pytest -m regressionunder Python 3.12: 19 passed, before and after the rule.