mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-25 16:37:32 +00:00
fix(cli): capture keeps an SVG link attribute only under its plain or xlink name (#8705)
A link attribute written under another prefix (for example xl:href with the prefix bound to the xlink namespace) was not checked as a link, so an SVG that loads an outside file through it was saved as a plain image. Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
8eeeabf8a6
commit
42ad487987
@@ -61,6 +61,13 @@ describe("captured image validation", () => {
|
||||
expect(bytes).toEqual(original);
|
||||
});
|
||||
|
||||
it("keeps a local reference written as href or xlink:href", async () => {
|
||||
const mark = '<defs><path id="mark" d="M0 0h24v24z"/></defs>';
|
||||
const xlink = '<g xmlns:xlink="http://www.w3.org/1999/xlink"><use xlink:href="#mark"/></g>';
|
||||
expect(await captureImageExtension(svg(`${mark}<use href="#mark"/>`))).toBe(".svg");
|
||||
expect(await captureImageExtension(svg(mark + xlink))).toBe(".svg");
|
||||
});
|
||||
|
||||
it.each([
|
||||
"<script>alert(1)</script>",
|
||||
'<rect width="24" height="24" onload="alert(1)"/>',
|
||||
@@ -70,6 +77,9 @@ describe("captured image validation", () => {
|
||||
"<style>path{fill:url(https://private.example/image.svg)}</style>",
|
||||
"<style>path{fill:u\\72l(https://private.example/image.svg)}</style>",
|
||||
'<set attributeName="href" to="https://private.example/image.svg"/>',
|
||||
'<g xmlns:xl="http://www.w3.org/1999/xlink"><image xl:href="https://private.example/image.png"/></g>',
|
||||
'<g xmlns:xl="http://www.w3.org/1999/xlink"><use xl:href="#mark"/></g>',
|
||||
'<image xmlns:m="urn:media" m:src="https://private.example/image.png"/>',
|
||||
])("rejects active or externally loading SVG: %s", async (content) => {
|
||||
expect(await captureImageExtension(svg(content))).toBeNull();
|
||||
});
|
||||
|
||||
@@ -82,6 +82,7 @@ export function passiveInlineSvg(markup: string): boolean {
|
||||
function passiveSvgAttribute(name: string, value: string, embedded: Set<string>): boolean {
|
||||
if (name.startsWith("on") || name === "xml:base") return false;
|
||||
if (["href", "xlink:href", "src"].includes(name)) return localImageReference(value, embedded);
|
||||
if (/:(?:href|src)$/.test(name)) return false;
|
||||
if (name === "style") return passiveCss(value, "declarationList", embedded);
|
||||
return !/url\s*\(|\\/i.test(value) || passiveCss(value, "value", embedded);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user