Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions workspace-server/internal/middleware/wsauth_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ func CanvasOrBearer(database *sql.DB) gin.HandlerFunc {
}

c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "admin auth required"})
return
}
}

Expand Down
11 changes: 11 additions & 0 deletions workspace-server/internal/middleware/wsauth_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,11 @@ func TestCanvasOrBearer_TokensExist_NoCreds_Returns401(t *testing.T) {
if w.Code != http.StatusUnauthorized {
t.Errorf("no creds: got %d, want 401", w.Code)
}
// Audit #32 regression: without `return` after AbortWithStatusJSON the handler
// overwrites the 401 with its own 200 body. Explicitly check the handler did NOT run.
if body := w.Body.String(); body == `{"ok":true}` {
t.Errorf("no creds: handler was called after AbortWithStatusJSON (got body %q — should be auth error, not handler output)", body)
}
}

func TestCanvasOrBearer_TokensExist_CanvasOrigin_Passes(t *testing.T) {
Expand Down Expand Up @@ -925,6 +930,12 @@ func TestCanvasOrBearer_TokensExist_WrongOrigin_Returns401(t *testing.T) {
if w.Code != http.StatusUnauthorized {
t.Errorf("wrong origin: got %d, want 401", w.Code)
}
// Audit #32 regression: missing `return` after AbortWithStatusJSON caused requests
// to flow into the handler after writing 401, overwriting the status and body.
// Verify the final response is definitively the auth error, not handler output.
if body := w.Body.String(); body == `{"ok":true}` {
t.Errorf("wrong origin: handler was called after AbortWithStatusJSON (got body %q — should be auth error, not handler output)", body)
}
}

func TestCanvasOriginAllowed_EmptyOriginRejected(t *testing.T) {
Expand Down
Loading