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

Proposal: limit api routes to access by token/basic auth only #4794

Closed
beeonthego opened this issue Aug 26, 2018 · 4 comments
Closed

Proposal: limit api routes to access by token/basic auth only #4794

beeonthego opened this issue Aug 26, 2018 · 4 comments
Labels
modifies/api This PR adds API routes or modifies them

Comments

@beeonthego
Copy link
Contributor

As pointed out in issue #4703 (content deleted now), it is a csrf vulnerability to allow users to access api routes using session cookie without second check.

Currently the CSRF middleware only checks POST requests, and skips API routes. In addition, the reqToken function in routers/api/v1/api.go accepts all signed in users, including authenticated with session cookie. This means a script can make a POST/DELETE request to api routes while user is logged in (cookie present), without user's knowledge or consent. This is not desirable in multi tenant environment.

We have implemented some extra checks internally to limit api routes to access by token/basic auth only, and prohibit access by cookie when the route requires token. This does not affect public routes.

We have searched the code base and haven't found any client side Javascript code accessing protected api routes with cookie. But maybe there are cases we are not aware.
Is this the right approach? Will a PR like this break someone's code in the pipeline (if merged)?

@lafriks
Copy link
Member

lafriks commented Aug 26, 2018

There is repo/org search in user dashboard that uses it. If that would be changed to not use API, I agree

@beeonthego
Copy link
Contributor Author

Thanks for the insight. I thought I may have missed something. I did.

Here are the JS functions and api routes I have found in compiled JS file in user dashboard. The reqToken middleware was not present when registering routes. That is why I thought these were public routes. However I have just looked at the handler function and the access check is actually in the function.

searchUsers: /api/v1/users/search (public ?)
searchRepositories: /api/v1/repos/search (access check in function)
searchURL: /api/v1/repos/search (access check in function)
apiSettings: /api/v1/topics/search (access check in function)

Is it better to inject an access token to the dashboard page, and send the token back when making API requests? this will be similar to how csrf token is handled now. As long as we don't allow dashboard to load in cross site iFrame, it should be safe, as there is no content generated by other users in dashboard.

your thoughts?

@techknowlogick techknowlogick added the modifies/api This PR adds API routes or modifies them label Aug 26, 2018
@beeonthego
Copy link
Contributor Author

I have just submitted PR #4840 to address a critical security issue reported in issue #4357 . It has passed all tests except two db tests. When token is enforced on API routes, reqToken will do its job as its name suggests, ask for a token. It will reject requests if token is not provided.

The current tests look for records and the records are not supposed to be there when token is enforced on API routes. Could someone review and rewrite the tests?

IMHO, API routes are designed for consumption by apps or remote servers, and private routes are protected with a key or token. Accepting authentication by cookie on API routes opens a can of worms.

POST requests on UI routes check the second factor of CSRF token. The current API routes are not covered by csrf handler. If someone has discovered a creative way to bypass markdown parser/sanitizer and run their code, they can make requests to the API routes using someone else's cookie. This is not an issue in a single user/team environment. things are different when there are multiple users.

@lunny
Copy link
Member

lunny commented Sep 11, 2018

closed by #4840

@lunny lunny closed this as completed Sep 11, 2018
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
modifies/api This PR adds API routes or modifies them
Projects
None yet
Development

No branches or pull requests

4 participants