Repository navigation
feat: report structured attacker input reaching NoSQL sinks - #160
Merged
Merged
Conversation
A module-level name denotes what its value denotes in a function body: an alias, an attribute, an item or a call of an import or of an earlier module-level name, resolved in statement order.
…odel Symbol resolution reads the Members models the engine provides as the semantic.members input, so SymbolAnalysis now depends on MembersAnalysis besides scopes and imports.
Text sources (form fields, headers, URL parameters, argv, the environment, input()) no longer carry NOSQL, so the operator source kinds are now expressed with TEXT_KINDS.
Only input that may hold a structure carries NOSQL: text sources carry TEXT_KINDS, and an entry-point parameter annotated with scalars loses NOSQL. A flow names each origin once, whatever kinds the parameters of one entry point carry.
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.
Summary
nosql-injectionreports attacker input that may hold a structure reaching aNOSQLsink. The typical case is a MongoDB filter, where a JSON body giving{"$ne": null}matches any value. A string cannot hold an operator, so only input that may hold a structure carriesNOSQL. That is the decision recorded in #158.Closes #158.
Stacked on #156 and #159. Merge them first; this PR then shows only its own two commits.
What carries
NOSQLNOSQLrequest.json,get_json()), raw bodies (data,get_data(),stream, bottle'sbody), files, tornado's request object and WebSocket messages,sys.stdin, HTTP responses, process outputargs,form,values,cookies,headersand paths; bottle's equivalents; tornadoget_*argument(s),get_cookie,path_args,path_kwargs; the URL parameters of Flask, bottle and tornado routes;argv, click and Typer parameters, the environment,input()TEXT_KINDSstr,int,float,bool,bytes,UUID, dates,Decimal,Literal[...], or containers of them; also throughOptional,Union,| NoneandAnnotatedTEXT_KINDSisALLwithoutNOSQL. It is exported for model plugins.One origin per flow
Problem. The parameters of one entry point can now carry different kinds: a scalar one has no
NOSQL. They therefore got distinctSourceobjects for the same origin, andreportemitted one flow perSource. The regression snapshots caught it: healthchecks'ping_body(request, code: UUID, n: int)gave two identicalxssfindings at line 814.Fix.
reportnow emits one flow per origin (symbol and label). As before, the flow's kinds come from the taint.test_parameters_of_one_entry_point_remain_one_origincovers the case, and the snapshots are unchanged.Changed expectation
test_source_kinds_reflect_who_controls_them:os.environ,sys.argvandinput()are text, so they no longer carryNOSQL. TheirCOMMANDandPATHrestrictions are checked as before, andsubprocess.check_outputis unchanged.Limits
They are documented in
docs/usage.md.request.GET["name"]still counts. A test locks this behaviour.$whereis not reported.json.loads(request.args["filter"])) is not reported, and neither is a whole query mapping used as a filter.The engine ships no
NOSQLsink. The pymongo models (CoreTrace-Entreprise/coretrace-python-analyzer-plugins#3) will declare them, using #157 for the database and collection names.Tests
tests/test_nosql_injection.pycovers:argvand the environment;The count of bundled plugins goes from 36 to 37.
Local results:
ruff checkandmypyreport nothing.