This is an automated email from the ASF dual-hosted git repository.
snoopdave pushed a commit to branch roller-6.1.x
in repository https://gitbox.apache.org/repos/asf/roller.git
The following commit(s) were added to refs/heads/roller-6.1.x by this push:
new 4d2afe572 Keep the parameters of links that are escaped twice (#397)
4d2afe572 is described below
commit 4d2afe5724d9933e1d54035ee83b64fd7d61e56e
Author: Matt Raible <[email protected]>
AuthorDate: Fri Nov 27 06:37:42 2026 -0700
Keep the parameters of links that are escaped twice (#397)
* 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.
* Check every use of a URL escaped twice
The test now also finds uses written as #name or %{#name}, flags uses
escaped for JavaScript (where & would stay in the string), and checks only
the uses between a URL and the next <s:url> that sets the same var. <s:a href>
is not checked, since its template writes href without escaping it again.
---
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 | 44 ++++++++++++++++++++++
5 files changed, 53 insertions(+), 6 deletions(-)
diff --git a/CHANGES.md b/CHANGES.md
index 085f0e673..f7bc2a721 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -142,6 +142,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..63cf9dfa9 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,9 @@ 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 URL_VAR =
Pattern.compile("\\bvar=\"([^\"]+)\"");
private static final Pattern INLINE_HANDLER_PROPERTY =
Pattern.compile("(?<![\\w:.-])on[a-z]+\\s*=\\s*\"[^\"]*<s:property",
Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
@@ -134,6 +137,47 @@ 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 = URL_VAR.matcher(url.group(1));
+ if (!var.find() || url.group(1).contains("escapeAmp=\"false\"")
+ || url.group(2).split("<s:param\\b", -1).length < 3) {
+ continue;
+ }
+ String name = Pattern.quote(var.group(1));
+ // Uses of this URL run until the next <s:url> that sets the
+ // same var. <s:a href="%{name}"> isn't checked: its template
+ // writes href without escaping it again.
+ Matcher redefined = Pattern.compile("<s:url\\b[^>]*\\bvar=\""
+ name + "\"")
+ .matcher(text);
+ int end = redefined.find(url.end()) ? redefined.start() :
text.length();
+ Matcher written =
Pattern.compile("<s:(property|param)\\b[^>]*value=[\"'](%\\{)?#?"
+ + name +
"\\}?[\"'][^>]*>").matcher(text).region(url.end(), end);
+ while (written.find()) {
+ // Unescaped is right in HTML, but escaping for JavaScript
+ // leaves & in the string.
+ if (!written.group().contains("escapeHtml=\"false\"")
+ ||
written.group().contains("escapeJavaScript=\"true\"")) {
+ 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);
}