Sensitive information in URLs

Sensitive information in C# URLs

Description

A password, API key, or token in a query string can persist in browser history, caches, and server or proxy logs, even over HTTPS.

Potential impact

Sharing the URL can disclose the value. Depending on the referrer policy and destination, the Referer header can also include it.

Remediation

Send passwords in an HTTPS request body and bearer tokens in the Authorization header. Keep only non-sensitive identifiers and filters in URLs.

Examples

Before

csharp
[HttpGet("reset")]
public IActionResult Reset([FromQuery] string newPassword)
{
    return Ok();
}

After

csharp
[HttpPost("reset")]
public IActionResult Reset([FromBody] ResetPasswordRequest request)
{
    return Ok();
}

The reset action changes from [FromQuery] on GET to [FromBody] on POST. Update the client to send the new password in the body. Both actions omit the reset itself.

References