Skip to content
Open
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
11 changes: 10 additions & 1 deletion src/forge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,19 @@ struct Endpoint
query::Dict=Dict(),
allow_404::Bool=false,
)
# do not allow path navigation in URLs
# Do not allow path navigation in URLs
# Disallowed pattern: ..
if occursin(r"\.\.", url)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this is needed any more... the specific path traversal cases it was needed for preventing seem to be covered in the below regex. Should this be removed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm. Technically the regex PATH_TRAVERSAL doesn't actually cover the pattern .. - is that okay?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see that it does not cover r"^\.\.$", which is a valid path traversal without /. But that seems to be the only one, right? Should we then change it to that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then, an Endpoint without / is not really valid. So it does seem okay to remove it.

throw(ArgumentError("URLs cannot contain path navigation"))
end

# Additional disallowed patterns:
# ../, ..\, /.., \.., ./, .\, /./, \.\
PATH_TRAVERSAL = r"(?:\.{2,}[\/\\]|\.{1,}[\/\\]|[\/\\]\.{2,}|[\/\\]\.{1,}[\/\\])"
if occursin(PATH_TRAVERSAL, url)
throw(ArgumentError("URLs cannot contain path navigation"))
end

# do not allow new lines or carriage returns in URLs
if occursin(r"\s", url)
throw(ArgumentError("URLs cannot contain line breaks"))
Expand Down
Loading