Blog | G5 Cyber Security

Protecting URL Query Strings Without HTTPS

TL;DR

While HTTPS is the best way to protect query strings (and everything else) in a URL, you can take steps to make sniffing them more difficult. These aren’t foolproof – they add layers of obscurity, not security. The main techniques are encryption client-side before sending and obfuscation.

Protecting Query Strings Without HTTPS

  1. Understand the Risk
  • Client-Side Encryption
  • Encrypt the query string in the browser before sending it in the URL. Decrypt it after receiving it on the server.

    // Encryption in browser
    const queryString = 'sensitive_data=value&another=other';
    const encrypted = CryptoJS.AES.encrypt(queryString, 'secretKey').toString();
    const url = '/your-endpoint?' + encodedURIComponent(encrypted);
    
    // Decryption on server (Node.js example)
    const decryptedBytes  = CryptoJS.AES.decrypt(req.query.encrypted, 'secretKey');
    const originalText = decryptedBytes.toString(CryptoJS.enc.Utf8);
  • Important: Keep the encryption key secret! Do not embed it directly in your JavaScript code where it can be easily extracted. Consider fetching it from a secure source (though this introduces other complexities).
  • Obfuscation (Not Encryption)
  • Make the query string harder to read, but not truly secret. This is less effective than encryption.

  • Short-Lived Tokens
  • If the query string contains a token, make it expire quickly. This limits the window of opportunity for an attacker.

  • Consider POST Requests
  • If possible, send the data in the body of a POST request instead of as query string parameters. This doesn’t prevent sniffing entirely but makes it slightly harder to extract information directly from URLs.

  • Important Disclaimer
  • Exit mobile version