Compare commits

...

1 Commits

Author SHA1 Message Date
fullstack-engineer afc282c556 fix(channels): remove duplicate EncryptSensitiveFields + log json.Marshal errors
Runtime PR-Built Compatibility / PR-built wheel + import smoke (pull_request) Blocked by required conditions
Block internal-flavored paths / Block forbidden paths (pull_request) Successful in 28s
Harness Replays / detect-changes (pull_request) Successful in 31s
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 34s
qa-review / approved (pull_request) Successful in 38s
security-review / approved (pull_request) Successful in 37s
CI / Detect changes (pull_request) Successful in 1m51s
lint-required-no-paths / lint-required-no-paths (pull_request) Successful in 1m41s
E2E API Smoke Test / detect-changes (pull_request) Successful in 1m56s
Handlers Postgres Integration / detect-changes (pull_request) Successful in 2m3s
Harness Replays / Harness Replays (pull_request) Successful in 15s
CI / Shellcheck (E2E scripts) (pull_request) Successful in 17s
CI / Python Lint & Test (pull_request) Successful in 15s
Runtime PR-Built Compatibility / detect-changes (pull_request) Failing after 10m50s
Handlers Postgres Integration / Handlers Postgres Integration (pull_request) Successful in 6m45s
E2E API Smoke Test / E2E API Smoke Test (pull_request) Failing after 10m58s
sop-tier-check / tier-check (pull_request) Successful in 41s
CI / Canvas (Next.js) (pull_request) Successful in 20m50s
CI / Platform (Go) (pull_request) Failing after 21m59s
CI / Canvas Deploy Reminder (pull_request) Has been skipped
gate-check-v3 / gate-check (pull_request) Failing after 14m21s
CI / all-required (pull_request) Failing after 10m32s
sop-checklist / all-items-acked (pull_request) [info tier:low] acked: 0/7 — missing: comprehensive-testing, local-postgres-e2e, staging-smoke, +4
audit-force-merge / audit (pull_request) Has been skipped
- Create: remove the duplicate EncryptSensitiveFields call introduced
  during OFFSEC-010 conflict resolution (commit 58882381). The
  function is idempotent so impact was nil (wasted CPU), but the block
  was dead code.
- Create: add error checks on json.Marshal for config and allowed_users
  (previously j, _ := json.Marshal(...) silently dropped marshal failures).
- Update: add error checks on json.Marshal for config and allowed_users
  (same silent-discard pattern). Also renamed the EncryptSensitiveFields
  error variable to encErr to avoid shadowing the outer err used by
  db.DB.ExecContext.

This PR complements #1109 (merge-queue: json.Unmarshal + rows.Err) and
#1110 (duplicate EncryptSensitiveFields removal) — those two cover the
same channels.go surface but neither adds json.Marshal error checks.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-15 04:18:09 +00:00
+24 -13
View File
@@ -149,17 +149,18 @@ func (h *ChannelHandler) Create(c *gin.Context) {
return
}
// #319: encrypt sensitive fields (bot_token, webhook_secret) before
// persisting so a DB read/backup leak can't recover the credentials.
// Validation above ran against plaintext; storage is ciphertext.
if err := channels.EncryptSensitiveFields(body.Config); err != nil {
log.Printf("Channels: encrypt config failed for workspace %s: %v", workspaceID, err)
c.JSON(http.StatusInternalServerError, gin.H{"error": "encrypt failed"})
configJSON, mErr := json.Marshal(body.Config)
if mErr != nil {
log.Printf("Channels Create: marshal config for workspace %s: %v", workspaceID, mErr)
c.JSON(http.StatusInternalServerError, gin.H{"error": "marshal config failed"})
return
}
allowedJSON, mErr := json.Marshal(body.AllowedUsers)
if mErr != nil {
log.Printf("Channels Create: marshal allowed_users for workspace %s: %v", workspaceID, mErr)
c.JSON(http.StatusInternalServerError, gin.H{"error": "marshal allowed_users failed"})
return
}
configJSON, _ := json.Marshal(body.Config)
allowedJSON, _ := json.Marshal(body.AllowedUsers)
enabled := true
if body.Enabled != nil {
enabled = *body.Enabled
@@ -209,16 +210,26 @@ func (h *ChannelHandler) Update(c *gin.Context) {
// #319: re-encrypt sensitive fields on every config update — the
// PATCH body carries plaintext (client already had them plaintext in
// List response's unmasked path or typed fresh).
if err := channels.EncryptSensitiveFields(body.Config); err != nil {
log.Printf("Channels: encrypt update for workspace %s: %v", workspaceID, err)
if encErr := channels.EncryptSensitiveFields(body.Config); encErr != nil {
log.Printf("Channels: encrypt update for workspace %s: %v", workspaceID, encErr)
c.JSON(http.StatusInternalServerError, gin.H{"error": "encrypt failed"})
return
}
j, _ := json.Marshal(body.Config)
j, mErr := json.Marshal(body.Config)
if mErr != nil {
log.Printf("Channels Update: marshal config for channel %s: %v", channelID, mErr)
c.JSON(http.StatusInternalServerError, gin.H{"error": "marshal config failed"})
return
}
configArg = string(j)
}
if body.AllowedUsers != nil {
j, _ := json.Marshal(body.AllowedUsers)
j, mErr := json.Marshal(body.AllowedUsers)
if mErr != nil {
log.Printf("Channels Update: marshal allowed_users for channel %s: %v", channelID, mErr)
c.JSON(http.StatusInternalServerError, gin.H{"error": "marshal allowed_users failed"})
return
}
allowedArg = string(j)
}