FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
codeql/python/ql/src/Variables/UndefinedExport.ql at codeql-cli/v2.15.4 · github/codeql · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
github
/
codeql
Public
Notifications
You must be signed in to change notification settings
Fork
2.1k
Star
10k
Code
Issues
997
Pull requests
457
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
codeql
/
python
/
ql
/
src
/
Variables
/
UndefinedExport.ql
Copy path
More file actions
More file actions
Latest commit
History
History
History
81 lines (75 loc) · 2.72 KB
Breadcrumbs
codeql
/
python
/
ql
/
src
/
Variables
/
UndefinedExport.ql
Copy path
File metadata and controls
81 lines (75 loc) · 2.72 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
* @name Explicit export is not defined
* @description Including an undefined attribute in `__all__` causes an exception when
* the module is imported using '*'
* @kind problem
* @tags reliability
* maintainability
* @problem.severity error
* @sub-severity low
* @precision high
* @id py/undefined-export
*/
import
python
/** Whether name is declared in the __all__ list of this module */
predicate
declaredInAll
(
Module
m
,
StrConst
name
)
{
exists
(
Assign
a
,
GlobalVariable
all
|
a
.
defines
(
all
)
and
a
.
getScope
(
)
=
m
and
all
.
getId
(
)
=
"__all__"
and
a
.
getValue
(
)
.
(
List
)
.
getAnElt
(
)
=
name
)
}
predicate
mutates_globals
(
ModuleValue
m
)
{
exists
(
CallNode
globals
|
globals
=
Value
::
named
(
"globals"
)
.
(
FunctionValue
)
.
getACall
(
)
and
globals
.
getScope
(
)
=
m
.
getScope
(
)
|
exists
(
AttrNode
attr
|
attr
.
getObject
(
)
=
globals
)
or
exists
(
SubscriptNode
sub
|
sub
.
getObject
(
)
=
globals
and
sub
.
isStore
(
)
)
)
or
// Enum (added in 3.4) has method `_convert_` that alters globals
// This was called `_convert` until 3.8, but that name will be removed in 3.9
exists
(
ClassValue
enum_class
|
enum_class
.
getASuperType
(
)
=
Value
::
named
(
"enum.Enum"
)
and
(
// In Python < 3.8, Enum._convert can be found with points-to
exists
(
Value
enum_convert
|
enum_convert
=
enum_class
.
attr
(
"_convert"
)
and
exists
(
CallNode
call
|
call
.
getScope
(
)
=
m
.
getScope
(
)
|
enum_convert
.
getACall
(
)
=
call
or
call
.
getFunction
(
)
.
pointsTo
(
enum_convert
)
)
)
or
// In Python 3.8, Enum._convert_ is implemented using a metaclass, and our points-to
// analysis doesn't handle that well enough. So we need a special case for this
not
exists
(
enum_class
.
attr
(
"_convert"
)
)
and
exists
(
CallNode
call
|
call
.
getScope
(
)
=
m
.
getScope
(
)
|
call
.
getFunction
(
)
.
(
AttrNode
)
.
getObject
(
[
"_convert"
,
"_convert_"
]
)
.
pointsTo
(
)
=
enum_class
)
)
)
}
predicate
is_exported_submodule_name
(
ModuleValue
m
,
string
exported_name
)
{
m
.
getScope
(
)
.
getShortName
(
)
=
"__init__"
and
exists
(
m
.
getScope
(
)
.
getPackage
(
)
.
getSubModule
(
exported_name
)
)
}
predicate
contains_unknown_import_star
(
ModuleValue
m
)
{
exists
(
ImportStarNode
imp
|
imp
.
getEnclosingModule
(
)
=
m
.
getScope
(
)
|
imp
.
getModule
(
)
.
pointsTo
(
)
.
isAbsent
(
)
or
not
exists
(
imp
.
getModule
(
)
.
pointsTo
(
)
)
)
}
from
ModuleValue
m
,
StrConst
name
,
string
exported_name
where
declaredInAll
(
m
.
getScope
(
)
,
name
)
and
exported_name
=
name
.
getText
(
)
and
not
m
.
hasAttribute
(
exported_name
)
and
not
is_exported_submodule_name
(
m
,
exported_name
)
and
not
contains_unknown_import_star
(
m
)
and
not
mutates_globals
(
m
)
select
name
,
"The name '"
+
exported_name
+
"' is exported by __all__ but is not defined."
Back
|
FazBrowse Home
|
New Git URL