mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
fix(ai): broaden SSRF pre-scan regex to cover srcset, poster, formaction, @import
This commit is contained in:
@@ -10,11 +10,11 @@ import re
|
||||
import sys
|
||||
|
||||
_REMOTE_REF_RE = re.compile(
|
||||
r'(?:src|href|action)\s*=\s*["\']?\s*(https?:/{1,2}[^\s"\'>\)]{1,200})',
|
||||
r'(?:src|href|action|srcset|poster|formaction)\s*=\s*["\']?\s*(https?:/{1,2}[^\s"\'>\)]{1,200})',
|
||||
re.IGNORECASE,
|
||||
)
|
||||
_REMOTE_CSS_URL_RE = re.compile(
|
||||
r'url\s*\(\s*["\']?\s*(https?:/{1,2}[^\s"\'>\)]{1,200})',
|
||||
r'(?:url\s*\(|@import)\s*["\']?\s*(https?:/{1,2}[^\s"\'>\)]{1,200})',
|
||||
re.IGNORECASE,
|
||||
)
|
||||
|
||||
|
||||
@@ -49,6 +49,18 @@ describe.skipIf(!hasPython)("SSRF pre-scan regexes (doc_html_pdf.py)", () => {
|
||||
it("does NOT match relative paths", () => {
|
||||
expect(testRegex('<a href="page2.xhtml">', "_REMOTE_REF_RE")).toBe(false);
|
||||
});
|
||||
|
||||
it("matches srcset attribute", () => {
|
||||
expect(testRegex('<img srcset="https://h/x.png 2x">', "_REMOTE_REF_RE")).toBe(true);
|
||||
});
|
||||
|
||||
it("matches poster attribute", () => {
|
||||
expect(testRegex('<video poster="https://h/thumb.jpg">', "_REMOTE_REF_RE")).toBe(true);
|
||||
});
|
||||
|
||||
it("matches formaction attribute", () => {
|
||||
expect(testRegex('<button formaction="https://h/submit">', "_REMOTE_REF_RE")).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("_REMOTE_CSS_URL_RE", () => {
|
||||
@@ -63,5 +75,17 @@ describe.skipIf(!hasPython)("SSRF pre-scan regexes (doc_html_pdf.py)", () => {
|
||||
it("does NOT match data: CSS url()", () => {
|
||||
expect(testRegex("url(data:image/png;base64,AA==)", "_REMOTE_CSS_URL_RE")).toBe(false);
|
||||
});
|
||||
|
||||
it("matches @import with double-quoted URL", () => {
|
||||
expect(testRegex('@import "https://h/style.css";', "_REMOTE_CSS_URL_RE")).toBe(true);
|
||||
});
|
||||
|
||||
it("matches @import with single-quoted URL", () => {
|
||||
expect(testRegex("@import 'https://h/style.css';", "_REMOTE_CSS_URL_RE")).toBe(true);
|
||||
});
|
||||
|
||||
it("matches @import with bare URL", () => {
|
||||
expect(testRegex("@import https://h/style.css;", "_REMOTE_CSS_URL_RE")).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user