Add safeguards against accidental AllowInsecureHTTP use in production #96
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
From security review on PR #93 (review #2870, finding #2):
The
AllowInsecureHTTPoption permits sending credentials over HTTP when enabled. Although documented for trusted/internal use, accidental enablement in production would expose tokens over cleartext.Proposed improvements:
REVIEW_BOT_ALLOW_INSECURE=1) in addition to the optionThis adds defense-in-depth so that misconfiguration doesn't silently degrade security.
Ref: PR #93 review #2870
Plan: Add safeguards against accidental AllowInsecureHTTP use in production
Problem
AllowInsecureHTTP()is a client option that permits sending credentials over HTTP. It's currently a simple boolean with no guardrails — if someone passes it in production code, credentials silently flow over cleartext. Tests use it heavily (httptest servers are HTTP), but production usage would be a security incident.Constraints
AllowInsecureHTTP()withhttptest.Server)gopkg.in/yaml.v3)githubpackage currently has zeroslogorlogimports — adding structured logging is acceptableProposed Approach
Three-layer defense:
Environment gate: When
AllowInsecureHTTP()is active, require env varREVIEW_BOT_ALLOW_INSECURE=1. Without it, the option is silently ignored (treated as if not set). This prevents accidental enablement from config drift.Warning log on activation: When the env gate IS satisfied and insecure mode activates, emit a
slog.Warnso operators notice in production logs. The warning fires once at client construction time.Test build tag alternative: Provide
AllowInsecureHTTPForTest()— a separate option that skips the env gate. Tests use this instead, keeping test code clean while production code requires the env gate. This avoids needingt.Setenv(...)in every test.Implementation detail:
In
clientConfigandClient:In
NewClient:AllowInsecureHTTPForTest()sets bothallowInsecureHTTPandinsecureIsTestBypassto true, bypassing the env check. Existing tests switch fromAllowInsecureHTTP()toAllowInsecureHTTPForTest().Files Changed
github/client.goinsecureIsTestBypassfield, env gate logic inNewClient,AllowInsecureHTTPForTest()option, addlog/slog+osimportsgithub/client_test.goAllowInsecureHTTPForTest(), add tests for env gate behaviorgithub/pr_test.goAllowInsecureHTTPForTest()github/files_test.goAllowInsecureHTTPForTest()github/helpers_test.goAllowInsecureHTTPForTest()Error Cases
AllowInsecureHTTP()without env var → option silently disabled, warning logged, credentials still protectedAllowInsecureHTTP()with env var → works, but warning logged (operators notice)AllowInsecureHTTPForTest()→ always works, no env check (test-only path)AllowInsecureHTTP()→ no env gate needed (existing logic already skips check when token is empty)Edge Cases
Testing Strategy
AllowInsecureHTTP()without env → HTTP request refused (same as no option)AllowInsecureHTTP()with envREVIEW_BOT_ALLOW_INSECURE=1→ HTTP permittedAllowInsecureHTTPForTest()→ HTTP permitted without env varAllowInsecureHTTPForTest()Open Questions
AllowInsecureHTTP()without the env var return an error fromNewClientrather than silently disabling? I lean toward silent disable + warning log becauseNewClientcurrently has no error return. Changing the signature would be a breaking API change for a defense-in-depth feature. The warning log provides visibility.REVIEW_BOT_ALLOW_INSECUREor something more generic likeALLOW_INSECURE_HTTP? Using theREVIEW_BOT_prefix avoids namespace collisions with other tools.