Earlier quoted context omitted.
There's absolutely nothing you can do to prevent an active MITM attack over HTTP
Have the authentication header effectively be a signed hash of relevant headers and the full URL, rather than a simple bearer token?
API Shouldn't Redirect HTTP to HTTPS
161–170 of 310 posts
Re: API Shouldn't Redirect HTTP to HTTPS
#162Earlier quoted context omitted.
If anybody is looking to copy in a public API, please return 400 and don't misuse a standard code.
400 is usually for a malformed request. It seems like in this case the request is well formed, it's just not allowed. 403 seems reasonable if the user isn't authorized to make a request to the URL, which they aren't. Some APIs return redirects which also seems pretty reasonable.
IMO, 400 is more accurate, but really either could be acceptable, so long as the client is notified of the error. But, I wouldn’t automatically redirect the client. That’s what we are trying to avoid.
Re: API Shouldn't Redirect HTTP to HTTPS
#163Earlier quoted context omitted.
Why not just stop listening on port 80, period?
It’s a good option, but you can’t give users a reason for the failure. They might even assume your service is broken.
Re: API Shouldn't Redirect HTTP to HTTPS
#164Earlier quoted context omitted.
Have the authentication header effectively be a signed hash of relevant headers and the full URL, rather than a simple bearer token?
What's stopping the MITM just copying that header?
Re: API Shouldn't Redirect HTTP to HTTPS
#165A strawman fallacy.
Re: API Shouldn't Redirect HTTP to HTTPS
#166Re: API Shouldn't Redirect HTTP to HTTPS
#167Great article! We've updated the OpenAI API to 403 on HTTP requests instead of redirecting. $ curl http://api.openai.com/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer 123" \ -d '{}' { "error": { "type": "invalid_request_error", "code": "http_unsupported", "message": "The OpenAI API is only accessible over HTTPS. Ensure the URL starts with 'https://' and not 'http://'.", "param"…
http://api.openai.com/v1/chat/completions/../bar responds with error messages about http://api.openai.com/v1/chat/bar which might suggest some path traversal vulnerability that could be exploited.
Generally an API client is not going to need .. to be resolved in a path. It should return 400 - Bad Request (deceptive routing).
Re: API Shouldn't Redirect HTTP to HTTPS
#168npm is misusing 426 Upgrade Required. https://httpwg.org/specs/rfc9110.html#status.426 : > The server MUST send an Upgrade header field in a 426 response to indicate the required protocol(s) (Section 7.8). https://httpwg.org/specs/rfc9110.html#field.upgrade : > The Upgrade header field only applies to switching protocols on top of the existing connection; it cannot be used to switch the underlying connection (transpo…
Re: API Shouldn't Redirect HTTP to HTTPS
#169The Stack Exchange API used to revoke API keys sent over HTTP (and return an error message), which is my favorite way to handle this.
Re: API Shouldn't Redirect HTTP to HTTPS
#170The Stack Exchange API used to revoke API keys sent over HTTP (and return an error message), which is my favorite way to handle this.
Wouldn't this open the door to revoking random API keys sent maliciously ?