Skip to content

Commit

Permalink
Regression coverage for Issue 52402 (#2299)
Browse files Browse the repository at this point in the history
  • Loading branch information
labkey-nicka authored Feb 26, 2025
1 parent e06107a commit 9a31c42
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
15 changes: 15 additions & 0 deletions modules/simpletest/resources/views/encodeButton.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<input id="firstName" type="text" value="<script>alert('XSS Input Success')</script><span>Loading XSS</span>" />
<button class="btn btn-primary input-test" data-loading-text="<span>I'm Loading</span>" type="button">
Attempt XSS injection
</button>
<script type="text/javascript" nonce="<%=scriptNonce%>">
// Issue 52402: Verify the "loadingText" attribute for a bootstrap button() is properly encoded.
// See ClientAPITest.testBootstrapButtonEncoding
$(function () {
$('.input-test').click(function () {
let inputValue = $('#firstName').val();
$(this).data('loadingText', inputValue);
$(this).button('loading', inputValue);
});
});
</script>
5 changes: 5 additions & 0 deletions modules/simpletest/resources/views/encodeButton.view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<view xmlns="http://labkey.org/data/xml/view">
<dependencies>
<dependency path="internal/jQuery" />
</dependencies>
</view>
15 changes: 15 additions & 0 deletions src/org/labkey/test/tests/ClientAPITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1546,6 +1546,21 @@ public void suggestedColumnsInQueryDetailsTest() throws Exception
columns.stream().noneMatch(col -> col.getName().equalsIgnoreCase("Container")));
}

@Test
public void testBootstrapButtonEncoding()
{
assumeTestModules();

beginAt(WebTestHelper.buildURL("simpletest", getProjectName(), "encodeButton"));
var buttonLocator = Locator.tagWithClass("button", "input-test");
waitForElement(buttonLocator);

// Prior to the patch for Issue 52402 clicking the button would result in a XSS injection
// which would result in an UnhandledAlertException.
click(buttonLocator);
waitForElement(Locator.buttonContainingText("<script>alert('XSS Input Success')</script><span>Loading XSS</span>"));
}

@Override
public BrowserType bestBrowser()
{
Expand Down

0 comments on commit 9a31c42

Please sign in to comment.