Skip to content
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

fix(python): shared input rules to use import wherever possible #402

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions rules/python/shared/django/user_input.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ patterns:
- pattern: $<FORM>.$<METHOD>[$<_>]
filters:
- variable: FORM
regex: \A(un)?(bound_)?form\z
detection: python_shared_django_user_input_form
scope: result
- variable: METHOD
values:
- data
Expand All @@ -28,9 +29,19 @@ patterns:
- pattern: $<FORM>[$<_>].value()
filters:
- variable: FORM
regex: \A(un)?(bound_)?form\z
detection: python_shared_django_user_input_form
scope: result
auxiliary:
- id: python_shared_django_user_input_form
elsapet marked this conversation as resolved.
Show resolved Hide resolved
patterns:
- pattern: $<FORM>
# from <some_form_module> import <SomeFormName>
# form = FormName(request.POST)
filters:
- variable: FORM
regex: \A(un)?(bound_)?form\z
- id: python_shared_django_user_input_request
# passed to a view method e.g. def my_view(request)
patterns:
- request
- req
Expand Down
39 changes: 17 additions & 22 deletions rules/python/shared/lang/dynamic_input.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,38 @@
type: shared
languages:
- python
imports:
- python_shared_lang_import1
patterns:
- sys.argv[$<_>]
- pattern: $<PARSER>.parse_args($<...>)
filters:
- variable: PARSER
detection: python_shared_lang_dynamic_input_parser
scope: result
- pattern: $<GETOPT>.getopt($<...>)
- pattern: $<GETOPT>($<...>)
filters:
- variable: GETOPT
detection: python_shared_lang_dynamic_input_getopt
scope: result
detection: python_shared_lang_import1
scope: cursor
filters:
- variable: MODULE1
values: [getopt]
- variable: NAME
values: [getopt]
auxiliary:
- id: python_shared_lang_dynamic_input_parser
patterns:
- pattern: $<ARG_PARSER>()
filters:
- variable: ARG_PARSER
detection: python_shared_lang_dynamic_input_argument_parser
- id: python_shared_lang_dynamic_input_argument_parser
patterns:
- ArgumentParser # fallback
- from argparse import ArgumentParser as $<!>$<_>
- pattern: $<ARGPARSE>.ArgumentParser
filters:
- variable: ARGPARSE
detection: python_shared_lang_dynamic_input_argparse_import
- id: python_shared_lang_dynamic_input_argparse_import
patterns:
- import $<!>argparse
- import argparse as $<!>$<_>
- argparse # fallback
- id: python_shared_lang_dynamic_input_getopt
patterns:
- import $<!>getopt
- import getopt as $<!>$<_>
- getopt # fallback
detection: python_shared_lang_import1
scope: cursor
filters:
- variable: MODULE1
values: [argparse]
- variable: NAME
values: [ArgumentParser]
metadata:
description: "Python dynamic input."
id: python_shared_lang_dynamic_input
Loading