security(teams): authorize /teams from the session, not the global users.role_id (#830) - #844
Open
alex-dembele wants to merge 3 commits into
Open
alex-dembele wants to merge 3 commits into
alex-dembele wants to merge 3 commits into
Conversation
…ole_id (#830) Every /teams handler re-checked the global users.role_id and looked the caller up by the token id (claims.ID) instead of the user id, so each call answered 404 before the check ran. The RequireRole("admin") route guard already authorizes these routes from the caller's role in the active organization; the in-handler checks are removed. AddTeamMember now also requires the target's membership to be active and answers a malformed id with the same 404 as an unknown one. DeleteTeam removes the members and the team in one transaction. Team and member ids are set explicitly rather than left to a Postgres-only column default. Signed-off-by: alex-dembele <alexandredembele16@gmail.com>
…#830) Signed-off-by: alex-dembele <alexandredembele16@gmail.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #830
Decision (criterion 1): kept and fixed, not removed
/teamshas no UI, no OpenAPI entry and no product claim, and it had never worked: every call returned 404. Removing a module would be a product decision, and the issue allowed either outcome. So this PR repairs it along criteria 2 to 4. If you'd rather drop the module, that is a separate, small PR: delete the 7 routes and the handler. The tables stay, so no migration is needed.What changed (
internal/handler/team_handler.go)currentUser.Role.Name != "admin"checks are removed (criterion 2). They read the globalusers.role_id, and they looked the caller up byclaims.ID(the JWT id) instead ofclaims.Sub, which is why everything returned 404. Authorization is theRequireRole("admin")route guard, which reads the caller's role in the active organization.AddTeamMemberrequires an active membership in the caller's tenant (criterion 3). A foreign user, a withdrawn member, an unknown id and a malformed id all get the same404 {"error":"User not found"}. Before, a malformed id could reachuuid.MustParse.DeleteTeamremoves the members and the team in one transaction (rule 7).uuid.New()instead of relying on the Postgres-onlygen_random_uuid()default.Verification
All three new tests fail against the old handler.
The DoD grep
grep -rn 'Role.Name != "admin"' internal/handler/now returns only the four hits inuser_handler.go. PR #832 (#807) removes those, so the grep is empty once both are merged.Honest remainders
/teams.GetTeamstill loads each member's user row one query at a time (N+1). It existed before this PR and is untouched, because this is a security fix.