Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion public/themes/Default/js/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@
};
d.VERSION = "3.3.7",
d.TRANSITION_DURATION = 150,
d._isSafeSelector = function(f) {
// Allow only simple ID selectors like "#my-alert"
if (!f || "string" != typeof f) return !1;
return /^#[A-Za-z][A-Za-z0-9\-_:.]*$/.test(f);
}
,
d.prototype.close = function(b) {
function c() {
g.detach().trigger("closed.bs.alert").remove()
Expand All @@ -72,7 +78,8 @@
, f = e.attr("data-target");
f || (f = e.attr("href"),
f = f && f.replace(/.*(?=#[^\s]*$)/, ""));
var g = a("#" === f ? [] : f);
d._isSafeSelector(f) || (f = null);
var g = f ? a("#" === f ? [] : f) : a();

Check failure

Code scanning / CodeQL

DOM text reinterpreted as HTML High

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

Copilot Autofix

AI about 1 month ago

In general, the fix is to ensure that untrusted text taken from the DOM (here, data-target / href) is not passed directly to a(...) (jQuery) in a way that could be interpreted as HTML. Instead, we should either (1) validate that it is a safe, restricted selector pattern before using it in $(), or (2) use APIs that only ever interpret it as a selector and never as HTML, or (3) fall back to a safe default (like the closest .alert) when the selector is unsafe.

The best fix, preserving existing behavior, is to validate f against a strict pattern for allowed selectors and discard it when it doesn’t match. You already have a helper d._isSafeSelector (lines 67–71) that allows only simple ID selectors like #my-alert. The minimal, targeted change is to ensure that any unsafe selector results in no element being selected (so jQuery is never invoked with potentially HTML-looking strings). Currently we already have:

81:                 d._isSafeSelector(f) || (f = null);
82:                 var g = f ? a("#" === f ? [] : f) : a();

However, this still uses the slightly odd "#" === f ? [] : f expression, which is unnecessary when f is either null or a validated ID selector (it will always start with # and have more than one character if valid). We can simplify and make the intent clearer by:

  • Keeping d._isSafeSelector(f) as the gatekeeper.
  • After that, using f ? a(f) : a(); instead of "#" === f ? [] : f, since f will be null for unsafe or empty values and a valid #id string for safe ones.
  • This prevents any possibility of jQuery interpreting HTML-like text, because only validated #id selectors reach it.

Concretely, in public/themes/Default/js/bootstrap.js within d.prototype.close, we will:

  1. Leave the _isSafeSelector helper as-is.
  2. Replace line 82 to remove the "#" === f ? [] : f ternary and rely solely on the safe/unsafe guard on line 81.

No new methods or imports are required; we only adjust the use of f when constructing the jQuery object.


Suggested changeset 1
public/themes/Default/js/bootstrap.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/public/themes/Default/js/bootstrap.js b/public/themes/Default/js/bootstrap.js
--- a/public/themes/Default/js/bootstrap.js
+++ b/public/themes/Default/js/bootstrap.js
@@ -79,7 +79,7 @@
                 f || (f = e.attr("href"),
                     f = f && f.replace(/.*(?=#[^\s]*$)/, ""));
                 d._isSafeSelector(f) || (f = null);
-                var g = f ? a("#" === f ? [] : f) : a();
+                var g = f ? a(f) : a();
                 b && b.preventDefault(),
                 g.length || (g = e.closest(".alert")),
                     g.trigger(b = a.Event("close.bs.alert")),
EOF
@@ -79,7 +79,7 @@
f || (f = e.attr("href"),
f = f && f.replace(/.*(?=#[^\s]*$)/, ""));
d._isSafeSelector(f) || (f = null);
var g = f ? a("#" === f ? [] : f) : a();
var g = f ? a(f) : a();
b && b.preventDefault(),
g.length || (g = e.closest(".alert")),
g.trigger(b = a.Event("close.bs.alert")),
Copilot is powered by AI and may make mistakes. Always verify output.
b && b.preventDefault(),
g.length || (g = e.closest(".alert")),
g.trigger(b = a.Event("close.bs.alert")),
Expand Down