Reddit OAuth Credential Validation Flaw Exposes Authentication Bypass Risk
A high-severity security vulnerability has been identified in a codebase handling Reddit API authentication. The flaw resides in a function that directly uses environment variables containing Reddit OAuth credentials to construct an HTTP Basic Authentication header without any input validation. This creates a direct path for authentication bypass or header injection if the stored credentials contain specific special characters.
The vulnerability is located in the `getToken()` function within a TypeScript file. The code concatenates the `CLIENT_ID` and `CLIENT_SECRET` environment variables with a colon and then encodes the result to base64. The critical failure is the lack of sanitization: if either credential string contains a colon character, it corrupts the Basic Auth parsing, causing the server to misinterpret the username and password fields. Furthermore, if a credential contains a newline character, it could be leveraged to inject arbitrary headers into the HTTP request.
While the probability of exploitation is assessed as low—requiring an attacker to control or manipulate the environment variables—the potential impact is high, enabling a complete bypass of the intended authentication mechanism. The finding underscores a lapse in defense-in-depth practices, where the integrity of credential formatting is assumed rather than validated. The core recommendation is to implement strict input validation on the credentials before they are used to construct the authentication header, preventing malformed strings from breaking the security model.