This is an automated email from the ASF dual-hosted git repository. mraible pushed a commit to branch entry-comments-link-6.1.x in repository https://gitbox.apache.org/repos/asf/roller.git
commit d1826ebd8c823ddc91dfe34a8243f6c76d64d7d6 Author: Matt Raible <[email protected]> AuthorDate: Wed Nov 25 15:46:56 2026 -0700 Keep the parameters of links that are escaped twice The Edit Entry sidebar's "Comments [n]" link, the media sidebar's "Add Media File" link and the two buttons on the upload-complete page built their URLs with <s:url>, which writes "&" as "&", and then wrote them through <s:property> or an <s:text> argument, which escape it again. The browser got "&" in the URL, so every parameter after the first was lost and the comments link ended on Permission Denied. These URLs now use escapeAmp="false", so they are escaped once. The upload-complete buttons also called window.load(), which doesn't exist, so they now go to their URL and no longer submit the form. JspOutputEncodingTest checks that a URL with more than one parameter isn't escaped twice. --- CHANGES.md | 3 ++ .../webapp/WEB-INF/jsps/editor/EntrySidebar.jsp | 2 +- .../WEB-INF/jsps/editor/MediaFileAddSuccess.jsp | 8 ++--- .../WEB-INF/jsps/editor/MediaFileSidebar.jsp | 2 +- .../ui/struts2/util/JspOutputEncodingTest.java | 34 ++++++++++++++++++++++ 5 files changed, 43 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 789f5df79..897fe7e57 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -136,6 +136,9 @@ on the Comments page left the filter form with a used-up form token, so filtering then failed with an error. - **Media filenames keep their punctuation** when inserted into an entry. +- **"Upload more" and "Cancel" work after a media upload.** Both buttons on + the upload-complete page failed with a script error instead of opening the + upload form or the media folder. - **Changing a password ends the account's other sessions.** Saving a new password in the profile, an administrator's reset, or disabling an account now logs out that user's other browsers at their next Roller UI page; the diff --git a/app/src/main/webapp/WEB-INF/jsps/editor/EntrySidebar.jsp b/app/src/main/webapp/WEB-INF/jsps/editor/EntrySidebar.jsp index ee56faf60..2aeb582cc 100644 --- a/app/src/main/webapp/WEB-INF/jsps/editor/EntrySidebar.jsp +++ b/app/src/main/webapp/WEB-INF/jsps/editor/EntrySidebar.jsp @@ -28,7 +28,7 @@ <h3><s:text name="weblogEdit.comments" /></h3> <s:if test="bean.commentCount > 0"> - <s:url action="comments" var="commentsURL"> + <s:url action="comments" var="commentsURL" escapeAmp="false"> <s:param name="bean.entryId" value="bean.id" /> <s:param name="weblog" value="weblog" /> </s:url> diff --git a/app/src/main/webapp/WEB-INF/jsps/editor/MediaFileAddSuccess.jsp b/app/src/main/webapp/WEB-INF/jsps/editor/MediaFileAddSuccess.jsp index 707d96a21..d1e0f0fac 100644 --- a/app/src/main/webapp/WEB-INF/jsps/editor/MediaFileAddSuccess.jsp +++ b/app/src/main/webapp/WEB-INF/jsps/editor/MediaFileAddSuccess.jsp @@ -154,12 +154,12 @@ <%-- buttons for create new weblog, cancel and upload more --%> <div> - <s:url var="mediaFileAddURL" action="mediaFileAdd"> + <s:url var="mediaFileAddURL" action="mediaFileAdd" escapeAmp="false"> <s:param name="weblog" value="%{actionWeblog.handle}"/> <s:param name="directoryName" value="%{directoryName}"/> </s:url> - <s:url var="mediaFileViewURL" action="mediaFileView"> + <s:url var="mediaFileViewURL" action="mediaFileView" escapeAmp="false"> <s:param name="weblog" value="%{actionWeblog.handle}"/> <s:param name="directoryId" value="%{bean.directoryId}"/> </s:url> @@ -167,11 +167,11 @@ <s:submit cssClass="btn btn-success" id="submit" value="%{getText('mediaFileSuccess.createPost')}" action="entryAddWithMediaFile"/> - <button class="btn btn-default" data-url="<s:property value="%{mediaFileAddURL}"/>" onclick="window.load(this.dataset.url)"> + <button type="button" class="btn btn-default" data-url="<s:property value="%{mediaFileAddURL}"/>" onclick="window.location = this.dataset.url"> <s:text name="mediaFileSuccess.uploadMore"/> </button> - <button class="btn" data-url="<s:property value="%{mediaFileViewURL}"/>" onclick="window.load(this.dataset.url)"> + <button type="button" class="btn" data-url="<s:property value="%{mediaFileViewURL}"/>" onclick="window.location = this.dataset.url"> <s:text name="generic.cancel"/> </button> </div> diff --git a/app/src/main/webapp/WEB-INF/jsps/editor/MediaFileSidebar.jsp b/app/src/main/webapp/WEB-INF/jsps/editor/MediaFileSidebar.jsp index 29eee599e..90641c71b 100644 --- a/app/src/main/webapp/WEB-INF/jsps/editor/MediaFileSidebar.jsp +++ b/app/src/main/webapp/WEB-INF/jsps/editor/MediaFileSidebar.jsp @@ -26,7 +26,7 @@ <div style="clear:right"> <span class="glyphicon glyphicon-picture"></span> - <s:url var="mediaFileAddURL" action="mediaFileAdd"> + <s:url var="mediaFileAddURL" action="mediaFileAdd" escapeAmp="false"> <s:param name="weblog" value="%{actionWeblog.handle}"/> <s:param name="directoryName" value="%{directoryName}"/> </s:url> diff --git a/app/src/test/java/org/apache/roller/weblogger/ui/struts2/util/JspOutputEncodingTest.java b/app/src/test/java/org/apache/roller/weblogger/ui/struts2/util/JspOutputEncodingTest.java index 0b945f03b..5c641e177 100644 --- a/app/src/test/java/org/apache/roller/weblogger/ui/struts2/util/JspOutputEncodingTest.java +++ b/app/src/test/java/org/apache/roller/weblogger/ui/struts2/util/JspOutputEncodingTest.java @@ -53,6 +53,8 @@ class JspOutputEncodingTest { Pattern.compile("<s:property\\b[^>]*>", Pattern.DOTALL); private static final Pattern SINGLE_QUOTED_ATTRIBUTE = Pattern.compile("[\\w:.-]+\\s*=\\s*'[^']*<s:property", Pattern.DOTALL); + private static final Pattern URL_WITH_BODY = + Pattern.compile("<s:url\\b((?:[^>/]|/(?!>))*)>(.*?)</s:url>", Pattern.DOTALL); private static final Pattern INLINE_HANDLER_PROPERTY = Pattern.compile("(?<![\\w:.-])on[a-z]+\\s*=\\s*\"[^\"]*<s:property", Pattern.DOTALL | Pattern.CASE_INSENSITIVE); @@ -134,6 +136,38 @@ class JspOutputEncodingTest { assertEquals(Collections.emptyList(), problems); } + /** + * {@code <s:url>} writes "&" as "&" unless escapeAmp is false, and + * {@code <s:property>} and the {@code <s:param>} strings of an + * {@code <s:text>} escape it again. A link built that way reaches the + * browser with "&" in it and loses every parameter after the first. + */ + @Test + void urlsWithParamsAreNotEscapedTwice() throws IOException { + List<String> problems = new ArrayList<>(); + for (Path jsp : jsps) { + String text = read(jsp); + Matcher url = URL_WITH_BODY.matcher(text); + while (url.find()) { + Matcher var = Pattern.compile("\\bvar=\"([^\"]+)\"").matcher(url.group(1)); + if (!var.find() || url.group(1).contains("escapeAmp=\"false\"") + || url.group(2).split("<s:param\\b", -1).length < 3) { + continue; + } + Pattern use = Pattern.compile("<s:(property|param)\\b[^>]*value=[\"'](%\\{)?" + + Pattern.quote(var.group(1)) + "\\}?[\"'][^>]*>"); + Matcher written = use.matcher(text); + while (written.find()) { + if (!written.group().contains("escapeHtml=\"false\"")) { + problems.add(name(jsp) + ": " + var.group(1)); + break; + } + } + } + } + assertEquals(Collections.emptyList(), problems); + } + private static String read(Path jsp) throws IOException { return new String(Files.readAllBytes(jsp), StandardCharsets.UTF_8); }
