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

feat(net): follow http redirects #2308

Merged
merged 1 commit into from
Feb 2, 2023

Conversation

tmpolaczyk
Copy link
Contributor

Fix #2305

@tmpolaczyk
Copy link
Contributor Author

If the redirect limit is reached, the data source will resolve to the RadError HttpOther { message: "number of redirects hit the maximum amount" }

@guidiaz
Copy link
Contributor

guidiaz commented Nov 16, 2022

If the redirect limit is reached, the data source will resolve to the RadError HttpOther { message: "number of redirects hit the maximum amount" }

Another option would be to resolve with the http error produced by last attempt. This way it the ultimate http error may be specifically refered as a specific enumerated value when reported to Solidity.

@tmpolaczyk
Copy link
Contributor Author

Another option would be to resolve with the http error produced by last attempt. This way it the ultimate http error may be specifically refered as a specific enumerated value when reported to Solidity.

Yeah, I actually expected that behavior, but not sure if we can extract the http status code from that error.

@aesedepece
Copy link
Member

If the redirect limit is reached, the data source will resolve to the RadError HttpOther { message: "number of redirects hit the maximum amount" }

Another option would be to resolve with the http error produced by last attempt. This way it the ultimate http error may be specifically refered as a specific enumerated value when reported to Solidity.

Redirects are not errors, so there's no such a thing as an error produced by last attempt. But hitting a client-chosen number of redirects is indeed a client error, which is the one to commit.

@tmpolaczyk tmpolaczyk marked this pull request as draft November 21, 2022 11:14
@tmpolaczyk
Copy link
Contributor Author

Marking this as a draft because I'm not sure if we can release this without TAPI, as it may change the behavior of some requests.

@aesedepece
Copy link
Member

Marking this as a draft because I'm not sure if we can release this without TAPI, as it may change the behavior of some requests.

It could indeed be potentially used as a griefing attack by crafting data requests that will use between 2 and 4 redirects and thus cause non-adopting nodes to commit an error and adopting ones to commit a value.

As a counterargument, as you can't easily use that attack in a targeted manner so as to intentionally steal collateral from someone else's identities into your own, the existence of that vector attack could arguably be considered pretty equivalent to all other existing "inconsistent source" attacks.

However this one wouldn't be prevented by the paranoid mode / retrieval proxies, so it's probably a good idea to use TAPI for this, just to stay on the safe side.

@aesedepece
Copy link
Member

This change sounds like a good candidate for being shipped with 1.6 — behind a TAPI flag if necessary. What do you think?

@tmpolaczyk
Copy link
Contributor Author

Seems like a good candidate for 1.6, with TAPI.

I believe the only unresolved issue is the error message when hitting the redirect limit? It is currently HttpOther { message: "number of redirects hit the maximum amount" }, I would expect it to return some HTTP status code in the 3xx range as well, but the http client doesn't give us that information.

@aesedepece
Copy link
Member

I believe the only unresolved issue is the error message when hitting the redirect limit? It is currently HttpOther { message: "number of redirects hit the maximum amount" }, I would expect it to return some HTTP status code in the 3xx range as well, but the http client doesn't give us that information.

Funnily enough, there's no widely accepted HTTP client error code for "too many redirects" 🤷

Anyway, are you suggesting to have something like a dedicated RadError::HttpTooManyRedirects?

@aesedepece
Copy link
Member

One way or another, I think we need a WIP here. So is that something @tmpolaczyk you're interested in working on? Or shall I go and create the WIP based on this implementation?

@tmpolaczyk
Copy link
Contributor Author

I was suggesting something like HttpError { code: 302 }, just so that the end user can get the specific error code returned by the server. But it is hard for me to imagine any use cases that would need to detect HTTP redirects, so maybe the generic HttpOther error is fine.

And feel free to write the WIP!

@aesedepece
Copy link
Member

We have a WIP now at https://github.com/witnet/WIPs/pull/93/files!

@tmpolaczyk tmpolaczyk force-pushed the follow-http-redirects branch 2 times, most recently from 8882e06 to 7516aba Compare January 16, 2023 15:23
@tmpolaczyk tmpolaczyk changed the base branch from master to witnet-1.6 January 16, 2023 15:24
@tmpolaczyk tmpolaczyk marked this pull request as ready for review January 16, 2023 15:24
@tmpolaczyk tmpolaczyk force-pushed the follow-http-redirects branch from 7516aba to 290c921 Compare February 2, 2023 14:29
@tmpolaczyk tmpolaczyk merged commit 290c921 into witnet:witnet-1.6 Feb 2, 2023
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.

Data sources returning HTTP/300s redirects are being systematically ignored
3 participants