-
Notifications
You must be signed in to change notification settings - Fork 7
A couple more CSP enhancements #6809
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
labkey-adam
wants to merge
7
commits into
release25.7-SNAPSHOT
Choose a base branch
from
fb_csp_issues
base: release25.7-SNAPSHOT
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ae225f1
A couple more CSP enhancements
labkey-adam 29abbc2
Accommodate nonce substitution when rendering outside a request
labkey-adam 26c7162
Bump the expected removal version for a couple deprecated features
labkey-adam b2eb45f
Merge remote-tracking branch 'origin/develop' into fb_csp_issues
labkey-tchad fc4be17
Merge remote-tracking branch 'origin/develop' into fb_csp_issues
labkey-tchad 72d1611
Use non-deprecated registration method. Update unregister() signature…
labkey-adam 826c688
Merge remote-tracking branch 'origin/develop' into fb_csp_issues
labkey-tchad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3156,4 +3156,51 @@ public static HtmlString getDataRegionHtmlForPropertyValues(Map<String, String> | |
return HtmlString.unsafe(sb.toString()); | ||
} | ||
|
||
/** | ||
* Convert String containing HTML into a Document, add nonces to all {@code <script>} tags, and turn the Document | ||
* back into a String. | ||
*/ | ||
public static String addScriptNonces(String html) | ||
{ | ||
Document doc = JSoupUtil.convertHtmlToDocument(StringUtils.trimToEmpty(html), false, new LinkedList<>()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Of course this will do various transformations to the code if it is not well-formed. I guess I'm alright with that. |
||
String ret = ""; | ||
if (doc != null) | ||
{ | ||
addScriptNonces(doc); | ||
try | ||
{ | ||
ret = convertNodeToHtml(doc); | ||
} | ||
catch (TransformerException | IOException e) | ||
{ | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
return ret; | ||
} | ||
|
||
/* | ||
* Add nonce attribute to <script> tags in the Document. | ||
* We don't require the <%=scriptNonce%> syntax (as with module HTML view), because we already parsed the page. | ||
* ModuleHtmlView does not parse the page and does a raw regexp substitution. | ||
*/ | ||
public static int addScriptNonces(Document doc) | ||
{ | ||
NodeList nl = doc.getElementsByTagName("script"); | ||
|
||
if (nl.getLength() > 0) | ||
{ | ||
// If rendering outside a request (e.g., search crawler), substitute blank | ||
String nonce = HttpView.hasCurrentView() ? HttpView.currentPageConfig().getScriptNonce().toString() : ""; | ||
|
||
for (int i = 0, length = nl.getLength(); i < length; i++) | ||
{ | ||
Element script = (Element) nl.item(i); | ||
script.setAttribute("nonce", nonce); | ||
} | ||
} | ||
|
||
return nl.getLength(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems fine. I'm curious about all the R caching scenarios, but I think this happens "late".