Skip to content

Commit 73521e2

Browse files
authored
Merge pull request github#5791 from tausbn/python-limit-absolute-imports
Python: Limit absolute imports
2 parents 310baab + 4ae3a23 commit 73521e2

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

python/ql/src/semmle/python/Module.qll

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,15 @@ private string moduleNameFromBase(Container file) {
212212
private predicate transitively_imported_from_entry_point(File file) {
213213
file.getExtension().matches("%py%") and
214214
exists(File importer |
215+
// Only consider files that are in the source archive
216+
exists(importer.getRelativePath()) and
215217
importer.getParent() = file.getParent() and
216-
exists(ImportExpr i | i.getLocation().getFile() = importer and i.getName() = file.getStem())
218+
exists(ImportExpr i |
219+
i.getLocation().getFile() = importer and
220+
i.getName() = file.getStem() and
221+
// Disregard relative imports
222+
i.getLevel() = 0
223+
)
217224
|
218225
importer.isPossibleEntryPoint() or transitively_imported_from_entry_point(importer)
219226
)

0 commit comments

Comments
 (0)