[ 
https://issues.apache.org/jira/browse/ROL-2184?focusedWorklogId=1045542&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1045542
 ]

ASF GitHub Bot logged work on ROL-2184:
---------------------------------------

                Author: ASF GitHub Bot
            Created on: 03/Oct/26 20:58
            Start Date: 03/Oct/26 20:58
    Worklog Time Spent: 10m 
      Work Description: snoopdave commented on code in PR #203:
URL: https://github.com/apache/roller/pull/203#discussion_r4174827626


##########
app/src/main/java/org/apache/roller/weblogger/util/InlineImageData.java:
##########
@@ -0,0 +1,156 @@
+/*
+ * 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.ArrayList;
+import java.util.Base64;
+import java.util.List;
+import java.util.Locale;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/** Image data URLs accepted in entry content and their locations in HTML. */
+public final class InlineImageData {
+
+    // MySQL's TEXT column holds 65,535 bytes. Leave room for the rest of an 
entry.
+    public static final int MAX_FIELD_BYTES = 60000;
+
+    private static final Pattern IMAGE_TAG = 
Pattern.compile("(?is)<img\\b[^>]*>");
+    private static final Pattern SOURCE_ATTRIBUTE = Pattern.compile(

Review Comment:
   🐞Claude Issue: **Important:** `SOURCE_ATTRIBUTE` can match `src=` inside 
another attribute's quoted value. For example, in `<img 
alt='src="data:image/png;base64,..."' src="https://...";>` the alt text is 
treated as the source. That alt text is then rewritten or rejected, and the 
real `src` is ignored. Match attributes in sequence instead (`name=value` pairs 
from the tag start), or at least skip matches that fall inside an earlier 
quoted value.



##########
app/src/main/java/org/apache/roller/weblogger/util/InlineImageData.java:
##########
@@ -0,0 +1,156 @@
+/*
+ * 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.ArrayList;
+import java.util.Base64;
+import java.util.List;
+import java.util.Locale;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/** Image data URLs accepted in entry content and their locations in HTML. */
+public final class InlineImageData {
+
+    // MySQL's TEXT column holds 65,535 bytes. Leave room for the rest of an 
entry.
+    public static final int MAX_FIELD_BYTES = 60000;
+
+    private static final Pattern IMAGE_TAG = 
Pattern.compile("(?is)<img\\b[^>]*>");

Review Comment:
   🐞Claude Issue: **Blocking:** This is the cause of the failing CodeQL check 
(high: polynomial regex on user data). `[^>]*` also matches `<`, so on text 
with many `<img` and no `>` each `find()` scans to the end of the input, which 
is O(n²). Measured with `"<img ".repeat(n)`: 0.44 s at 50 KB, 1.8 s at 100 KB, 
7.2 s at 200 KB. Any author can make a save take minutes.
   
   Fix: stop at the next tag start. On the same input this ran in 1–3 ms:
   ```java
   private static final Pattern IMAGE_TAG = 
Pattern.compile("(?is)<img\\b[^<>]*>");
   ```
   Add a regression test with a large adversarial input.





Issue Time Tracking
-------------------

    Worklog Id:     (was: 1045542)
    Time Spent: 20m  (was: 10m)

> Pasted desktop images disappear from published entries
> ------------------------------------------------------
>
>                 Key: ROL-2184
>                 URL: https://issues.apache.org/jira/browse/ROL-2184
>             Project: Apache Roller
>          Issue Type: Bug
>          Components: Media files / uploads, Themes and Macros, User Interface 
> - Weblog Editor
>            Reporter: David M. Johnson
>            Assignee: David M. Johnson
>            Priority: Major
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> Reported against 6.1.6.
> If you drag a desktop image into the rich text editor, it becomes a {{data:}} 
> image. It shows while you edit, but the published entry leaves it out: 
> rendering strips {{data:}} images, and the bundled themes' CSP blocks them. 
> Fix both paths:
> # *Upload (preferred).* When upload is available, upload new pasted or 
> dropped images as media files. Convert stored inline images the next time an 
> entry is saved. Leave remote images unchanged. Use Roller's existing checks 
> for upload permission, file type, size and quota.
> # *Inline fallback.* When upload is unavailable, or when the new global 
> "inline images" preference is set, store the image inline. Accept only 
> strictly validated PNG, JPEG and GIF data images, with a 60,000-byte field 
> limit.
> h3. Acceptance
> * New pastes and drops, and edits of old entries, produce working published 
> images on both paths. Check the draft and publish flows.
> * A failed upload, or an invalid or oversized inline image, shows a clear 
> message. It never silently publishes a missing image.
> * Valid inline images render in the bundled themes. Non-image data URLs and 
> active content stay blocked.
> * The docs say that custom themes with their own CSP must allow {{data:}} 
> under {{img-src}}.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to