Blog | G5 Cyber Security

HTTPS Login Security: Don’t Send Passwords!

TL;DR

Sending usernames and passwords with every HTTPS request is a very bad idea. It’s insecure, unnecessary, and easily exploitable. Use session cookies or tokens instead.

Why Sending Credentials With Every Request Is Dangerous

While HTTPS encrypts the data in transit, repeatedly sending login details exposes you to several risks:

How to Securely Handle Login Information

The correct way is to authenticate once and then maintain that authentication without repeatedly asking for login details.

1. Authentication Process

  1. User Logs In: The user enters their username and password on a secure (HTTPS) page.
  2. Server Verifies: The server checks the credentials against its database.
  3. Session Creation: If valid, the server creates a session for the user. This session is identified by a unique ID.
  4. Session Cookie/Token: The server sends this session ID back to the user’s browser as an HTTP cookie or in a token (e.g., JWT).

2. Subsequent Requests

For every following request, the browser automatically includes the session cookie/token.

# Example cookie settings in PHP
setcookie('session_id', $session_id, [ 'secure' => true, 'httponly' => true]);

3. Session Management

4. Tokens (e.g., JWT)

JSON Web Tokens (JWTs) are another option, particularly for APIs or stateless applications.

# Example Authorization header
Authorization: Bearer <your_jwt_token>

Checking for Incorrect Implementation

  1. Browser Developer Tools: Use your browser’s developer tools (Network tab) to inspect the requests. Look for username/password fields in the request payload after login.
  2. Server Logs: Check server logs for any accidental recording of passwords.
  3. Code Review: Carefully review authentication code to ensure it’s not sending credentials with every request.
Exit mobile version