Merge pull request #209 from Molecule-AI/fix/c2-source-id-spoof-check

fix(security): C2 from #169 — reject spoofed source_id in activity.Report
This commit is contained in:
Hongming Wang 2026-04-15 11:15:14 -07:00 committed by GitHub
commit da20ae4717
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -329,7 +329,18 @@ func (h *ActivityHandler) Report(c *gin.Context) {
if reqBody == nil {
reqBody = body.Metadata
}
// C2 (from #169) — source_id spoof defense. WorkspaceAuth middleware
// already proves the caller owns :id, but that check doesn't cover the
// body field. Without this guard, workspace A authenticated for its own
// /activity endpoint could still set source_id=<workspace B's UUID> in
// the payload and attribute the log to B. Reject any body where
// source_id is non-empty AND differs from the authenticated workspace.
// Empty source_id falls through to the default-to-self branch below.
sourceID := body.SourceID
if sourceID != "" && sourceID != workspaceID {
c.JSON(http.StatusForbidden, gin.H{"error": "source_id must match authenticated workspace"})
return
}
if sourceID == "" {
sourceID = workspaceID
}