Skip to content
Merged
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
5 changes: 4 additions & 1 deletion src/egress/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ export interface EgressResult {
}

// Matches markdown images ![alt](url) and bare http/https/ftp URLs.
const URL_RE = /!\[([^\]]*)\]\(\s*([^)\s]+)(?:\s+"[^"]*")?\)|(?:https?|ftp):\/\/[^\s)<>"']+/g;
// Alt excludes '[' and the image URL excludes '(' so a partial "![..." / "![](..."
// start that never completes fails in O(1) instead of re-scanning to the end of the
// input, which would make matching quadratic on adversarial egress text (ReDoS).
const URL_RE = /!\[([^\]\[]*)\]\(\s*([^)\s(]+)(?:\s+"[^"]*")?\)|(?:https?|ftp):\/\/[^\s)<>"']+/g;

function urlAllowed(url: string, allowlist: (string | RegExp)[]): boolean {
return allowlist.some((entry) => {
Expand Down
Loading