Skip to content

Commit 814fa59

Browse files
committed
Disallow additional path traversal patterns
1 parent 527332b commit 814fa59

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/forge.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,19 @@ struct Endpoint
187187
query::Dict=Dict(),
188188
allow_404::Bool=false,
189189
)
190-
# do not allow path navigation in URLs
190+
# Do not allow path navigation in URLs
191+
# Disallowed pattern: ..
191192
if occursin(r"\.\.", url)
192193
throw(ArgumentError("URLs cannot contain path navigation"))
193194
end
195+
196+
# Additional disallowed patterns:
197+
# ../, ..\, /.., \.., ./, .\, /./, \.\
198+
PATH_TRAVERSAL = r"(?:\.{2,}[\/\\]|\.{1,}[\/\\]|[\/\\]\.{2,}|[\/\\]\.{1,}[\/\\])"
199+
if occursin(PATH_TRAVERSAL, url)
200+
throw(ArgumentError("URLs cannot contain path navigation"))
201+
end
202+
194203
# do not allow new lines or carriage returns in URLs
195204
if occursin(r"\s", url)
196205
throw(ArgumentError("URLs cannot contain line breaks"))

0 commit comments

Comments
 (0)