Skip to content

🐛 bug: fix proxy overwrote the wrong scheme - #2004

Merged
ReneWerner87 merged 2 commits into
gofiber:masterfrom
wangjq4214:fix-proxy
Aug 9, 2022
Merged

🐛 bug: fix proxy overwrote the wrong scheme#2004
ReneWerner87 merged 2 commits into
gofiber:masterfrom
wangjq4214:fix-proxy

Conversation

@wangjq4214

Copy link
Copy Markdown
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
Comment thread middleware/proxy/proxy.go
Comment thread middleware/proxy/proxy.go
@ReneWerner87

Copy link
Copy Markdown
Member

thanks for the work, can you look over my comments

@wangjq4214
wangjq4214 requested a review from ReneWerner87 August 9, 2022 02:20
@wangjq4214

wangjq4214 commented Aug 9, 2022

Copy link
Copy Markdown
Member Author

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
Copy Markdown
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
Copy Markdown
Member

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

@wangjq4214

wangjq4214 commented Aug 9, 2022

Copy link
Copy Markdown
Member Author

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

welcome Bot commented Aug 9, 2022

Copy link
Copy Markdown

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