Skip to content

Commit 9e100c2

Browse files
Potential fix for code scanning alert no. 98: Clear-text logging of sensitive information (#90)
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 8aad92e commit 9e100c2

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

modules/reverseproxy/module.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,9 +1784,13 @@ func (m *ReverseProxyModule) createReverseProxyForBackend(ctx context.Context, t
17841784
}
17851785
if err := m.responseHeaderModifier(resp, backendID, tenantID); err != nil {
17861786
if m.app != nil && m.app.Logger() != nil {
1787-
// Sanitize tenantID before logging to prevent log forging via newlines
1788-
safeTenantID := strings.ReplaceAll(strings.ReplaceAll(string(tenantID), "\n", ""), "\r", "")
1789-
m.app.Logger().Error("Response header modifier error", "backend", backendID, "tenant", safeTenantID, "error", err.Error())
1787+
// Log a hashed representation of the tenant ID to avoid exposing it in clear text
1788+
tenantHashStr := ""
1789+
if hasTenant {
1790+
sum := sha256.Sum256([]byte(tenantID))
1791+
tenantHashStr = hex.EncodeToString(sum[:])
1792+
}
1793+
m.app.Logger().Error("Response header modifier error", "backend", backendID, "tenant_hash", tenantHashStr, "error", err.Error())
17901794
}
17911795
return err
17921796
}

0 commit comments

Comments
 (0)