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

🐛 bug: fix proxy overwrote the wrong scheme #2004

Merged
merged 2 commits into from Aug 9, 2022

Conversation

wangjq4214
Copy link
Member

Please provide enough information so that others can review your pull request:

Fix proxy overwrote the wrong scheme

Explain the details for making this change. What existing problem does the pull request solve?

close #2001

Commit formatting

Use emojis on commit messages so it provides an easy way of identifying the purpose or intention of a commit. Check out the emoji cheatsheet here: https://gitmoji.carloscuesta.me/

@wangjq4214 wangjq4214 marked this pull request as ready for review August 8, 2022 14:29
middleware/proxy/proxy.go Show resolved Hide resolved
middleware/proxy/proxy.go Show resolved Hide resolved
@ReneWerner87
Copy link
Member

thanks for the work, can you look over my comments

@wangjq4214
Copy link
Member Author

wangjq4214 commented Aug 9, 2022

thanks for the work, can you look over my comments

In this scenario, addr is a slice reference to the []byte c.fasthttp.Request.Header.requestURI, so when SetRequestURI is executed the requestURI changes causing addr to change as well.

More specifically, for the above example, addr is equivalent to requestURI[1:], so after the requestURI changes from /http://ip-api.com/json to http://ip-api.com/json addr will change from http://ip-api.com/json to ttp://ip-api.com/json, causing SetSchema to fail.

So I think it is necessary to make the above changes.

@ReneWerner87
Copy link
Member

thanks for the work, can you look over my comments

In this scenario, addr is a slice reference to the []byte c.fasthttp.Request.Header.requestURI, so when SetRequestURI is executed the requestURI changes causing addr to change as well.

More specifically, for the above example, addr is equivalent to requestURI[1:], so after the requestURI changes from /http://ip-api.com/json to http://ip-api.com/json addr will change from http://ip-api.com/json to ttp://ip-api.com/json, causing SetSchema to fail.

yes i know so it should be enough to inject the copy when setting the requestUri

@ReneWerner87
Copy link
Member

since this removes the link to the variable with the addr, the following change is then no longer necessary

@wangjq4214
Copy link
Member Author

wangjq4214 commented Aug 9, 2022

since this removes the link to the variable with the addr, the following change is then no longer necessary

image

image

When I use the modifications you mentioned above, I can't pass the test.

In SetRequestURI, h.requestURI = append(h.requestURI[:0], requestURI...) will be executed. Because the resulting []byte is shorter than the original one, it will execute in the original []byte. And no memory will be allocated.

@ReneWerner87 ReneWerner87 merged commit e8a2ba3 into gofiber:master Aug 9, 2022
@welcome
Copy link

welcome bot commented Aug 9, 2022

Congrats on merging your first pull request! 🎉 We here at Fiber are proud of you! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

@wangjq4214 wangjq4214 deleted the fix-proxy branch August 10, 2022 01:09
trim21 pushed a commit to trim21/fiber that referenced this pull request Aug 15, 2022
* 🐛 bug: fix proxy overwrote the wrong scheme

* ✅ fix: fix io not exist in go1.14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 [Bug]: Middleware proxy.Do overwrote the wrong scheme
2 participants