Skip to content

Commit bdefd27

Browse files
committed
- add better signature deduplciation to module finder and sqli detections
1 parent 15d5c48 commit bdefd27

File tree

6 files changed

+24
-22
lines changed

6 files changed

+24
-22
lines changed

aura/analyzers/python/nodes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1471,7 +1471,7 @@ def call_graph(self):
14711471

14721472
@property
14731473
def signature(self) -> str:
1474-
return f"{self.visitor.normalized_path}/{self.node.line_no}"
1474+
return f"{self.visitor.normalized_path}:{self.node.line_no}"
14751475

14761476
def as_child(self, node: NodeType, replace=lambda x: None) -> Context:
14771477
return Context(

aura/analyzers/python/pattern_matching_visitor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def gen_module_import(self, context: Context):
3939
"name": module_name
4040
},
4141
node=context.node,
42-
signature=f"module_import#{module_name}#{context.visitor.normalized_path}",
42+
signature=f"module_import#{module_name}#{context.signature}",
4343
tags=context.node.tags
4444
)
4545
self.hits.append(hit)

aura/analyzers/python/sqli.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ def node_BinOp(self, context):
4848
detection_type="SQLInjection",
4949
score=50,
5050
message="Possible SQL injection found",
51-
signature=f"vuln#{context.visitor.normalized_path}#{context.node.line_no}",
51+
signature=f"vuln#{context.signature}",
52+
node = context.node,
5253
line_no=context.node.line_no,
5354
)
5455

@@ -73,6 +74,7 @@ def node_Call(self, context):
7374
detection_type="SQLInjection",
7475
score=50,
7576
message="Possible SQL injection found",
76-
signature=f"vuln#{context.visitor.normalized_path}#{context.node.line_no}",
77+
signature=f"vuln#sqli#{context.signature}",
78+
node = context.node,
7779
line_no=context.node.line_no,
7880
)

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ classifiers = [
1515
"Intended Audience :: Developers",
1616
"Intended Audience :: System Administrators",
1717
"Operating System :: POSIX :: Linux",
18+
"Programming Language :: Python :: 3.10",
1819
"Programming Language :: Python :: 3.9",
1920
"Programming Language :: Python :: 3.8",
2021
"Programming Language :: Python :: 3 :: Only",

tests/test_ast_rewrite.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,19 @@ def test_string_format_via_mod():
196196
tree = process_source_code(src)
197197
assert isinstance(tree, String)
198198
assert str(tree) == "Hello world"
199+
200+
201+
202+
@pytest.mark.parametrize("src,modules", (
203+
("import a", {"a"}),
204+
("import a.b", {"a.b"}),
205+
("import m1, m2, m3", {"m1", "m2", "m3"}),
206+
("import a as b", {"a"}),
207+
("from a import *", {"a.*"}),
208+
("from a import b, c", {"a.b", "a.c"}),
209+
("from a import b as c", {"a.b"})
210+
))
211+
def test_various_imports(src, modules):
212+
tree = process_source_code(src)
213+
assert isinstance(tree, Import)
214+
assert tree.get_modules() == modules

tests/test_misc.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def test_different_source_code_encoding(fixtures):
8181
def test_fs_structure_detections(fs_mock, fixtures, tmp_path):
8282
files = {
8383
"bytecode.pyc": "some_bytecode_content",
84-
".pypirc": "pypirc_content",
84+
# FIXME: ".pypirc": "pypirc_content",
8585
".empty.txt": ""
8686
}
8787

@@ -98,23 +98,6 @@ def test_fs_structure_detections(fs_mock, fixtures, tmp_path):
9898
"file_name": "bytecode.pyc",
9999
"file_type": "python_bytecode"
100100
}
101-
},
102-
{
103-
"type": "SuspiciousFile",
104-
"message": "A potentially suspicious file has been found",
105-
"tags": ["hidden_file"],
106-
"extra": {
107-
"file_name": ".pypirc",
108-
"file_type": "hidden_file"
109-
}
110-
},
111-
{
112-
"type": "SensitiveFile",
113-
"message": "A potentially sensitive file has been found",
114-
"tags": ["sensitive_file"],
115-
"extra": {
116-
"file_name": ".pypirc"
117-
}
118101
}
119102
]
120103

0 commit comments

Comments
 (0)