Skip to content

Commit 5f9c23b

Browse files
committed
Add nonce to embedded script references.
This should allow these scripts to execute with a nonce-.... content security policy (csp). However there is still a lot of inline javascript that a web developer needs to look at and rewrite the inline javascript (onsubmit, onclick ..) to be applied by a nonce authorized javascript library that adds event listeners. Ref: https://csp.withgoogle.com/docs/adopting-csp.html#refactor-inline-event-handlers-and-javascript-uris
1 parent d887492 commit 5f9c23b

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

roundup/cgi/KeywordsExpr.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<h3>Keyword Expression Editor:</h3>
66
<hr/>
77
<div id="content"></div>
8-
<script type="text/javascript">
8+
<script nonce="%(nonce)s" type="text/javascript">
99
<!--
1010
1111
var NOT_OP = "-2";
@@ -265,7 +265,8 @@ def render_keywords_expression_editor(request):
265265
window_content = WINDOW_CONTENT % {
266266
'prop' : prop,
267267
'keywords': items_to_keywords(list_nodes(request)),
268-
'original': ''
268+
'original': '',
269+
'nonce': request.client.client_nonce
269270
}
270271

271272
return window_content

roundup/cgi/actions.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -998,9 +998,10 @@ def finishRego(self):
998998
# to want to reload the page, or something)
999999
return '''<html><head><title>%s</title></head>
10001000
<body><p><a href="%s">%s</a></p>
1001-
<script type="text/javascript">
1001+
<script nonce="%s" type="text/javascript">
10021002
window.setTimeout('window.location = "%s"', 1000);
1003-
</script>'''%(message, url, message, url)
1003+
</script>'''%(message, url, message,
1004+
self.client.client_nonce, url)
10041005

10051006
class ConfRegoAction(RegoCommon):
10061007
def handle(self):

roundup/cgi/templating.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2904,7 +2904,7 @@ def indexargs_url(self, url, args):
29042904

29052905
def base_javascript(self):
29062906
return """
2907-
<script type="text/javascript">
2907+
<script nonce="%s" type="text/javascript">
29082908
submitted = false;
29092909
function submit_once() {
29102910
if (submitted) {
@@ -2920,7 +2920,7 @@ def base_javascript(self):
29202920
HelpWin.focus ()
29212921
}
29222922
</script>
2923-
"""%self.base
2923+
"""%(self._client.client_nonce,self.base)
29242924

29252925
def batch(self, permission='View'):
29262926
""" Return a batch object for results from the "current search"

0 commit comments

Comments
 (0)