Skip to content

Commit fd3316e

Browse files
committed
fixed path traversal issue
1 parent 1f44fcc commit fd3316e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/lib/helper.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
export const sanitizePath = (str: string) => str?.replace(/^(\.\.(\/|\\|$))+/, '');
1+
export const sanitizePath = (str: string) =>
2+
str
3+
?.replace(/^([\/\\])+/, "./") // Normalize leading slashes/backslashes to './'
4+
.replace(/[\/\\]+/g, "/") // Replace multiple slashes/backslashes with a single '/'
5+
.replace(/(\.\.(\/|\\|$))+/g, ""); // Remove directory traversal (../ or ..\)

0 commit comments

Comments
 (0)