Skip to content

Commit 527332b

Browse files
disallow path navigation and newlines in urls (#50)
* disallow path navigation and newlines in urls Adding checks to `Endpoint` urls to disallow: - path navigation. This would prevent API calls like `GitForge.get_repo(forge, "JuliaLang", "../octocat/Hello-World")` from succeeding. Helps avoid possible security loopholes. - newlines. This would prevent possible security loopholes using HTTP protocol. Also added some tests. * Update src/forge.jl Co-authored-by: Dilum Aluthge <[email protected]> * disallow all whitespaces in url * updated patch version --------- Co-authored-by: Dilum Aluthge <[email protected]>
1 parent f8df114 commit 527332b

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "GitForge"
22
uuid = "8f6bce27-0656-5410-875b-07a5572985df"
33
authors = ["Chris de Graaf <[email protected]>"]
4-
version = "0.4.2"
4+
version = "0.4.3"
55

66
[deps]
77
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"

src/forge.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,14 @@ struct Endpoint
187187
query::Dict=Dict(),
188188
allow_404::Bool=false,
189189
)
190+
# do not allow path navigation in URLs
191+
if occursin(r"\.\.", url)
192+
throw(ArgumentError("URLs cannot contain path navigation"))
193+
end
194+
# do not allow new lines or carriage returns in URLs
195+
if occursin(r"\s", url)
196+
throw(ArgumentError("URLs cannot contain line breaks"))
197+
end
190198
return new(method, url, headers, query, allow_404)
191199
end
192200
end

test/runtests.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ GF.into(::TestForge, ::typeof(get_user)) = Symbol
6969
@test haskey(get(body, :args, Dict()), :foo)
7070
@test get(get(body, :args, Dict()), :a, "") == "b"
7171
end
72+
73+
@testset "URL sanity" begin
74+
@test isa(GitForge.Endpoint(:GET, "/repos/owner/repo"), GitForge.Endpoint)
75+
@test_throws ArgumentError GitForge.Endpoint(:GET, "/repos/owner1/../owner2/repo")
76+
@test_throws ArgumentError GitForge.Endpoint(:GET, "/repos/owner1/\n/owner2/repo")
77+
@test_throws ArgumentError GitForge.Endpoint(:GET, "/repos/owner1/\r\nfoo/owner2/repo")
78+
79+
forge = GitForge.GitHub.GitHubAPI(;token=GitForge.GitHub.NoToken())
80+
@test_throws ArgumentError GitForge.get_repo(forge, "JuliaLang", "../octocat/Hello-World")
81+
end
7282
end
7383

7484
# test whether apis are conformant

0 commit comments

Comments
 (0)