Skip to content
This repository has been archived by the owner on Jun 7, 2022. It is now read-only.

Return 401 Unauthorized instead of 403 Forbidden on HMAC auth failure #31

Open
Valloric opened this issue Feb 7, 2016 · 5 comments
Open

Comments

@Valloric
Copy link
Contributor

Valloric commented Feb 7, 2016

Racerd currently returns a 403 on HMAC failure instead of a 401. The 401 makes more sense; the request was unauthorized. 403 means the user has been authenticated but his level of access is not sufficient to access this resource.

Both ycmd and JediHTTP work use a 401.

Relevant SO answer which goes into more detail.

Put more simply, 401 is authentication failure whereas 403 is authorization failure.

@Valloric
Copy link
Contributor Author

Valloric commented Feb 7, 2016

Note that RFC's say that you MUST send the www-authenticate header in the 401 response with a "challenge." Docs: https://httpstatuses.com/401

ycmd currently doesn't do this, but I have a branch where I'm working on adding it. My www-authenticate header value will be:

Request should have x-ycm-hmac header set to base64(HmacSHA256(HmacSHA256(method, key) + HmacSHA256(path, key) + HmacSHA256(body, key)), key). Key is provided on server startup in options file.

@vheon Similar for JediHTTP. Needs a www-authenticate header. Since you're using Bottle, here's what you might want to use instead of abort() (from my ycmd branch):

from bottle import HTTPError
...
def RespondWithUnauthorized():
  _logger.info( 'Dropping request with bad Host header.' )
  error = HTTPError( httplib.UNAUTHORIZED,
                     'Unauthorized, received bad Host header.' )
  error.add_header( _WWW_AUTH_HEADER, _WWW_AUTH_MESSAGE )
  raise error

Verified to work.

@jwilm
Copy link
Owner

jwilm commented Feb 7, 2016

Thanks for filing the issue; i'll fix this today. I went to peak at your ycmd branch to see what challenge you were returning, but it appears to have not been pushed for several days.

@Valloric
Copy link
Contributor Author

Valloric commented Feb 7, 2016

Yeah the branch I'm talking about is still on my workstation. I need to write tests for our hmac middleware and that will take time I don't have right now (I'm porting ycmd to run on Python 2 & 3).

But I quote the "challenge" above. It's literally the quoted text.

@vheon
Copy link

vheon commented Feb 7, 2016

But I quote the "challenge" above. It's literally the quoted text.

So we should return the instruction on the authorization? It wasn't clear for me 😭

@Valloric
Copy link
Contributor Author

Valloric commented Feb 8, 2016

The RFC is unclear beyond that the response must have WWW-Authentication header with info on how to authenticate. There's a specific scheme when using HTTP Basic Auth, but we aren't, so the value is whatever we want it to be.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants