Closed Bug 1477163 Opened 7 years ago Closed 7 years ago

REST API authentication fails with X-Bugzilla-Token header

Categories

(bugzilla.mozilla.org :: API, defect)

Production
defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: kohei, Assigned: kohei)

References

Details

Attachments

(1 obsolete file)

REST API with `X-Bugzilla-API-Key` HTTP header: OK REST API with `X-Bugzilla-Token` HTTP header: *NG* REST API with `Bugzilla_api_key` param: OK REST API with `Bugzilla_api_token` param: OK JSON-RPC API with `X-Bugzilla-API-Key` HTTP header: OK JSON-RPC API with `X-Bugzilla-Token` HTTP header: OK JSON-RPC API with `Bugzilla_api_key` param: OK JSON-RPC API with `Bugzilla_api_token` param: OK
On most accounts, API token will only work if cookies are also sent.
Assignee: nobody → kohei.yoshino
Status: NEW → ASSIGNED
Which fixes a security bug. Here's what we should actually do (in about that place) trust cookies for API calls, if a custom header is set and the Origin header is valid.
Maybe I shouldn’t touch this stuff 😉 Basically removing the `elsif` clause solves the issue: trust cookies for REST API calls just like JSON-RPC. There are too many authentication methods... Should we remove the token support in favour of cookies?
Some context in Bug 1139257. If we fix the issue straightforwardly, these 2 lines have to be altered to check the header as well: ```Perl if (exists Bugzilla->input_params->{Bugzilla_api_token}) { my $api_token = Bugzilla->input_params->{Bugzilla_api_token}; ```
(In reply to Kohei Yoshino [:kohei] from comment #4) > Maybe I shouldn’t touch this stuff 😉 > > Basically removing the `elsif` clause solves the issue: trust cookies for > REST API calls just like JSON-RPC. > > There are too many authentication methods... Should we remove the token > support in favour of cookies? The landscape changed a bit with SameSite cookies too.. I'll tell you what, I'll fix this so that the REST api just uses cookies + the current recommendations for preventing request forgery.
Assignee: kohei.yoshino → dylan
Bug 1380437 should be solved first so the `Bugzilla_api_token` param can be removed easily from JavaScript at one place.
No longer blocks: 1380437
Depends on: 1380437
Summary: REST API authentication fails with X-Bugzilla-Token header → Remove REST API token authentication (Bugzilla_api_token URL query param) to simply trust login cookies
I thought tokens had been used only on this site, but just realized it was available via the API [1]. In that case, I assume we can’t remove the support now. Deprecating it is fine though. Maybe we should fix the original issue I reported so the X-Bugzilla-Token HTTP request header works as expected, as said in Comment 5. [1] https://bmo.readthedocs.io/en/latest/api/core/v1/user.html
Also, an interesting fact is, according to the document, the official query param name is not `Bugzilla_api_token` used on Bugzilla but `Bugzilla_token` or `token`. Both don’t work. https://bmo.readthedocs.io/en/latest/api/core/v1/general.html#authentication
Reverting the summary and adding the facts mentioned in my Comment 9.
Summary: Remove REST API token authentication (Bugzilla_api_token URL query param) to simply trust login cookies → REST API authentication fails with X-Bugzilla-Token header or token/Bugzilla_token query param
Attached file pull request (obsolete) —
Sent a PR to solve the original issue.
Assignee: dylan → kohei.yoshino
Hmm, `token` and `Bugzilla_token` query params are somewhat different, so the tests are failing. I’m just fixing the header issue then.
Summary: REST API authentication fails with X-Bugzilla-Token header or token/Bugzilla_token query param → REST API authentication fails with X-Bugzilla-Token header
Then the `X-Bugzilla-Token` header is also different. The token returned by `/rest/login` is Bugzilla_login + Bugzilla_logincookie: https://github.com/mozilla-bteam/bmo/blob/master/Bugzilla/WebService/User.pm#L472 It's called _login_ token, not an API token :( https://github.com/mozilla-bteam/bmo/blob/master/Bugzilla/Auth/Login/Cookie.pm#L146 In that case, this bug is INVALID. Or we could support a different header, like `X-Bugzilla-API-Token`.
Let’s revisit the auth methods while designing REST API v2.
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
Resolution: --- → INVALID
Attachment #8996521 - Attachment is obsolete: true
See Also: → 1209148
Type: enhancement → defect
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: