Search code examples
securityhttphttp-redirecthttpspost-redirect-get

What response code to return for insecure POST not acceptable?


If somebody accesses my server via http (i. e. not https) then I redirect GET requests to the https version.

But I don't know what to do with POST and PUT because I cannot redirect them (the browser does a GET on redirect I believe).

I should return an error code. What HTTP error code should I return?


Solution

  • http://www.ietf.org/id/draft-ietf-httpbis-p2-semantics-18.txt explains HTTP response codes. If you want an error code, just return a 404 if requests cannot be serviced at that URL.

    7.4.5. 404 Not Found

    The server has not found anything matching the effective request URI. No indication is given of whether the condition is temporary or permanent. The 410 (Gone) status code SHOULD be used if the server knows, through some internally configurable mechanism, that an old resource is permanently unavailable and has no forwarding address. This status code is commonly used when the server does not wish to reveal exactly why the request has been refused, or when no other response is applicable.