FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pyt/pyt/trigger_definitions_parser.py at 8githubScanRefactor · python-security/pyt · GitHub
python-security
pyt
Repository navigation
Code
Issues
26
(26)
Pull requests
2
(2)
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
pyt
/
pyt
/
trigger_definitions_parser.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
55 lines (45 loc) · 1.65 KB
Breadcrumbs
pyt
/
pyt
/
trigger_definitions_parser.py
Copy path
File metadata and controls
55 lines (45 loc) · 1.65 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
import
os
from
collections
import
namedtuple
SANITISER_SEPARATOR
=
'->'
SOURCES_KEYWORD
=
'sources:'
SINKS_KEYWORD
=
'sinks:'
Definitions
=
namedtuple
(
'Definitions'
,
'sources sinks'
)
default_trigger_word_file
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'trigger_definitions'
,
'flask_trigger_words.pyt'
)
def
parse_section
(
iterator
):
"""Parse a section of a file. Stops at empty line.
Args:
iterator(File): file descriptor pointing at a definition file.
Returns:
Iterator of all definitions in the section.
"""
try
:
line
=
next
(
iterator
).
rstrip
()
while
line
:
if
line
.
rstrip
():
if
SANITISER_SEPARATOR
in
line
:
line
=
line
.
split
(
SANITISER_SEPARATOR
)
sink
=
line
[
0
].
rstrip
()
sanitisers
=
list
(
map
(
str
.
strip
,
line
[
1
].
split
(
','
)))
yield
(
sink
,
sanitisers
)
else
:
yield
(
line
,
list
())
line
=
next
(
iterator
).
rstrip
()
except
StopIteration
:
return
def
parse
(
trigger_word_file
=
default_trigger_word_file
):
"""Parse the file for source and sink definitions.
Returns:
A definitions tuple with sources and sinks.
"""
sources
=
list
()
sinks
=
list
()
with
open
(
trigger_word_file
,
'r'
)
as
fd
:
for
line
in
fd
:
line
=
line
.
rstrip
()
if
line
==
SOURCES_KEYWORD
:
sources
=
list
(
parse_section
(
fd
))
elif
line
==
SINKS_KEYWORD
:
sinks
=
list
(
parse_section
(
fd
))
return
Definitions
(
sources
,
sinks
)
Back
|
FazBrowse Home
|
New Git URL