Repository navigation
feat: recognise entry points by a pattern on the base class - #177
Merged
Merged
Conversation
A gRPC servicer subclasses a class generated per project, so no fixed symbol names it. The tests specify a BasePattern model: the methods of a class whose base's canonical symbol matches the pattern are entry points whatever the module's prefix and however the base is imported, their parameters typed by their position (the message is input of every kind, the context denotes a class whose invocation_metadata() is a text source and whose peer() is not), only the methods the base defines when the project holds it, and every method with the listed arity otherwise. Async methods, client streams, other processes, a single-file check and a base preceded by another are covered.
BasePattern(pattern, label, parameters, kinds) matches the canonical symbol of a class's base against a regular expression, for bases generated per project such as a gRPC servicer's. Each parameter after self is, by position, input of the model's kinds or an object of a class the model names, which the sources on that class taint without the object being input. When the project holds the base, only the methods the base defines are entry points, so a servicer's utility methods are not; otherwise every method with the listed number of parameters is. The engine derives Signatures from the models and provides them to the call graph, which types the parameters by their position for every resolvable base of the class, since the inheritance map keeps the first base only. The taint engine decides the entry point with the project index, which says what the base defines.
Merged
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 #176. The engine side of the gRPC chantier; the
grpctable follows in Enterprise (CoreTrace-Entreprise/coretrace-python-analyzer-plugins#3), with the pattern(?:^|\.)\w+_pb2_grpc\.\w+Servicer$and the sources onServicerContext.Summary
BasePattern(pattern, label, parameters=(None,), kinds=ALL). The methods of a class whose base's canonical symbol matches the regular expression are entry points, whatever the module's prefix and however the base is imported: module, module alias,import … as, name, name alias. The generated module may be in the project or absent from it.self:Noneis attacker input of the model's kinds; a class symbol makes the parameter denote that class, so the sources on the class apply, asinvocation_metadata()on aServicerContext, without the object being input:peer()andstr(context)give nothing. The message carries every kind, itsMessageToDictconversion, attributes and dict literals included.SignatureandSignaturesAnalysisin the interprocedural layer, provided from the models at the four sites (single file, project, batch), likeClearingAnalysis. The call graph types the parameters by position for every resolvable base of the class: its inheritance map keeps the first base only, and a mixin or an installed class before the generated base would otherwise hide the context typing.SummaryIndex.definessays whether the project holds a class.Verification
tests/test_base_patterns.py: 24 passed. Full suite under Python 3.12.10, regression snapshots included: 1434 passed.ruff checkandmypypass.