mraible commented on code in PR #175:
URL: https://github.com/apache/roller/pull/175#discussion_r3891448738


##########
app/src/main/java/org/apache/roller/weblogger/util/EnclosureMetadata.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.roller.weblogger.util;
+
+import java.util.regex.Pattern;
+import org.apache.commons.validator.routines.UrlValidator;
+
+/**
+ * Validated metadata for an RSS or Atom enclosure.
+ */
+public final class EnclosureMetadata {
+
+    private static final UrlValidator URL_VALIDATOR = new UrlValidator(

Review Comment:
   `UrlValidator` rejects any host whose TLD isn't in its IANA list 
(`blog.internal`, `roller.local`, `blog.lan`, `.test`), underscores, and IDN 
hosts; `ALLOW_LOCAL_URLS` only admits single-label hosts like `localhost`. 
Since `MediaFileAddSuccess` pre-fills the enclosure URL from the site's own 
absolute URL, an intranet install can never attach uploaded media as an 
enclosure, and existing entries with such URLs can no longer be re-saved. 
`java.net.URI` with a scheme check (`http` / `https`, non-empty host) is enough 
here; the point is no longer fetching it.



##########
app/src/main/java/org/apache/roller/weblogger/util/EnclosureMetadata.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.roller.weblogger.util;
+
+import java.util.regex.Pattern;
+import org.apache.commons.validator.routines.UrlValidator;
+
+/**
+ * Validated metadata for an RSS or Atom enclosure.
+ */
+public final class EnclosureMetadata {
+
+    private static final UrlValidator URL_VALIDATOR = new UrlValidator(
+            new String[] {"http", "https"}, UrlValidator.ALLOW_LOCAL_URLS);
+
+    private static final Pattern MEDIA_TYPE = Pattern.compile(

Review Comment:
   This admits `&` (and `'`, `` ` ``, `|`), but ``feeds.vm`` lines 52 and 80 
emit `type="$`mc_type`"` without ``escapeXML``, so `audio/mp&eg` passes 
validation and turns the whole RSS and Atom feed into malformed XML. Either 
escape it in ``feeds.vm`` or drop those characters from the character class 
(real media types never use them).



##########
app/src/main/webapp/WEB-INF/jsps/editor/MediaFileAddSuccess.jsp:
##########
@@ -96,7 +98,9 @@
 
                         <div class="col-md-1">
                             <input type="radio" name="enclosure"
-                                   onchange="setEnclosure('<s:property 
value="%{#newFile.permalink}"/>')"/>
+                                   onchange="setEnclosure('<s:property 
value="%{#newFile.permalink}"/>',
+                                           '<s:property 
value="%{#newFile.contentType}"/>',

Review Comment:
   Use `escapeJavaScript="true" escapeHtml="false"`, or better, put the three 
values in `data-` attributes and read them in the handler. (#174 changes how 
`contentType` is derived, which narrows this, but the JSP should still not 
inline it unescaped.)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to