-
Notifications
You must be signed in to change notification settings - Fork 61
fix(api,ui): remaining Tier-0 security hardening (#157-#164) #238
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c8c1ec2
fix(api): scope workspace-level labels to the caller's workspace (#157)
nazarli-shabnam 9274b2e
fix(api): bind invite join to invited email and make accept atomic (#…
nazarli-shabnam 7dd3dd6
fix(api): add rate limiting on auth endpoints and fix magic-code lock…
nazarli-shabnam 95f65c8
fix(api): cap upload size and add nosniff/Content-Disposition on Serv…
nazarli-shabnam 706d42e
fix(api): accept API tokens in auth middleware (#162)
nazarli-shabnam 3d09582
fix(ui): gate instance-admin routes on real admin status (#163)
nazarli-shabnam 274a6d8
chore(ui): delete dead mock instance-admin login page (#164)
nazarli-shabnam 6fa5c89
fix(api,ui): address code-review findings on combined security PR
nazarli-shabnam 99ff69b
fix(api): address CodeRabbit findings on auth middleware and rate lim…
nazarli-shabnam 530c6de
fix(ci): use apps/web's pinned prettier in lint-staged to match CI, f…
nazarli-shabnam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| package handler_test | ||
|
|
||
| import ( | ||
| "context" | ||
| "net/http" | ||
| "testing" | ||
|
|
||
| "github.com/Devlaner/devlane/api/internal/model" | ||
| "github.com/Devlaner/devlane/api/internal/testutil" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // TestWorkspace_JoinByToken_RejectsEmailMismatch proves a workspace invite | ||
| // token can't be redeemed by an account whose email doesn't match the | ||
| // invited email (a leaked/forwarded token must not grant membership). | ||
| func TestWorkspace_JoinByToken_RejectsEmailMismatch(t *testing.T) { | ||
| ts := testutil.NewTestServer(t) | ||
| owner := testutil.CreateUser(t, ts.DB) | ||
| w := testutil.CreateWorkspace(t, ts.DB, owner.ID) | ||
| inv := testutil.CreateWorkspaceInvite(t, ts.DB, w.ID, "invited@test.local", "tok-mismatch-111") | ||
|
|
||
| stranger := testutil.CreateUser(t, ts.DB) // email is stranger-N@test.local, not invited@test.local | ||
| session := testutil.LoginAs(t, ts.DB, stranger) | ||
|
|
||
| rr := ts.POST("/api/workspaces/join/", map[string]any{"token": inv.Token}, session) | ||
| require.Equal(t, http.StatusNotFound, rr.Code, "body=%s", rr.Body.String()) | ||
| } | ||
|
|
||
| // TestWorkspace_JoinByToken_AcceptsEmailMatch proves the happy path still | ||
| // works when the joining account's email matches the invite. | ||
| func TestWorkspace_JoinByToken_AcceptsEmailMatch(t *testing.T) { | ||
| ts := testutil.NewTestServer(t) | ||
| owner := testutil.CreateUser(t, ts.DB) | ||
| w := testutil.CreateWorkspace(t, ts.DB, owner.ID) | ||
|
|
||
| invitee := testutil.CreateUser(t, ts.DB) | ||
| email := invitee.Email | ||
| require.NotNil(t, email) | ||
| inv := testutil.CreateWorkspaceInvite(t, ts.DB, w.ID, *email, "tok-match-111") | ||
| session := testutil.LoginAs(t, ts.DB, invitee) | ||
|
|
||
| rr := ts.POST("/api/workspaces/join/", map[string]any{"token": inv.Token}, session) | ||
| require.Equal(t, http.StatusOK, rr.Code, "body=%s", rr.Body.String()) | ||
| } | ||
|
|
||
| func TestProject_JoinByToken_RejectsEmailMismatch(t *testing.T) { | ||
| ts := testutil.NewTestServer(t) | ||
| owner := testutil.CreateUser(t, ts.DB) | ||
| w := testutil.CreateWorkspace(t, ts.DB, owner.ID) | ||
| p := testutil.CreateProject(t, ts.DB, w.ID, owner.ID) | ||
|
|
||
| inv := &model.ProjectMemberInvite{ | ||
| ProjectID: p.ID, | ||
| WorkspaceID: w.ID, | ||
| Email: "invited@test.local", | ||
| Token: "proj-tok-mismatch-111", | ||
| Role: testutil.RoleMember, | ||
| } | ||
| require.NoError(t, ts.DB.WithContext(context.Background()).Create(inv).Error) | ||
|
|
||
| stranger := testutil.CreateUser(t, ts.DB) | ||
| session := testutil.LoginAs(t, ts.DB, stranger) | ||
|
|
||
| rr := ts.POST("/api/workspaces/"+w.Slug+"/projects/join/", map[string]any{"token": inv.Token}, session) | ||
| require.Equal(t, http.StatusNotFound, rr.Code, "body=%s", rr.Body.String()) | ||
| } | ||
|
|
||
| func TestProject_JoinByToken_AcceptsEmailMatch(t *testing.T) { | ||
| ts := testutil.NewTestServer(t) | ||
| owner := testutil.CreateUser(t, ts.DB) | ||
| w := testutil.CreateWorkspace(t, ts.DB, owner.ID) | ||
| p := testutil.CreateProject(t, ts.DB, w.ID, owner.ID) | ||
|
|
||
| invitee := testutil.CreateUser(t, ts.DB) | ||
| testutil.AddWorkspaceMember(t, ts.DB, w.ID, invitee.ID, testutil.RoleMember) | ||
| email := invitee.Email | ||
| require.NotNil(t, email) | ||
|
|
||
| inv := &model.ProjectMemberInvite{ | ||
| ProjectID: p.ID, | ||
| WorkspaceID: w.ID, | ||
| Email: *email, | ||
| Token: "proj-tok-match-111", | ||
| Role: testutil.RoleMember, | ||
| } | ||
| require.NoError(t, ts.DB.WithContext(context.Background()).Create(inv).Error) | ||
|
|
||
| session := testutil.LoginAs(t, ts.DB, invitee) | ||
| rr := ts.POST("/api/workspaces/"+w.Slug+"/projects/join/", map[string]any{"token": inv.Token}, session) | ||
| require.Equal(t, http.StatusOK, rr.Code, "body=%s", rr.Body.String()) | ||
| } |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.