Get a Pentest and security assessment of your IT network.

Cyber Security

HTTP GET Request Tokens: Security Risks

TL;DR

Hackers can find secret tokens passed in HTTP GET requests if they aren’t properly protected. This is a serious security risk. The best way to avoid this is to never pass sensitive data like tokens in the URL. Use POST requests with secure cookies or headers instead.

Why Tokens in GET Requests are Dangerous

HTTP GET requests send data as part of the URL. This has several security implications:

  • Browser History: URLs are stored in browser history, making tokens accessible to anyone with access to that computer.
  • Server Logs: Web servers often log all incoming requests, including the full URL and its parameters.
  • Referrer Header: The URL is sometimes sent in the Referrer header when a user clicks a link on one page to another.
  • Caching: GET requests are often cached by browsers and proxy servers, potentially exposing tokens for extended periods.

Because of these risks, any sensitive information – especially authentication tokens – should never be transmitted via GET.

How Hackers Exploit Tokens in GET Requests

  1. Sniffing Network Traffic: If the connection isn’t encrypted (HTTPS), an attacker can intercept the URL and steal the token.
  2. Log File Analysis: Attackers who gain access to server logs can search for tokens within the request URLs.
  3. Browser History Access: Someone with access to a user’s browser history can find exposed tokens.
  4. Referrer Header Exploitation: An attacker controlling a website linked from your site could potentially capture the token if it’s in the Referrer header.

How to Protect Against Token Exposure

Here’s how to prevent tokens being exposed via GET requests:

  1. Use POST Requests: Always use HTTP POST requests for sending sensitive data like authentication tokens. POST sends the data in the request body, not the URL.
    curl -X POST 
      -H "Content-Type: application/json" 
      -d '{"username": "your_user", "password": "your_password"}' 
      https://example.com/login
  2. Secure Cookies: Store tokens in secure, HTTPOnly cookies.
    • Secure Flag: Ensure the cookie is only transmitted over HTTPS.
    • HTTPOnly Flag: Prevent client-side JavaScript from accessing the cookie (mitigates XSS attacks).
    • SameSite Attribute: Control how cookies are sent with cross-site requests to prevent CSRF attacks. Set to ‘Strict’ or ‘Lax’.
  3. Use Headers: Pass tokens in custom HTTP headers.
    curl -H "X-Auth-Token: your_token" https://example.com/api/resource
  4. HTTPS Everywhere: Always use HTTPS to encrypt all communication between the client and server, protecting data in transit.
  5. Short Token Lifetimes: Implement short token expiration times and require frequent renewal.
  6. Regular Security Audits: Regularly review your code and infrastructure for potential vulnerabilities.

Example of a Bad Practice (Avoid!)

Sending a token directly in the URL:

https://example.com/resource?token=your_secret_token

This is highly insecure and should be avoided at all costs.

Related posts
Cyber Security

Zip Codes & PII: Are They Personal Data?

Cyber Security

Zero-Day Vulnerabilities: User Defence Guide

Cyber Security

Zero Knowledge Voting with Trusted Server

Cyber Security

ZeroNet: 51% Attack Risks & Mitigation