Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
a864b450
Commit
a864b450
authored
Jun 30, 2017
by
Robert Raposa
Committed by
GitHub
Jun 30, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #15436 from edx/robrap/rename-xss-linter
Rename xss linter.
parents
9329a5e3
b370fe23
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
193 additions
and
193 deletions
+193
-193
cms/static/js/views/pages/container.js
+1
-1
common/lib/xmodule/xmodule/js/src/problem/edit.js
+15
-15
common/lib/xmodule/xmodule/js/src/video/09_video_caption.js
+1
-1
lms/templates/courseware/progress.html
+1
-1
lms/templates/courseware/progress_graph.js
+9
-9
lms/templates/discussion/_thread_list_template.html
+2
-2
openedx/features/course_search/static/course_search/js/views/search_results_view.js
+1
-1
pavelib/paver_tests/test_paver_quality.py
+16
-16
pavelib/paver_tests/test_xsscommitlint.py
+12
-12
pavelib/paver_tests/test_xsslint.py
+40
-40
pavelib/quality.py
+53
-53
scripts/all-tests.sh
+2
-2
scripts/generic-ci-tests.sh
+4
-4
scripts/tests/test_xss_linter.py
+15
-15
scripts/xss-commit-linter.sh
+8
-9
scripts/xss_linter.py
+13
-12
scripts/xsslint_thresholds.json
+0
-0
No files found.
cms/static/js/views/pages/container.js
View file @
a864b450
...
...
@@ -343,7 +343,7 @@ define(['jquery', 'underscore', 'backbone', 'gettext', 'js/views/pages/base_page
updateHtml
:
function
(
element
,
html
)
{
// Replace the element with the new HTML content, rather than adding
// it as child elements.
this
.
$el
=
$
(
html
).
replaceAll
(
element
);
//
safe
-lint: disable=javascript-jquery-insertion
this
.
$el
=
$
(
html
).
replaceAll
(
element
);
//
xss
-lint: disable=javascript-jquery-insertion
}
});
temporaryView
=
new
TemporaryXBlockView
({
...
...
common/lib/xmodule/xmodule/js/src/problem/edit.js
View file @
a864b450
...
...
@@ -344,7 +344,7 @@
for
(
i
=
0
;
i
<
options
.
length
;
i
+=
1
)
{
inner
=
/
\s
*
\|\|(
.*
?)\|\|
/
.
exec
(
options
[
i
]);
if
(
inner
)
{
//
safe
-lint: disable=javascript-concat-html
//
xss
-lint: disable=javascript-concat-html
demandhints
+=
' <hint>'
+
inner
[
1
].
trim
()
+
'</hint>
\
n'
;
}
}
...
...
@@ -601,9 +601,9 @@
hintLine
=
''
;
if
(
textHint
.
hint
)
{
firstAnswer
=
textHint
.
nothint
;
//
safe
-lint: disable=javascript-concat-html
//
xss
-lint: disable=javascript-concat-html
hintLine
=
' <correcthint'
+
textHint
.
labelassign
+
'>'
+
//
safe
-lint: disable=javascript-concat-html
//
xss
-lint: disable=javascript-concat-html
textHint
.
hint
+
'</correcthint>
\
n'
;
}
...
...
@@ -611,16 +611,16 @@
if
(
isRangeToleranceCase
(
firstAnswer
))
{
// [5, 7) or (5, 7), or (1.2345 * (2+3), 7*4 ] - range tolerance case
// = (5*2)*3 should not be used as range tolerance
//
safe
-lint: disable=javascript-concat-html
//
xss
-lint: disable=javascript-concat-html
numericalResponseString
=
'<numericalresponse answer="'
+
firstAnswer
+
'">
\
n'
;
}
else
{
answerData
=
getAnswerData
(
firstAnswer
);
//
safe
-lint: disable=javascript-concat-html
//
xss
-lint: disable=javascript-concat-html
numericalResponseString
=
'<numericalresponse answer="'
+
answerData
.
answer
+
'">
\
n'
;
if
(
answerData
.
default
)
{
//
safe
-lint: disable=javascript-concat-html
//
xss
-lint: disable=javascript-concat-html
numericalResponseString
+=
' <responseparam type="tolerance" default="'
+
//
safe
-lint: disable=javascript-concat-html
//
xss
-lint: disable=javascript-concat-html
answerData
.
default
+
'" />
\
n'
;
}
}
...
...
@@ -644,15 +644,15 @@
}
if
(
additionalTextHint
.
hint
)
{
//
safe
-lint: disable=javascript-concat-html
//
xss
-lint: disable=javascript-concat-html
additionalHintLine
=
'<correcthint'
+
//
safe
-lint: disable=javascript-concat-html
//
xss
-lint: disable=javascript-concat-html
additionalTextHint
.
labelassign
+
'>'
+
//
safe
-lint: disable=javascript-concat-html
//
xss
-lint: disable=javascript-concat-html
additionalTextHint
.
hint
+
'</correcthint>'
;
}
//
safe
-lint: disable=javascript-concat-html
//
xss
-lint: disable=javascript-concat-html
additionalAnswerString
+=
' <additional_answer answer="'
+
orMatch
[
1
]
+
'">'
;
additionalAnswerString
+=
additionalHintLine
;
additionalAnswerString
+=
'</additional_answer>
\
n'
;
...
...
@@ -765,7 +765,7 @@
responseTypesSelector
=
responseTypes
.
join
(
', '
);
// make temporary xml
//
safe
-lint: disable=javascript-concat-html
//
xss
-lint: disable=javascript-concat-html
$xml
=
$
(
$
.
parseXML
(
'<prob>'
+
xml
+
'</prob>'
));
responseType
=
$xml
.
find
(
responseTypesSelector
);
...
...
@@ -783,7 +783,7 @@
}
if
(
beforeInputtype
)
{
//
safe
-lint: disable=javascript-jquery-insert-into-target
//
xss
-lint: disable=javascript-jquery-insert-into-target
responseType
[
0
].
insertBefore
(
child
,
inputtype
);
}
else
{
responseType
[
0
].
appendChild
(
child
);
...
...
@@ -814,11 +814,11 @@
});
finalDemandHints
=
''
;
if
(
demandHintTags
.
length
)
{
//
safe
-lint: disable=javascript-concat-html
//
xss
-lint: disable=javascript-concat-html
finalDemandHints
=
'
\
n<demandhint>
\
n'
+
demandHintTags
.
join
(
''
)
+
'</demandhint>'
;
}
// make all responsetypes descendants of a single problem element
//
safe
-lint: disable=javascript-concat-html
//
xss
-lint: disable=javascript-concat-html
finalXml
=
'<problem>
\
n'
+
responseTypesXML
.
join
(
'
\
n
\
n'
)
+
finalDemandHints
+
'
\
n</problem>'
;
return
finalXml
;
};
...
...
common/lib/xmodule/xmodule/js/src/video/09_video_caption.js
View file @
a864b450
...
...
@@ -747,7 +747,7 @@
HtmlUtils
.
setHtml
(
$
(
$spanEl
),
HtmlUtils
.
HTML
(
text
.
toString
()));
return
$spanEl
.
wrap
(
'<li>'
).
parent
()[
0
];
//
safe
-lint: disable=javascript-jquery-insertion
return
$spanEl
.
wrap
(
'<li>'
).
parent
()[
0
];
//
xss
-lint: disable=javascript-jquery-insertion
};
return
AsyncProcess
.
array
(
captions
,
process
).
done
(
function
(
list
)
{
...
...
lms/templates/courseware/progress.html
View file @
a864b450
...
...
@@ -32,7 +32,7 @@ from django.utils.http import urlquote_plus
<script>
##
This
JavaScript
is
being
HTML
-
escaped
because
it
historically
has
,
and
it
is
not
clear
what
##
the
correct
syntax
is
.
For
safety
,
maintain
the
previous
behavior
.
##
safe
-
lint
:
disable
=
mako
-
invalid
-
js
-
filter
##
xss
-
lint
:
disable
=
mako
-
invalid
-
js
-
filter
$
{
progress_graph
.
body
(
grade_summary
,
course
.
grade_cutoffs
,
"grade-detail-graph"
,
not
course
.
no_grade
,
not
course
.
no_grade
)}
</script>
</
%
block>
...
...
lms/templates/courseware/progress_graph.js
View file @
a864b450
...
...
@@ -64,27 +64,27 @@ $(function () {
categoryData
=
categories
[
section
[
'category'
]
]
##
Because
this
is
Python
(
Mako
)
embedded
in
JavaScript
,
our
safe
linting
script
is
##
Because
this
is
Python
(
Mako
)
embedded
in
JavaScript
,
our
xss
linting
script
is
##
thoroughly
confused
.
We
should
rewrite
this
file
to
remove
Python
/
Mako
.
##
safe
-
lint
:
disable
=
javascript
-
jquery
-
append
##
xss
-
lint
:
disable
=
javascript
-
jquery
-
append
categoryData
[
'data'
].
append
(
[
tickIndex
,
section
[
'percent'
]]
)
##
Note
that
some
courses
had
stored
images
in
the
Abbreviation
.
We
are
no
longer
##
allowing
the
display
of
such
images
,
and
remove
any
previously
stored
HTML
##
to
prevent
ugly
HTML
from
being
shown
to
learners
.
##
safe
-
lint
:
disable
=
javascript
-
jquery
-
append
##
xss
-
lint
:
disable
=
javascript
-
jquery
-
append
ticks
.
append
(
[
tickIndex
,
bleach
.
clean
(
section
[
'label'
],
tags
=
[],
strip
=
True
)]
)
if
section
[
'category'
]
in
detail_tooltips
:
##
safe
-
lint
:
disable
=
javascript
-
jquery
-
append
##
xss
-
lint
:
disable
=
javascript
-
jquery
-
append
detail_tooltips
[
section
[
'category'
]
].
append
(
section
[
'detail'
]
)
else
:
detail_tooltips
[
section
[
'category'
]
]
=
[
section
[
'detail'
],
]
if
'mark'
in
section
:
##
safe
-
lint
:
disable
=
javascript
-
jquery
-
append
##
xss
-
lint
:
disable
=
javascript
-
jquery
-
append
droppedScores
.
append
(
[
tickIndex
,
0.05
]
)
##
safe
-
lint
:
disable
=
javascript
-
jquery
-
append
##
xss
-
lint
:
disable
=
javascript
-
jquery
-
append
dropped_score_tooltips
.
append
(
section
[
'mark'
][
'detail'
]
)
tickIndex
+=
1
...
...
@@ -107,7 +107,7 @@ $(function () {
else
:
color
=
colors
[
extraColorIndex
%
len
(
colors
)
]
extraColorIndex
+=
1
##
safe
-
lint
:
disable
=
javascript
-
jquery
-
append
##
xss
-
lint
:
disable
=
javascript
-
jquery
-
append
series
.
append
({
'label'
:
section
[
'category'
]
+
"-grade_breakdown"
,
'data'
:
[
[
overviewBarX
,
section
[
'percent'
]]
],
...
...
@@ -131,7 +131,7 @@ $(function () {
descending_grades
=
sorted
(
grade_cutoffs
,
key
=
lambda
x
:
grade_cutoffs
[
x
],
reverse
=
True
)
for
grade
in
descending_grades
:
percent
=
grade_cutoffs
[
grade
]
##
safe
-
lint
:
disable
=
javascript
-
jquery
-
append
##
xss
-
lint
:
disable
=
javascript
-
jquery
-
append
grade_cutoff_ticks
.
append
(
[
percent
,
u
"{0} {1:.0%}"
.
format
(
grade
,
percent
)
]
)
else
:
grade_cutoff_ticks
=
[
]
...
...
@@ -284,7 +284,7 @@ $(function () {
edx
.
HtmlUtils
.
append
(
$grade_detail_graph
,
edx
.
HtmlUtils
.
joinHtml
(
//
safe
-lint: disable=javascript-concat-html
//
xss
-lint: disable=javascript-concat-html
edx
.
HtmlUtils
.
HTML
(
'<div class="overallGrade" style="position:absolute;left:'
+
(
o
.
left
-
12
)
+
'px;top:'
+
(
o
.
top
-
20
)
+
'px">'
),
edx
.
HtmlUtils
.
HTML
(
'<span class=sr>'
),
gettext
(
'Overall Score'
),
...
...
lms/templates/discussion/_thread_list_template.html
View file @
a864b450
...
...
@@ -20,7 +20,7 @@
<
option
value
=
"flagged"
>
$
{
_
(
"Flagged"
)}
<
/option
>
%
endif
<
/select
>
##
safe
-
lint
:
disable
=
python
-
parse
-
error
,
python
-
wrap
-
html
##
xss
-
lint
:
disable
=
python
-
parse
-
error
,
python
-
wrap
-
html
<
/label>${"<% if
(
isDiscussionDivisionEnabled && isPrivilegedUser
)
{ %>" | n, decode.utf8}<label class="forum-nav-filter-cohort"
>
##
Translators
:
This
labels
a
group
menu
in
forum
navigation
<
span
class
=
"sr"
>
$
{
_
(
"Group:"
)}
<
/span
>
...
...
@@ -31,7 +31,7 @@
<option value="${group['
id
']}">${group['
name
']}</option>
%endfor
</select>
##
safe
-lint: disable=python-parse-error,python-wrap-html
##
xss
-lint: disable=python-parse-error,python-wrap-html
</label>${"<% } %>" | n, decode.utf8}<label class="forum-nav-sort">
## Translators: This labels a sort menu in forum navigation
<span class="sr">${_("Sort:")}</span>
...
...
openedx/features/course_search/static/course_search/js/views/search_results_view.js
View file @
a864b450
...
...
@@ -59,7 +59,7 @@
});
return
item
.
render
().
el
;
},
this
);
//
safe
-lint: disable=javascript-jquery-append
//
xss
-lint: disable=javascript-jquery-append
this
.
$el
.
find
(
'ol'
).
append
(
items
);
},
...
...
pavelib/paver_tests/test_paver_quality.py
View file @
a864b450
...
...
@@ -63,7 +63,7 @@ class TestPaverQualityViolations(unittest.TestCase):
class
TestPaverReportViolationsCounts
(
unittest
.
TestCase
):
"""
For testing utility functions for getting counts from reports for
run_eslint, run_complexity, run_
safelint, and run_safecommit_repor
t.
run_eslint, run_complexity, run_
xsslint, and run_xsscommitlin
t.
"""
def
setUp
(
self
):
...
...
@@ -136,9 +136,9 @@ class TestPaverReportViolationsCounts(unittest.TestCase):
actual_count
=
pavelib
.
quality
.
_get_count_from_last_line
(
self
.
f
.
name
,
"foo"
)
# pylint: disable=protected-access
self
.
assertEqual
(
actual_count
,
None
)
def
test_get_
safe
lint_counts_happy
(
self
):
def
test_get_
xss
lint_counts_happy
(
self
):
"""
Test happy path getting violation counts from
safe
lint report.
Test happy path getting violation counts from
xss
lint report.
"""
report
=
textwrap
.
dedent
(
"""
test.html: 30:53: javascript-jquery-append: $('#test').append(print_tos);
...
...
@@ -150,7 +150,7 @@ class TestPaverReportViolationsCounts(unittest.TestCase):
"""
)
with
open
(
self
.
f
.
name
,
'w'
)
as
f
:
f
.
write
(
report
)
counts
=
pavelib
.
quality
.
_get_
safe
lint_counts
(
self
.
f
.
name
)
# pylint: disable=protected-access
counts
=
pavelib
.
quality
.
_get_
xss
lint_counts
(
self
.
f
.
name
)
# pylint: disable=protected-access
self
.
assertDictEqual
(
counts
,
{
'rules'
:
{
'javascript-concat-html'
:
310
,
...
...
@@ -159,9 +159,9 @@ class TestPaverReportViolationsCounts(unittest.TestCase):
'total'
:
2608
,
})
def
test_get_
safe
lint_counts_bad_counts
(
self
):
def
test_get_
xss
lint_counts_bad_counts
(
self
):
"""
Test getting violation counts from truncated and malformed
safe
lint
Test getting violation counts from truncated and malformed
xss
lint
report.
"""
report
=
textwrap
.
dedent
(
"""
...
...
@@ -169,15 +169,15 @@ class TestPaverReportViolationsCounts(unittest.TestCase):
"""
)
with
open
(
self
.
f
.
name
,
'w'
)
as
f
:
f
.
write
(
report
)
counts
=
pavelib
.
quality
.
_get_
safe
lint_counts
(
self
.
f
.
name
)
# pylint: disable=protected-access
counts
=
pavelib
.
quality
.
_get_
xss
lint_counts
(
self
.
f
.
name
)
# pylint: disable=protected-access
self
.
assertDictEqual
(
counts
,
{
'rules'
:
{},
'total'
:
None
,
})
def
test_get_
safecommi
t_count_happy
(
self
):
def
test_get_
xsscommitlin
t_count_happy
(
self
):
"""
Test happy path getting violation count from
safecommi
t report.
Test happy path getting violation count from
xsscommitlin
t report.
"""
report
=
textwrap
.
dedent
(
"""
Linting lms/templates/navigation.html:
...
...
@@ -190,26 +190,26 @@ class TestPaverReportViolationsCounts(unittest.TestCase):
"""
)
with
open
(
self
.
f
.
name
,
'w'
)
as
f
:
f
.
write
(
report
)
count
=
pavelib
.
quality
.
_get_
safecommi
t_count
(
self
.
f
.
name
)
# pylint: disable=protected-access
count
=
pavelib
.
quality
.
_get_
xsscommitlin
t_count
(
self
.
f
.
name
)
# pylint: disable=protected-access
self
.
assertEqual
(
count
,
5
)
def
test_get_
safecommi
t_count_bad_counts
(
self
):
def
test_get_
xsscommitlin
t_count_bad_counts
(
self
):
"""
Test getting violation count from truncated
safecommi
t report.
Test getting violation count from truncated
xsscommitlin
t report.
"""
report
=
textwrap
.
dedent
(
"""
Linting lms/templates/navigation.html:
"""
)
with
open
(
self
.
f
.
name
,
'w'
)
as
f
:
f
.
write
(
report
)
count
=
pavelib
.
quality
.
_get_
safecommi
t_count
(
self
.
f
.
name
)
# pylint: disable=protected-access
count
=
pavelib
.
quality
.
_get_
xsscommitlin
t_count
(
self
.
f
.
name
)
# pylint: disable=protected-access
self
.
assertIsNone
(
count
)
def
test_get_
safecommi
t_count_no_files
(
self
):
def
test_get_
xsscommitlin
t_count_no_files
(
self
):
"""
Test getting violation count from
safecommi
t report where no files were
Test getting violation count from
xsscommitlin
t report where no files were
linted.
"""
report
=
textwrap
.
dedent
(
"""
...
...
@@ -217,7 +217,7 @@ class TestPaverReportViolationsCounts(unittest.TestCase):
"""
)
with
open
(
self
.
f
.
name
,
'w'
)
as
f
:
f
.
write
(
report
)
count
=
pavelib
.
quality
.
_get_
safecommi
t_count
(
self
.
f
.
name
)
# pylint: disable=protected-access
count
=
pavelib
.
quality
.
_get_
xsscommitlin
t_count
(
self
.
f
.
name
)
# pylint: disable=protected-access
self
.
assertEqual
(
count
,
0
)
...
...
pavelib/paver_tests/test_
safecommi
t.py
→
pavelib/paver_tests/test_
xsscommitlin
t.py
View file @
a864b450
"""
Tests for paver
safecommi
t quality tasks
Tests for paver
xsscommitlin
t quality tasks
"""
from
mock
import
patch
from
paver.easy
import
call_task
...
...
@@ -9,36 +9,36 @@ import pavelib.quality
from
.utils
import
PaverTestCase
class
Paver
SafeCommi
tTest
(
PaverTestCase
):
class
Paver
XSSCommitLin
tTest
(
PaverTestCase
):
"""
Test run_
safecommit_repor
t with a mocked environment in order to pass in
Test run_
xsscommitlin
t with a mocked environment in order to pass in
opts.
"""
def
setUp
(
self
):
super
(
Paver
SafeCommi
tTest
,
self
)
.
setUp
()
super
(
Paver
XSSCommitLin
tTest
,
self
)
.
setUp
()
self
.
reset_task_messages
()
@patch.object
(
pavelib
.
quality
,
'_write_metric'
)
@patch.object
(
pavelib
.
quality
,
'_prepare_report_dir'
)
@patch.object
(
pavelib
.
quality
,
'_get_
safecommi
t_count'
)
def
test_
safecommi
t_violation_number_not_found
(
self
,
_mock_count
,
_mock_report_dir
,
_mock_write_metric
):
@patch.object
(
pavelib
.
quality
,
'_get_
xsscommitlin
t_count'
)
def
test_
xsscommitlin
t_violation_number_not_found
(
self
,
_mock_count
,
_mock_report_dir
,
_mock_write_metric
):
"""
run_
safecommit_report encounters an error parsing the safecommi
t output
run_
xsscommitlint encounters an error parsing the xsscommitlin
t output
log.
"""
_mock_count
.
return_value
=
None
with
self
.
assertRaises
(
SystemExit
):
call_task
(
'pavelib.quality.run_
safecommit_repor
t'
)
call_task
(
'pavelib.quality.run_
xsscommitlin
t'
)
@patch.object
(
pavelib
.
quality
,
'_write_metric'
)
@patch.object
(
pavelib
.
quality
,
'_prepare_report_dir'
)
@patch.object
(
pavelib
.
quality
,
'_get_
safecommi
t_count'
)
def
test_
safecommi
t_vanilla
(
self
,
_mock_count
,
_mock_report_dir
,
_mock_write_metric
):
@patch.object
(
pavelib
.
quality
,
'_get_
xsscommitlin
t_count'
)
def
test_
xsscommitlin
t_vanilla
(
self
,
_mock_count
,
_mock_report_dir
,
_mock_write_metric
):
"""
run_
safecommit_repor
t finds violations.
run_
xsscommitlin
t finds violations.
"""
_mock_count
.
return_value
=
0
call_task
(
'pavelib.quality.run_
safecommit_repor
t'
)
call_task
(
'pavelib.quality.run_
xsscommitlin
t'
)
pavelib/paver_tests/test_
safe
lint.py
→
pavelib/paver_tests/test_
xss
lint.py
View file @
a864b450
"""
Tests for paver
safe
lint quality tasks
Tests for paver
xss
lint quality tasks
"""
from
mock
import
patch
from
paver.easy
import
call_task
...
...
@@ -9,110 +9,110 @@ import pavelib.quality
from
.utils
import
PaverTestCase
class
Paver
Safe
LintTest
(
PaverTestCase
):
class
Paver
XSS
LintTest
(
PaverTestCase
):
"""
Test run_
safe
lint with a mocked environment in order to pass in opts
Test run_
xss
lint with a mocked environment in order to pass in opts
"""
def
setUp
(
self
):
super
(
Paver
Safe
LintTest
,
self
)
.
setUp
()
super
(
Paver
XSS
LintTest
,
self
)
.
setUp
()
self
.
reset_task_messages
()
@patch.object
(
pavelib
.
quality
,
'_write_metric'
)
@patch.object
(
pavelib
.
quality
,
'_prepare_report_dir'
)
@patch.object
(
pavelib
.
quality
,
'_get_
safe
lint_counts'
)
def
test_
safe
lint_violation_number_not_found
(
self
,
_mock_counts
,
_mock_report_dir
,
_mock_write_metric
):
@patch.object
(
pavelib
.
quality
,
'_get_
xss
lint_counts'
)
def
test_
xss
lint_violation_number_not_found
(
self
,
_mock_counts
,
_mock_report_dir
,
_mock_write_metric
):
"""
run_
safelint encounters an error parsing the safe
lint output log
run_
xsslint encounters an error parsing the xss
lint output log
"""
_mock_counts
.
return_value
=
{}
with
self
.
assertRaises
(
SystemExit
):
call_task
(
'pavelib.quality.run_
safe
lint'
)
call_task
(
'pavelib.quality.run_
xss
lint'
)
@patch.object
(
pavelib
.
quality
,
'_write_metric'
)
@patch.object
(
pavelib
.
quality
,
'_prepare_report_dir'
)
@patch.object
(
pavelib
.
quality
,
'_get_
safe
lint_counts'
)
def
test_
safe
lint_vanilla
(
self
,
_mock_counts
,
_mock_report_dir
,
_mock_write_metric
):
@patch.object
(
pavelib
.
quality
,
'_get_
xss
lint_counts'
)
def
test_
xss
lint_vanilla
(
self
,
_mock_counts
,
_mock_report_dir
,
_mock_write_metric
):
"""
run_
safe
lint finds violations, but a limit was not set
run_
xss
lint finds violations, but a limit was not set
"""
_mock_counts
.
return_value
=
{
'total'
:
0
}
call_task
(
'pavelib.quality.run_
safe
lint'
)
call_task
(
'pavelib.quality.run_
xss
lint'
)
@patch.object
(
pavelib
.
quality
,
'_write_metric'
)
@patch.object
(
pavelib
.
quality
,
'_prepare_report_dir'
)
@patch.object
(
pavelib
.
quality
,
'_get_
safe
lint_counts'
)
def
test_
safe
lint_invalid_thresholds_option
(
self
,
_mock_counts
,
_mock_report_dir
,
_mock_write_metric
):
@patch.object
(
pavelib
.
quality
,
'_get_
xss
lint_counts'
)
def
test_
xss
lint_invalid_thresholds_option
(
self
,
_mock_counts
,
_mock_report_dir
,
_mock_write_metric
):
"""
run_
safe
lint fails when thresholds option is poorly formatted
run_
xss
lint fails when thresholds option is poorly formatted
"""
_mock_counts
.
return_value
=
{
'total'
:
0
}
with
self
.
assertRaises
(
SystemExit
):
call_task
(
'pavelib.quality.run_
safe
lint'
,
options
=
{
"thresholds"
:
"invalid"
})
call_task
(
'pavelib.quality.run_
xss
lint'
,
options
=
{
"thresholds"
:
"invalid"
})
@patch.object
(
pavelib
.
quality
,
'_write_metric'
)
@patch.object
(
pavelib
.
quality
,
'_prepare_report_dir'
)
@patch.object
(
pavelib
.
quality
,
'_get_
safe
lint_counts'
)
def
test_
safe
lint_invalid_thresholds_option_key
(
self
,
_mock_counts
,
_mock_report_dir
,
_mock_write_metric
):
@patch.object
(
pavelib
.
quality
,
'_get_
xss
lint_counts'
)
def
test_
xss
lint_invalid_thresholds_option_key
(
self
,
_mock_counts
,
_mock_report_dir
,
_mock_write_metric
):
"""
run_
safe
lint fails when thresholds option is poorly formatted
run_
xss
lint fails when thresholds option is poorly formatted
"""
_mock_counts
.
return_value
=
{
'total'
:
0
}
with
self
.
assertRaises
(
SystemExit
):
call_task
(
'pavelib.quality.run_
safe
lint'
,
options
=
{
"thresholds"
:
'{"invalid": 3}'
})
call_task
(
'pavelib.quality.run_
xss
lint'
,
options
=
{
"thresholds"
:
'{"invalid": 3}'
})
@patch.object
(
pavelib
.
quality
,
'_write_metric'
)
@patch.object
(
pavelib
.
quality
,
'_prepare_report_dir'
)
@patch.object
(
pavelib
.
quality
,
'_get_
safe
lint_counts'
)
def
test_
safe
lint_too_many_violations
(
self
,
_mock_counts
,
_mock_report_dir
,
_mock_write_metric
):
@patch.object
(
pavelib
.
quality
,
'_get_
xss
lint_counts'
)
def
test_
xss
lint_too_many_violations
(
self
,
_mock_counts
,
_mock_report_dir
,
_mock_write_metric
):
"""
run_
safe
lint finds more violations than are allowed
run_
xss
lint finds more violations than are allowed
"""
_mock_counts
.
return_value
=
{
'total'
:
4
}
with
self
.
assertRaises
(
SystemExit
):
call_task
(
'pavelib.quality.run_
safe
lint'
,
options
=
{
"thresholds"
:
'{"total": 3}'
})
call_task
(
'pavelib.quality.run_
xss
lint'
,
options
=
{
"thresholds"
:
'{"total": 3}'
})
@patch.object
(
pavelib
.
quality
,
'_write_metric'
)
@patch.object
(
pavelib
.
quality
,
'_prepare_report_dir'
)
@patch.object
(
pavelib
.
quality
,
'_get_
safe
lint_counts'
)
def
test_
safe
lint_under_limit
(
self
,
_mock_counts
,
_mock_report_dir
,
_mock_write_metric
):
@patch.object
(
pavelib
.
quality
,
'_get_
xss
lint_counts'
)
def
test_
xss
lint_under_limit
(
self
,
_mock_counts
,
_mock_report_dir
,
_mock_write_metric
):
"""
run_
safe
lint finds fewer violations than are allowed
run_
xss
lint finds fewer violations than are allowed
"""
_mock_counts
.
return_value
=
{
'total'
:
4
}
# No System Exit is expected
call_task
(
'pavelib.quality.run_
safe
lint'
,
options
=
{
"thresholds"
:
'{"total": 5}'
})
call_task
(
'pavelib.quality.run_
xss
lint'
,
options
=
{
"thresholds"
:
'{"total": 5}'
})
@patch.object
(
pavelib
.
quality
,
'_write_metric'
)
@patch.object
(
pavelib
.
quality
,
'_prepare_report_dir'
)
@patch.object
(
pavelib
.
quality
,
'_get_
safe
lint_counts'
)
def
test_
safe
lint_rule_violation_number_not_found
(
self
,
_mock_counts
,
_mock_report_dir
,
_mock_write_metric
):
@patch.object
(
pavelib
.
quality
,
'_get_
xss
lint_counts'
)
def
test_
xss
lint_rule_violation_number_not_found
(
self
,
_mock_counts
,
_mock_report_dir
,
_mock_write_metric
):
"""
run_
safelint encounters an error parsing the safe
lint output log for a
run_
xsslint encounters an error parsing the xss
lint output log for a
given rule threshold that was set.
"""
_mock_counts
.
return_value
=
{
'total'
:
4
}
with
self
.
assertRaises
(
SystemExit
):
call_task
(
'pavelib.quality.run_
safe
lint'
,
options
=
{
"thresholds"
:
'{"rules": {"javascript-escape": 3}}'
})
call_task
(
'pavelib.quality.run_
xss
lint'
,
options
=
{
"thresholds"
:
'{"rules": {"javascript-escape": 3}}'
})
@patch.object
(
pavelib
.
quality
,
'_write_metric'
)
@patch.object
(
pavelib
.
quality
,
'_prepare_report_dir'
)
@patch.object
(
pavelib
.
quality
,
'_get_
safe
lint_counts'
)
def
test_
safe
lint_too_many_rule_violations
(
self
,
_mock_counts
,
_mock_report_dir
,
_mock_write_metric
):
@patch.object
(
pavelib
.
quality
,
'_get_
xss
lint_counts'
)
def
test_
xss
lint_too_many_rule_violations
(
self
,
_mock_counts
,
_mock_report_dir
,
_mock_write_metric
):
"""
run_
safe
lint finds more rule violations than are allowed
run_
xss
lint finds more rule violations than are allowed
"""
_mock_counts
.
return_value
=
{
'total'
:
4
,
'rules'
:
{
'javascript-escape'
:
4
}}
with
self
.
assertRaises
(
SystemExit
):
call_task
(
'pavelib.quality.run_
safe
lint'
,
options
=
{
"thresholds"
:
'{"rules": {"javascript-escape": 3}}'
})
call_task
(
'pavelib.quality.run_
xss
lint'
,
options
=
{
"thresholds"
:
'{"rules": {"javascript-escape": 3}}'
})
@patch.object
(
pavelib
.
quality
,
'_write_metric'
)
@patch.object
(
pavelib
.
quality
,
'_prepare_report_dir'
)
@patch.object
(
pavelib
.
quality
,
'_get_
safe
lint_counts'
)
def
test_
safe
lint_under_rule_limit
(
self
,
_mock_counts
,
_mock_report_dir
,
_mock_write_metric
):
@patch.object
(
pavelib
.
quality
,
'_get_
xss
lint_counts'
)
def
test_
xss
lint_under_rule_limit
(
self
,
_mock_counts
,
_mock_report_dir
,
_mock_write_metric
):
"""
run_
safe
lint finds fewer rule violations than are allowed
run_
xss
lint finds fewer rule violations than are allowed
"""
_mock_counts
.
return_value
=
{
'total'
:
4
,
'rules'
:
{
'javascript-escape'
:
4
}}
# No System Exit is expected
call_task
(
'pavelib.quality.run_
safe
lint'
,
options
=
{
"thresholds"
:
'{"rules": {"javascript-escape": 5}}'
})
call_task
(
'pavelib.quality.run_
xss
lint'
,
options
=
{
"thresholds"
:
'{"rules": {"javascript-escape": 5}}'
})
pavelib/quality.py
View file @
a864b450
...
...
@@ -321,9 +321,9 @@ def run_eslint(options):
(
"thresholds="
,
"t"
,
"json containing limit for number of acceptable violations per rule"
),
])
@timed
def
run_
safe
lint
(
options
):
def
run_
xss
lint
(
options
):
"""
Runs
safe_template
_linter.py on the codebase
Runs
xss
_linter.py on the codebase
"""
thresholds_option
=
getattr
(
options
,
'thresholds'
,
'{}'
)
...
...
@@ -342,42 +342,42 @@ def run_safelint(options):
)
)
safelint_script
=
"safe_template
_linter.py"
safelint_report_dir
=
(
Env
.
REPORT_DIR
/
"safe
lint"
)
safelint_report
=
safelint_report_dir
/
"safe
lint.report"
_prepare_report_dir
(
safe
lint_report_dir
)
xsslint_script
=
"xss
_linter.py"
xsslint_report_dir
=
(
Env
.
REPORT_DIR
/
"xss
lint"
)
xsslint_report
=
xsslint_report_dir
/
"xss
lint.report"
_prepare_report_dir
(
xss
lint_report_dir
)
sh
(
"{repo_root}/scripts/{
safelint_script} --rule-totals >> {safe
lint_report}"
.
format
(
"{repo_root}/scripts/{
xsslint_script} --rule-totals >> {xss
lint_report}"
.
format
(
repo_root
=
Env
.
REPO_ROOT
,
safelint_script
=
safe
lint_script
,
safelint_report
=
safe
lint_report
,
xsslint_script
=
xss
lint_script
,
xsslint_report
=
xss
lint_report
,
),
ignore_error
=
True
)
safelint_counts
=
_get_safelint_counts
(
safe
lint_report
)
xsslint_counts
=
_get_xsslint_counts
(
xss
lint_report
)
try
:
metrics_str
=
"Number of {
safe
lint_script} violations: {num_violations}
\n
"
.
format
(
safelint_script
=
safelint_script
,
num_violations
=
int
(
safe
lint_counts
[
'total'
])
metrics_str
=
"Number of {
xss
lint_script} violations: {num_violations}
\n
"
.
format
(
xsslint_script
=
xsslint_script
,
num_violations
=
int
(
xss
lint_counts
[
'total'
])
)
if
'rules'
in
safelint_counts
and
any
(
safe
lint_counts
[
'rules'
]):
if
'rules'
in
xsslint_counts
and
any
(
xss
lint_counts
[
'rules'
]):
metrics_str
+=
"
\n
"
rule_keys
=
sorted
(
safe
lint_counts
[
'rules'
]
.
keys
())
rule_keys
=
sorted
(
xss
lint_counts
[
'rules'
]
.
keys
())
for
rule
in
rule_keys
:
metrics_str
+=
"{rule} violations: {count}
\n
"
.
format
(
rule
=
rule
,
count
=
int
(
safe
lint_counts
[
'rules'
][
rule
])
count
=
int
(
xss
lint_counts
[
'rules'
][
rule
])
)
except
TypeError
:
raise
BuildFailure
(
"Error. Number of {
safelint_script} violations could not be found in {safe
lint_report}"
.
format
(
safelint_script
=
safelint_script
,
safelint_report
=
safe
lint_report
"Error. Number of {
xsslint_script} violations could not be found in {xss
lint_report}"
.
format
(
xsslint_script
=
xsslint_script
,
xsslint_report
=
xss
lint_report
)
)
metrics_report
=
(
Env
.
METRICS_DIR
/
"
safe
lint"
)
metrics_report
=
(
Env
.
METRICS_DIR
/
"
xss
lint"
)
# Record the metric
_write_metric
(
metrics_str
,
metrics_report
)
# Print number of violations to log.
...
...
@@ -387,35 +387,35 @@ def run_safelint(options):
# Test total violations against threshold.
if
'total'
in
violation_thresholds
.
keys
():
if
violation_thresholds
[
'total'
]
<
safe
lint_counts
[
'total'
]:
if
violation_thresholds
[
'total'
]
<
xss
lint_counts
[
'total'
]:
error_message
=
"Too many violations total ({count}).
\n
The limit is {violations_limit}."
.
format
(
count
=
safe
lint_counts
[
'total'
],
violations_limit
=
violation_thresholds
[
'total'
]
count
=
xss
lint_counts
[
'total'
],
violations_limit
=
violation_thresholds
[
'total'
]
)
# Test rule violations against thresholds.
if
'rules'
in
violation_thresholds
:
threshold_keys
=
sorted
(
violation_thresholds
[
'rules'
]
.
keys
())
for
threshold_key
in
threshold_keys
:
if
threshold_key
not
in
safe
lint_counts
[
'rules'
]:
if
threshold_key
not
in
xss
lint_counts
[
'rules'
]:
error_message
+=
(
"
\n
Number of {
safe
lint_script} violations for {rule} could not be found in "
"{
safe
lint_report}."
"
\n
Number of {
xss
lint_script} violations for {rule} could not be found in "
"{
xss
lint_report}."
)
.
format
(
safelint_script
=
safelint_script
,
rule
=
threshold_key
,
safelint_report
=
safe
lint_report
xsslint_script
=
xsslint_script
,
rule
=
threshold_key
,
xsslint_report
=
xss
lint_report
)
elif
violation_thresholds
[
'rules'
][
threshold_key
]
<
safe
lint_counts
[
'rules'
][
threshold_key
]:
elif
violation_thresholds
[
'rules'
][
threshold_key
]
<
xss
lint_counts
[
'rules'
][
threshold_key
]:
error_message
+=
\
"
\n
Too many {rule} violations ({count}).
\n
The {rule} limit is {violations_limit}."
.
format
(
rule
=
threshold_key
,
count
=
safe
lint_counts
[
'rules'
][
threshold_key
],
rule
=
threshold_key
,
count
=
xss
lint_counts
[
'rules'
][
threshold_key
],
violations_limit
=
violation_thresholds
[
'rules'
][
threshold_key
],
)
if
error_message
is
not
""
:
raise
BuildFailure
(
"
SafeTemplate
Linter Failed.
\n
{error_message}
\n
"
"See {
safe
lint_report} or run the following command to hone in on the problem:
\n
"
" ./scripts/
safe
-commit-linter.sh -h"
.
format
(
error_message
=
error_message
,
safelint_report
=
safe
lint_report
"
XSS
Linter Failed.
\n
{error_message}
\n
"
"See {
xss
lint_report} or run the following command to hone in on the problem:
\n
"
" ./scripts/
xss
-commit-linter.sh -h"
.
format
(
error_message
=
error_message
,
xsslint_report
=
xss
lint_report
)
)
...
...
@@ -423,42 +423,42 @@ def run_safelint(options):
@task
@needs
(
'pavelib.prereqs.install_python_prereqs'
)
@timed
def
run_
safecommit_repor
t
():
def
run_
xsscommitlin
t
():
"""
Runs
safe
-commit-linter.sh on the current branch.
Runs
xss
-commit-linter.sh on the current branch.
"""
safecommit_script
=
"safe
-commit-linter.sh"
safecommit_report_dir
=
(
Env
.
REPORT_DIR
/
"safecommi
t"
)
safecommit_report
=
safecommit_report_dir
/
"safecommi
t.report"
_prepare_report_dir
(
safecommi
t_report_dir
)
xsscommitlint_script
=
"xss
-commit-linter.sh"
xsscommitlint_report_dir
=
(
Env
.
REPORT_DIR
/
"xsscommitlin
t"
)
xsscommitlint_report
=
xsscommitlint_report_dir
/
"xsscommitlin
t.report"
_prepare_report_dir
(
xsscommitlin
t_report_dir
)
sh
(
"{repo_root}/scripts/{
safecommit_script} | tee {safecommi
t_report}"
.
format
(
"{repo_root}/scripts/{
xsscommitlint_script} | tee {xsscommitlin
t_report}"
.
format
(
repo_root
=
Env
.
REPO_ROOT
,
safecommit_script
=
safecommi
t_script
,
safecommit_report
=
safecommi
t_report
,
xsscommitlint_script
=
xsscommitlin
t_script
,
xsscommitlint_report
=
xsscommitlin
t_report
,
),
ignore_error
=
True
)
safecommit_count
=
_get_safecommit_count
(
safecommi
t_report
)
xsscommitlint_count
=
_get_xsscommitlint_count
(
xsscommitlin
t_report
)
try
:
num_violations
=
int
(
safecommi
t_count
)
num_violations
=
int
(
xsscommitlin
t_count
)
except
TypeError
:
raise
BuildFailure
(
"Error. Number of {
safecommit_script} violations could not be found in {safecommi
t_report}"
.
format
(
safecommit_script
=
safecommit_script
,
safecommit_report
=
safecommi
t_report
"Error. Number of {
xsscommitlint_script} violations could not be found in {xsscommitlin
t_report}"
.
format
(
xsscommitlint_script
=
xsscommitlint_script
,
xsscommitlint_report
=
xsscommitlin
t_report
)
)
# Print number of violations to log.
violations_count_str
=
"Number of {
safecommi
t_script} violations: {num_violations}
\n
"
.
format
(
safecommit_script
=
safecommi
t_script
,
num_violations
=
num_violations
violations_count_str
=
"Number of {
xsscommitlin
t_script} violations: {num_violations}
\n
"
.
format
(
xsscommitlint_script
=
xsscommitlin
t_script
,
num_violations
=
num_violations
)
# Record the metric
metrics_report
=
(
Env
.
METRICS_DIR
/
"
safecommi
t"
)
metrics_report
=
(
Env
.
METRICS_DIR
/
"
xsscommitlin
t"
)
_write_metric
(
violations_count_str
,
metrics_report
)
# Output report to console.
sh
(
"cat {metrics_report}"
.
format
(
metrics_report
=
metrics_report
),
ignore_error
=
True
)
...
...
@@ -534,12 +534,12 @@ def _get_count_from_last_line(filename, file_type):
return
None
def
_get_
safe
lint_counts
(
filename
):
def
_get_
xss
lint_counts
(
filename
):
"""
This returns a dict of violations from the
safe
lint report.
This returns a dict of violations from the
xss
lint report.
Arguments:
filename: The name of the
safe
lint report.
filename: The name of the
xss
lint report.
Returns:
A dict containing the following:
...
...
@@ -566,15 +566,15 @@ def _get_safelint_counts(filename):
return
violations
def
_get_
safecommi
t_count
(
filename
):
def
_get_
xsscommitlin
t_count
(
filename
):
"""
Returns the violation count from the
safecommi
t report.
Returns the violation count from the
xsscommitlin
t report.
Arguments:
filename: The name of the
safecommi
t report.
filename: The name of the
xsscommitlin
t report.
Returns:
The count of
safecommi
t violations, or None if there is a problem.
The count of
xsscommitlin
t violations, or None if there is a problem.
"""
report_contents
=
_get_report_contents
(
filename
)
...
...
scripts/all-tests.sh
View file @
a864b450
...
...
@@ -14,8 +14,8 @@ set -e
export
PYLINT_THRESHOLD
=
3600
export
ESLINT_THRESHOLD
=
10122
SAFELINT_THRESHOLDS
=
`
cat
scripts/safe
lint_thresholds.json
`
export
SAFELINT_THRESHOLDS
=
${
SAFE
LINT_THRESHOLDS
//[[
:space:]]/
}
XSSLINT_THRESHOLDS
=
`
cat
scripts/xss
lint_thresholds.json
`
export
XSSLINT_THRESHOLDS
=
${
XSS
LINT_THRESHOLDS
//[[
:space:]]/
}
doCheckVars
()
{
if
[
-n
"
$CIRCLECI
"
]
;
then
...
...
scripts/generic-ci-tests.sh
View file @
a864b450
...
...
@@ -84,10 +84,10 @@ case "$TEST_SUITE" in
paver run_eslint
-l
$ESLINT_THRESHOLD
>
eslint.log
||
{
cat
eslint.log
;
EXIT
=
1
;
}
echo
"Running code complexity report (python)."
paver run_complexity
||
echo
"Unable to calculate code complexity. Ignoring error."
echo
"Running
safe template
linter report."
paver run_
safelint
-t
$SAFELINT_THRESHOLDS
>
safelint.log
||
{
cat
safe
lint.log
;
EXIT
=
1
;
}
echo
"Running
safe
commit linter report."
paver run_
safecommit_report
>
safecommit.log
||
{
cat
safecommi
t.log
;
EXIT
=
1
;
}
echo
"Running
xss
linter report."
paver run_
xsslint
-t
$XSSLINT_THRESHOLDS
>
xsslint.log
||
{
cat
xss
lint.log
;
EXIT
=
1
;
}
echo
"Running
xss
commit linter report."
paver run_
xsscommitlint
>
xsscommitlint.log
||
{
cat
xsscommitlin
t.log
;
EXIT
=
1
;
}
# Run quality task. Pass in the 'fail-under' percentage to diff-quality
echo
"Running diff quality."
paver run_quality
-p
100
||
EXIT
=
1
...
...
scripts/tests/test_
safe_template
_linter.py
→
scripts/tests/test_
xss
_linter.py
View file @
a864b450
# -*- coding: utf-8 -*-
"""
Tests for
safe_template
_linter.py
Tests for
xss
_linter.py
"""
import
re
import
textwrap
...
...
@@ -10,7 +10,7 @@ from unittest import TestCase
import
mock
from
ddt
import
data
,
ddt
from
scripts.
safe_template
_linter
import
(
from
scripts.
xss
_linter
import
(
FileResults
,
JavaScriptLinter
,
MakoTemplateLinter
,
...
...
@@ -93,7 +93,7 @@ class TestLinter(TestCase):
self
.
assertEqual
(
violation
.
rule
,
rule
)
class
Test
SafeTemplate
Linter
(
TestCase
):
class
Test
XSS
Linter
(
TestCase
):
"""
Test some top-level linter functions
"""
...
...
@@ -107,7 +107,7 @@ class TestSafeTemplateLinter(TestCase):
self
.
patch_is_valid_directory
(
UnderscoreTemplateLinter
)
self
.
patch_is_valid_directory
(
PythonLinter
)
patcher
=
mock
.
patch
(
'scripts.
safe_template
_linter.is_skip_dir'
,
return_value
=
False
)
patcher
=
mock
.
patch
(
'scripts.
xss
_linter.is_skip_dir'
,
return_value
=
False
)
patcher
.
start
()
self
.
addCleanup
(
patcher
.
stop
)
...
...
@@ -548,7 +548,7 @@ class TestMakoTemplateLinter(TestLinter):
# This is anything but a Mako file.
# pragma can appear anywhere in file
#
safe
-lint: disable=mako-missing-default
#
xss
-lint: disable=mako-missing-default
"""
)
linter
.
_check_mako_file_is_safe
(
mako_template
,
results
)
...
...
@@ -566,7 +566,7 @@ class TestMakoTemplateLinter(TestLinter):
mako_template
=
textwrap
.
dedent
(
"""
<
%
page expression_filter="h"/>
##
safe
-lint: disable=mako-unwanted-html-filter
##
xss
-lint: disable=mako-unwanted-html-filter
${x | h}
"""
)
...
...
@@ -982,25 +982,25 @@ class TestUnderscoreTemplateLinter(TestLinter):
@data
(
{
'template'
:
'<
%
//
safe
-lint: disable=underscore-not-escaped
%
>
\n
'
'<
%
//
xss
-lint: disable=underscore-not-escaped
%
>
\n
'
'<
%
= message
%
>'
,
'is_disabled'
:
[
True
],
},
{
'template'
:
'<
%
//
safe
-lint: disable=another-rule,underscore-not-escaped
%
>
\n
'
'<
%
//
xss
-lint: disable=another-rule,underscore-not-escaped
%
>
\n
'
'<
%
= message
%
>'
,
'is_disabled'
:
[
True
],
},
{
'template'
:
'<
%
//
safe
-lint: disable=another-rule
%
>
\n
'
'<
%
//
xss
-lint: disable=another-rule
%
>
\n
'
'<
%
= message
%
>'
,
'is_disabled'
:
[
False
],
},
{
'template'
:
'<
%
//
safe
-lint: disable=underscore-not-escaped
%
>
\n
'
'<
%
//
xss
-lint: disable=underscore-not-escaped
%
>
\n
'
'<
%
= message
%
>
\n
'
'<
%
= message
%
>'
,
'is_disabled'
:
[
True
,
False
],
...
...
@@ -1010,22 +1010,22 @@ class TestUnderscoreTemplateLinter(TestLinter):
'// This test does not use proper Underscore.js Template syntax
\n
'
'// But, it is just testing that a maximum of 5 non-whitespace
\n
'
'// are used to designate start of line for disabling the next line.
\n
'
' 1 2 3 4 5
safe
-lint: disable=underscore-not-escaped
%
>
\n
'
' 1 2 3 4 5
xss
-lint: disable=underscore-not-escaped
%
>
\n
'
'<
%
= message
%
>
\n
'
' 1 2 3 4 5 6
safe
-lint: disable=underscore-not-escaped
%
>
\n
'
' 1 2 3 4 5 6
xss
-lint: disable=underscore-not-escaped
%
>
\n
'
'<
%
= message
%
>'
,
'is_disabled'
:
[
True
,
False
],
},
{
'template'
:
'<
%
= message
%
><
%
//
safe
-lint: disable=underscore-not-escaped
%
>
\n
'
'<
%
= message
%
><
%
//
xss
-lint: disable=underscore-not-escaped
%
>
\n
'
'<
%
= message
%
>'
,
'is_disabled'
:
[
True
,
False
],
},
{
'template'
:
'<
%
= message
%
>
\n
'
'<
%
//
safe
-lint: disable=underscore-not-escaped
%
>'
,
'<
%
//
xss
-lint: disable=underscore-not-escaped
%
>'
,
'is_disabled'
:
[
False
],
},
)
...
...
@@ -1052,7 +1052,7 @@ class TestUnderscoreTemplateLinter(TestLinter):
results
=
FileResults
(
''
)
template
=
textwrap
.
dedent
(
"""
<
%
//
safe
-lint: disable=underscore-not-escaped
%
>
<
%
//
xss
-lint: disable=underscore-not-escaped
%
>
<
%
= message
%
>
<
%
= message
%
>
"""
)
...
...
scripts/
safe
-commit-linter.sh
→
scripts/
xss
-commit-linter.sh
View file @
a864b450
...
...
@@ -3,16 +3,15 @@ set -e
###############################################################################
#
#
safe
-commit-linter.sh
#
xss
-commit-linter.sh
#
# Executes safe_template_linter.py on the set of files in a particular git
# commit.
# Executes xss_linter.py on the set of files in a particular git commit.
#
###############################################################################
show_help
()
{
echo
"Usage:
safe
-commit-linter.sh [OPTION]"
echo
"Runs the
Safe Template
Linter against all files in a git commit."
echo
"Usage:
xss
-commit-linter.sh [OPTION]"
echo
"Runs the
XSS
Linter against all files in a git commit."
echo
""
echo
"Mandatory arguments to long options are mandatory for short options too."
echo
" -h, --help Output this help."
...
...
@@ -24,10 +23,10 @@ show_help() {
echo
"This scripts does not give a grand total. Be sure to check for"
echo
"0 violations on each file."
echo
""
echo
"For more help using the
safe template linter, including details on how
"
echo
"
to
understand and fix any violations, read the docs here:"
echo
"For more help using the
xss linter, including details on how to
"
echo
"understand and fix any violations, read the docs here:"
echo
""
echo
" http://edx.readthedocs.org/projects/edx-developer-guide/en/latest/conventions/
safe_templates.html#safe-template
-linter"
echo
" http://edx.readthedocs.org/projects/edx-developer-guide/en/latest/conventions/
preventing_xss.html#xss
-linter"
}
...
...
@@ -83,6 +82,6 @@ else
for
f
in
$diff_files
;
do
echo
""
echo
"Linting
$f
:"
./scripts/
safe_template
_linter.py
$f
./scripts/
xss
_linter.py
$f
done
fi
scripts/
safe_template
_linter.py
→
scripts/
xss
_linter.py
View file @
a864b450
#!/usr/bin/env python
"""
A linting tool to check
if templates are safe
A linting tool to check
for xss vulnerabilities.
"""
from
__future__
import
print_function
...
...
@@ -192,7 +192,7 @@ class Rules(Enum):
An Enum of each rule which the linter will check.
"""
# IMPORTANT: Do not edit without also updating the docs:
# - http://edx.readthedocs.
io/projects/edx-developer-guide/en/latest/conventions/safe_templates.html#safe-template
-linter
# - http://edx.readthedocs.
org/projects/edx-developer-guide/en/latest/conventions/preventing_xss.html#xss
-linter
mako_missing_default
=
'mako-missing-default'
mako_multiple_page_tags
=
'mako-multiple-page-tags'
mako_unparseable_expression
=
'mako-unparseable-expression'
...
...
@@ -300,7 +300,7 @@ class RuleViolation(object):
Pragma format::
safe
-lint: disable=violation-name,other-violation-name
xss
-lint: disable=violation-name,other-violation-name
Arguments:
string: The string of code in which to search for the pragma.
...
...
@@ -314,7 +314,7 @@ class RuleViolation(object):
found.
"""
pragma_match
=
re
.
search
(
r'
safe
-lint:\s*disable=([a-zA-Z,-]+)'
,
string
)
pragma_match
=
re
.
search
(
r'
xss
-lint:\s*disable=([a-zA-Z,-]+)'
,
string
)
if
pragma_match
is
None
:
return
if
scope_start_string
:
...
...
@@ -398,14 +398,14 @@ class ExpressionRuleViolation(RuleViolation):
Pragma format::
safe
-lint: disable=violation-name,other-violation-name
xss
-lint: disable=violation-name,other-violation-name
Examples::
<
%
//
safe
-lint: disable=underscore-not-escaped
%
>
<
%
//
xss
-lint: disable=underscore-not-escaped
%
>
<
%
= gettext('Single Line')
%
>
<
%
= gettext('Single Line')
%
><
%
//
safe
-lint: disable=underscore-not-escaped
%
>
<
%
= gettext('Single Line')
%
><
%
//
xss
-lint: disable=underscore-not-escaped
%
>
Arguments:
string_lines: A StringLines containing the contents of the file in
...
...
@@ -1421,7 +1421,7 @@ class JavaScriptLinter(BaseLinter):
class
BaseVisitor
(
ast
.
NodeVisitor
):
"""
Base class for AST NodeVisitor used for Python
safe
linting.
Base class for AST NodeVisitor used for Python
xss
linting.
Important: This base visitor skips all __repr__ function definitions.
"""
...
...
@@ -1787,7 +1787,7 @@ class PythonLinter(BaseLinter):
if
file_name
.
lower
()
.
endswith
(
'tests.py'
):
return
results
# skip this linter code (i.e.
safe_template
_linter.py)
# skip this linter code (i.e.
xss
_linter.py)
if
file_name
==
os
.
path
.
basename
(
__file__
):
return
results
...
...
@@ -2493,6 +2493,7 @@ SKIP_DIRS = (
'.git'
,
'.pycharm_helpers'
,
'common/static/xmodule/modules'
,
'common/static/bundles'
,
'perf_tests'
,
'node_modules'
,
'reports/diff_quality'
,
...
...
@@ -2615,11 +2616,11 @@ def main():
Prints all violations.
"""
epilog
=
"For more help using the
safe template linter, including details on how
\n
"
epilog
+=
"
to
understand and fix any violations, read the docs here:
\n
"
epilog
=
"For more help using the
xss linter, including details on how to
\n
"
epilog
+=
"understand and fix any violations, read the docs here:
\n
"
epilog
+=
"
\n
"
# pylint: disable=line-too-long
epilog
+=
" http://edx.readthedocs.org/projects/edx-developer-guide/en/latest/conventions/
safe_templates.html#safe-template
-linter
\n
"
epilog
+=
" http://edx.readthedocs.org/projects/edx-developer-guide/en/latest/conventions/
preventing_xss.html#xss
-linter
\n
"
parser
=
argparse
.
ArgumentParser
(
formatter_class
=
argparse
.
RawDescriptionHelpFormatter
,
...
...
scripts/
safe
lint_thresholds.json
→
scripts/
xss
lint_thresholds.json
View file @
a864b450
File moved
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment