Skip to content

Commit ab2575e

Browse files
Escape HTML in LDKController to prevent XSS (#288)
## Rationale Two spots in LDKController rendered untrusted content as raw HTML. The container-scoped-table inspection view is a correction to a previous security fix (#268): the HTMLView cleanup there wrapped the whole string in HtmlString.of, which escaped the literal <br>/<p> markup too — safe, but it broke the intended formatting. This escapes only the dynamic validation messages (which can contain arbitrary content from direct DB inserts that bypass the user schema) while preserving the markup. The invalid-redirect error message separately echoed the user-supplied URL via HtmlString.unsafe, so it is now escaped. ## Related Pull Requests - #268 ## Changes - Container-scoped-table inspection view: escape each validation message with PageFlowUtil.filter before joining with <br>, then wrap the assembled markup in HtmlString.unsafe — fixing the over-escaping introduced by #268 while keeping the output safe. - Invalid-redirect error message: switch the user-supplied URL from HtmlString.unsafe to HtmlString.of so it is escaped.
1 parent 5a5bd07 commit ab2575e

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

LDK/src/org/labkey/ldk/LDKController.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
import java.util.Map;
9393
import java.util.Set;
9494
import java.util.function.Predicate;
95+
import java.util.stream.Collectors;
9596

9697
public class LDKController extends SpringActionController
9798
{
@@ -439,9 +440,9 @@ public ModelAndView getView(Object form, BindException errors) throws Exception
439440
List<String> messages = service.validateContainerScopedTables(false);
440441

441442
String sb = "This page is designed to inspect all registered container scoped tables and report any tables with duplicate keys in the same container. This should be enforced by the user schema; however, direct DB inserts will bypass this check.<p>" +
442-
StringUtils.join(messages, "<br>");
443+
messages.stream().map(PageFlowUtil::filter).collect(Collectors.joining("<br>"));
443444

444-
return new HtmlView(HtmlString.of(sb));
445+
return new HtmlView(HtmlString.unsafe(sb));
445446
}
446447

447448
@Override
@@ -912,7 +913,7 @@ public ModelAndView getView(Object form, BindException errors) throws Exception
912913
}
913914
catch (URISyntaxException e)
914915
{
915-
return new HtmlView(HtmlString.unsafe("Invalid redirect URL set: " + urlString));
916+
return new HtmlView(HtmlString.of("Invalid redirect URL set: " + urlString));
916917
}
917918
}
918919
}

0 commit comments

Comments
 (0)