Skip to content

ActivityPub compatibility#1323

Merged
mrflos merged 25 commits into
doryphore-devfrom
activitypub-compatibility
Apr 18, 2026
Merged

ActivityPub compatibility#1323
mrflos merged 25 commits into
doryphore-devfrom
activitypub-compatibility

Conversation

@srosset81

@srosset81 srosset81 commented Mar 19, 2026

Copy link
Copy Markdown
Contributor

See documentation activitypub.md

Comment on lines +94 to +100
previewEl.innerHTML = `<img
class="img-responsive"
src="${url}"
alt="Preview"
onerror="this.style.display='none'"
onload="this.style.display='block'"
/>`

Check failure

Code scanning / CodeQL

DOM text reinterpreted as HTML High

DOM text
is reinterpreted as HTML without escaping meta-characters.

Copilot Autofix

AI 4 months ago

In general, this should be fixed by not using innerHTML with strings that contain or are derived from untrusted data. Instead, create DOM elements programmatically (e.g., via document.createElement) and assign untrusted data only to safe properties/attributes (like img.src), which will be treated as plain text/URLs rather than parsed as HTML.

For this file, the best minimal fix without changing existing functionality is to replace the innerHTML assignment that embeds the <img> tag with DOM-based creation and update of an <img> element inside previewEl. Concretely:

  • In handleImageUrlInput, in the block starting at line 93, remove the template literal assigned to previewEl.innerHTML.
  • Instead, clear any existing content in previewEl, then:
    • Create an <img> element.
    • Set its className to "img-responsive".
    • Set its alt attribute to "Preview".
    • Set its src property to the untrusted url.
    • Attach onerror and onload handlers equivalent to the inline ones: hide the image on error, show it on load.
    • Append this <img> element to previewEl.
  • Keep the else branch that sets previewEl.innerHTML = '' or similarly clear the element.

No new imports or external libraries are needed; this can be done with standard DOM APIs in tools/bazar/presentation/javascripts/inputs/image-field.js.

Suggested changeset 1
tools/bazar/presentation/javascripts/inputs/image-field.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/tools/bazar/presentation/javascripts/inputs/image-field.js b/tools/bazar/presentation/javascripts/inputs/image-field.js
--- a/tools/bazar/presentation/javascripts/inputs/image-field.js
+++ b/tools/bazar/presentation/javascripts/inputs/image-field.js
@@ -91,13 +91,23 @@
   if (!previewEl) return
 
   if (url && (url.startsWith('http://') || url.startsWith('https://'))) {
-    previewEl.innerHTML = `<img
-      class="img-responsive"
-      src="${url}"
-      alt="Preview"
-      onerror="this.style.display='none'"
-      onload="this.style.display='block'"
-    />`
+    // Clear previous preview content
+    previewEl.innerHTML = ''
+
+    // Create image element safely without using innerHTML with untrusted data
+    const img = document.createElement('img')
+    img.className = 'img-responsive'
+    img.alt = 'Preview'
+    img.style.display = 'none'
+    img.onerror = function onImageError() {
+      this.style.display = 'none'
+    }
+    img.onload = function onImageLoad() {
+      this.style.display = 'block'
+    }
+    img.src = url
+
+    previewEl.appendChild(img)
   } else {
     previewEl.innerHTML = ''
   }
EOF
@@ -91,13 +91,23 @@
if (!previewEl) return

if (url && (url.startsWith('http://') || url.startsWith('https://'))) {
previewEl.innerHTML = `<img
class="img-responsive"
src="${url}"
alt="Preview"
onerror="this.style.display='none'"
onload="this.style.display='block'"
/>`
// Clear previous preview content
previewEl.innerHTML = ''

// Create image element safely without using innerHTML with untrusted data
const img = document.createElement('img')
img.className = 'img-responsive'
img.alt = 'Preview'
img.style.display = 'none'
img.onerror = function onImageError() {
this.style.display = 'none'
}
img.onload = function onImageLoad() {
this.style.display = 'block'
}
img.src = url

previewEl.appendChild(img)
} else {
previewEl.innerHTML = ''
}
Copilot is powered by AI and may make mistakes. Always verify output.
@srosset81
srosset81 marked this pull request as ready for review April 3, 2026 14:02
@mrflos
mrflos force-pushed the activitypub-compatibility branch from 068c31c to 52aae21 Compare April 18, 2026 19:04
@mrflos
mrflos merged commit 52aae21 into doryphore-dev Apr 18, 2026
3 of 6 checks passed
@mrflos
mrflos deleted the activitypub-compatibility branch April 18, 2026 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants