|
3 | 3 | from libcst.metadata import ParentNodeProvider |
4 | 4 |
|
5 | 5 | from codemodder.codemods.check_annotations import is_disabled_by_annotations |
6 | | -from codemodder.codemods.libcst_transformer import NewArg |
| 6 | +from codemodder.codemods.libcst_transformer import ( |
| 7 | + LibcstResultTransformer, |
| 8 | + LibcstTransformerPipeline, |
| 9 | + NewArg, |
| 10 | +) |
7 | 11 | from codemodder.codemods.utils_mixin import NameResolutionMixin |
8 | | -from core_codemods.api import Metadata, Reference, ReviewGuidance, SimpleCodemod |
| 12 | +from core_codemods.api import ( |
| 13 | + CoreCodemod, |
| 14 | + Metadata, |
| 15 | + Reference, |
| 16 | + ReviewGuidance, |
| 17 | + SimpleCodemod, |
| 18 | +) |
9 | 19 |
|
10 | 20 |
|
11 | | -class SubprocessShellFalse(SimpleCodemod, NameResolutionMixin): |
12 | | - metadata = Metadata( |
13 | | - name="subprocess-shell-false", |
14 | | - summary="Use `shell=False` in `subprocess` Function Calls", |
15 | | - review_guidance=ReviewGuidance.MERGE_AFTER_CURSORY_REVIEW, |
16 | | - references=[ |
17 | | - Reference( |
18 | | - url="https://docs.python.org/3/library/subprocess.html#security-considerations" |
19 | | - ), |
20 | | - Reference( |
21 | | - url="https://en.wikipedia.org/wiki/Code_injection#Shell_injection" |
22 | | - ), |
23 | | - Reference(url="https://stackoverflow.com/a/3172488"), |
24 | | - ], |
25 | | - ) |
| 21 | +class SubprocessShellFalseTransformer(LibcstResultTransformer, NameResolutionMixin): |
26 | 22 | change_description = "Set `shell` keyword argument to `False`" |
27 | 23 | SUBPROCESS_FUNCS = [ |
28 | 24 | f"subprocess.{func}" |
@@ -68,3 +64,22 @@ def first_arg_is_not_string(self, original_node: cst.Call) -> bool: |
68 | 64 | value=m.SimpleString() | m.ConcatenatedString() | m.FormattedString() |
69 | 65 | ), |
70 | 66 | ) |
| 67 | + |
| 68 | + |
| 69 | +SubprocessShellFalse = CoreCodemod( |
| 70 | + metadata=Metadata( |
| 71 | + name="subprocess-shell-false", |
| 72 | + summary="Use `shell=False` in `subprocess` Function Calls", |
| 73 | + review_guidance=ReviewGuidance.MERGE_AFTER_CURSORY_REVIEW, |
| 74 | + references=[ |
| 75 | + Reference( |
| 76 | + url="https://docs.python.org/3/library/subprocess.html#security-considerations" |
| 77 | + ), |
| 78 | + Reference( |
| 79 | + url="https://en.wikipedia.org/wiki/Code_injection#Shell_injection" |
| 80 | + ), |
| 81 | + Reference(url="https://stackoverflow.com/a/3172488"), |
| 82 | + ], |
| 83 | + ), |
| 84 | + transformer=LibcstTransformerPipeline(SubprocessShellFalseTransformer), |
| 85 | +) |
0 commit comments