Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #3500 Add escape logic for header #3503

Merged
merged 1 commit into from
Feb 19, 2023

Conversation

t0rchwo0d
Copy link
Contributor

@t0rchwo0d t0rchwo0d commented Feb 17, 2023

Hi, @appleboy, @thinkerou

Excuse me, I again think about #3500
I'm sorry to bother you.

. delimiter & Repeated / delimiter was judged to need to be delete and merge,
So, I request PR again.

  • Remove characters outside the allowed range (alphabets, numeric, -, /)
  • Merge Repeated / delimiters into one
  • Add Test Case

@t0rchwo0d t0rchwo0d force-pushed the fix-3500-add-escape-logic branch from c22614f to bd78de0 Compare February 17, 2023 03:57
@codecov
Copy link

codecov bot commented Feb 17, 2023

Codecov Report

Merging #3503 (69e306f) into master (81ac7d5) will not change coverage.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #3503   +/-   ##
=======================================
  Coverage   98.63%   98.63%           
=======================================
  Files          42       42           
  Lines        3151     3151           
=======================================
  Hits         3108     3108           
  Misses         29       29           
  Partials       14       14           
Flag Coverage Δ
98.63% <100.00%> (ø)
go-1.16 ∅ <ø> (?)
go-1.17 98.54% <100.00%> (ø)
go-1.18 98.54% <100.00%> (ø)
go-1.19 98.63% <100.00%> (ø)
go-1.20 98.63% <100.00%> (ø)
macos-latest 98.63% <100.00%> (ø)
ubuntu-latest 98.63% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
gin.go 99.19% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@appleboy appleboy added this to the v1.9 milestone Feb 17, 2023
@t0rchwo0d t0rchwo0d force-pushed the fix-3500-add-escape-logic branch from bd78de0 to fd9f98e Compare February 17, 2023 05:28
t0rchwo0d

This comment was marked as outdated.

@t0rchwo0d t0rchwo0d force-pushed the fix-3500-add-escape-logic branch 2 times, most recently from 2deb996 to 2c2e15f Compare February 17, 2023 15:15
t0rchwo0d

This comment was marked as outdated.

@t0rchwo0d
Copy link
Contributor Author

t0rchwo0d commented Feb 17, 2023

I finished the exception handling that cases I was considering.
If / is continuous , all of it was not removed, so I added logic with Test case.

  • Remove characters outside the allowed range (alphabets, numeric, -, /)
  • Merge Repeated / delimiters into one
  • Add Test Case

@t0rchwo0d t0rchwo0d force-pushed the fix-3500-add-escape-logic branch from 2c2e15f to 6e8f186 Compare February 17, 2023 15:35
gin.go Outdated Show resolved Hide resolved
@t0rchwo0d t0rchwo0d force-pushed the fix-3500-add-escape-logic branch from 6e8f186 to 6b8cd84 Compare February 18, 2023 02:28
@t0rchwo0d t0rchwo0d requested review from appleboy and removed request for thinkerou February 18, 2023 05:32
gin.go Outdated Show resolved Hide resolved
@t0rchwo0d t0rchwo0d force-pushed the fix-3500-add-escape-logic branch from 6b8cd84 to 260f21b Compare February 18, 2023 06:41
@t0rchwo0d t0rchwo0d requested a review from appleboy February 18, 2023 06:44
@t0rchwo0d
Copy link
Contributor Author

Update - Initialize regular expressions only once and simplify logic

@t0rchwo0d t0rchwo0d force-pushed the fix-3500-add-escape-logic branch from 260f21b to 0cc8dca Compare February 18, 2023 06:52
@t0rchwo0d
Copy link
Contributor Author

Update - Test Case

@appleboy appleboy merged commit 4cee78f into gin-gonic:master Feb 19, 2023
@ksw2000
Copy link

ksw2000 commented Nov 25, 2024

I have some questions in routes_test.go. Why the expectation of Line205 is //path but not /path

gin/routes_test.go

Lines 205 to 211 in e46bd52

w = PerformRequest(router, http.MethodGet, "/path/", header{Key: "X-Forwarded-Prefix", Value: "api/../../"})
assert.Equal(t, "//path", w.Header().Get("Location"))
assert.Equal(t, http.StatusMovedPermanently, w.Code)
w = PerformRequest(router, http.MethodGet, "/path/", header{Key: "X-Forwarded-Prefix", Value: "api/../../../"})
assert.Equal(t, "/path", w.Header().Get("Location"))
assert.Equal(t, http.StatusMovedPermanently, w.Code)

Why the expectation of Line221 is https/gin-goniccom/https/gin-goniccom/path but not https/gin-goniccom/path

gin/routes_test.go

Lines 221 to 223 in e46bd52

w = PerformRequest(router, http.MethodGet, "/path/", header{Key: "X-Forwarded-Prefix", Value: "https://gin-gonic.com/#"})
assert.Equal(t, "https/gin-goniccom/https/gin-goniccom/path", w.Header().Get("Location"))
assert.Equal(t, http.StatusMovedPermanently, w.Code)

Additionally, is there any difference if the URL prefix returned by .Location() includes a leading slash or does not include one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants