mirror of
https://github.com/ZeroCatDev/Classworks.git
synced 2026-02-04 16:03:10 +00:00
harden css escaping for background
Co-authored-by: Sunwuyuan <88357633+Sunwuyuan@users.noreply.github.com>
This commit is contained in:
parent
b96484d26a
commit
2c12051c45
@ -693,8 +693,9 @@ export default {
|
|||||||
if (!safeUrl) return { display: "none" };
|
if (!safeUrl) return { display: "none" };
|
||||||
|
|
||||||
const blur = Math.min(Math.max(this.backgroundBlurAmount, 0), 50);
|
const blur = Math.min(Math.max(this.backgroundBlurAmount, 0), 50);
|
||||||
|
const escaped = this.cssEscape(encodeURI(safeUrl));
|
||||||
return {
|
return {
|
||||||
backgroundImage: `url("${encodeURI(safeUrl)}")`,
|
backgroundImage: `url("${escaped}")`,
|
||||||
filter: `blur(${blur}px)`,
|
filter: `blur(${blur}px)`,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@ -2217,7 +2218,7 @@ export default {
|
|||||||
try {
|
try {
|
||||||
const parsed = new URL(trimmed, window.location.origin);
|
const parsed = new URL(trimmed, window.location.origin);
|
||||||
const protocol = parsed.protocol.replace(":", "");
|
const protocol = parsed.protocol.replace(":", "");
|
||||||
if (["http", "https", "data", "blob"].includes(protocol)) return true;
|
if (["http", "https", "blob"].includes(protocol)) return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Allow relative paths
|
// Allow relative paths
|
||||||
if (
|
if (
|
||||||
@ -2237,9 +2238,15 @@ export default {
|
|||||||
return parsed.href;
|
return parsed.href;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Fallback for relative paths when URL parsing fails
|
// Fallback for relative paths when URL parsing fails
|
||||||
return url.replace(/[^a-zA-Z0-9-._~!$&'()*+,;=/:@%]/g, "");
|
return url.replace(/[^a-zA-Z0-9-._~/:@%+#?&=]/g, "");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
cssEscape(value) {
|
||||||
|
if (typeof CSS !== "undefined" && CSS.escape) {
|
||||||
|
return CSS.escape(value);
|
||||||
|
}
|
||||||
|
return value.replace(/[^a-zA-Z0-9_\-]/g, (char) => `\\${char}`);
|
||||||
|
},
|
||||||
|
|
||||||
safeBase64Decode(base64String) {
|
safeBase64Decode(base64String) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user