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
2 changes: 1 addition & 1 deletion apps/web/src/utils/isDataUri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
* @see {@link https://www.rfc-editor.org/rfc/rfc2397}
*/
export default function isDataURI(uri: string): boolean {
return /data:(image\/(?:\w|-)+)(;?\w+=[\w-]+)*(;base64)?,.*/gu.test(uri)
return /data:(image\/(?:\w|-)+)(;?\w+=\w+)*(;base64)?,.*/gu.test(uri)

Check failure

Code scanning / CodeQL

Inefficient regular expression

This part of the regular expression may cause exponential backtracking on strings starting with 'data:image/00=' and containing many repetitions of '000='.

Copilot Autofix

AI about 1 year ago

To fix the problem, we need to modify the regular expression to remove the ambiguity that can lead to exponential backtracking. This can be achieved by making the sub-expressions more specific and reducing the potential for overlapping matches.

  • We will replace \w+ with a more specific character class that matches the intended characters without causing ambiguity.
  • We will ensure that the regular expression is still compliant with RFC2397 while improving its performance.
Suggested changeset 1
apps/web/src/utils/isDataUri.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/apps/web/src/utils/isDataUri.ts b/apps/web/src/utils/isDataUri.ts
--- a/apps/web/src/utils/isDataUri.ts
+++ b/apps/web/src/utils/isDataUri.ts
@@ -5,3 +5,3 @@
 export default function isDataURI(uri: string): boolean {
-  return /data:(image\/(?:\w|-)+)(;?\w+=\w+)*(;base64)?,.*/gu.test(uri)
+  return /data:(image\/(?:[\w-]+))(;[\w-]+=([\w-]+))*(;base64)?,.*/gu.test(uri)
 }
EOF
@@ -5,3 +5,3 @@
export default function isDataURI(uri: string): boolean {
return /data:(image\/(?:\w|-)+)(;?\w+=\w+)*(;base64)?,.*/gu.test(uri)
return /data:(image\/(?:[\w-]+))(;[\w-]+=([\w-]+))*(;base64)?,.*/gu.test(uri)
}
Copilot is powered by AI and may make mistakes. Always verify output.
}