Protecting credentials and messages
Passwords, sessionThe ongoing connection between later requests and an earlier sign-in, so you are not asked for your password on every click. It is often tracked with a cookie holding an unpredictable session identifier. cookies and tokens can each grant access because a service accepts them as evidence. Their protection must cover the connection, storage, validation and the point at which they should stop working.
Protecting the evidence
Ava's password proves useful at sign-in because the service treats it as evidence of control. Once she signs in, a session cookieA small value that a website asks the browser to store and send back with later matching requests. Cookies commonly carry a session identifier, so the site can recognize an ongoing sign-in without your password. may let her keep using the application. A tokenA piece of data issued by a trusted service that a client presents as a credential, for example to call an API or to report a sign-in. Some tokens carry readable claims; others are random strings that only the issuer can interpret. may let an application call an APIAn application programming interface: a defined way for software to interact with a service. A web API offers endpoints where other programs send HTTP requests.. Each value matters because another system is prepared to accept it.
Protecting identity means following that evidence through its lifetime: how it travels, where it is stored, who can read it, and when it stops working. Protecting the password while exposing the session cookie would leave another route into the same account.
Some evidence is weak before it is ever used. Billions of passwords from past breaches circulate in published lists, and attackers try those email and password pairs at other services, counting on people who reused them. This is credential stuffing. A password that appears in those lists offers little protection however long it is, so a careful service compares a new password against known breached passwords and refuses a match.
Password
- Used at
- Sign-in
- What it does
- Supplies evidence of account control
- Accepted by
- The service
Session cookie
- Used at
- Later pages
- What it does
- Can carry continuing access
- Accepted by
- The application
Access token
- Used at
- API calls
- What it does
- Can authorize requests
- Accepted by
- The API
Protecting the password while exposing the session cookie would leave another route into the same account.
A password that appears in published breach lists offers little protection however long it is.
Protecting data in transit
When Ava sends her password, HTTPSHTTP protected by TLS, so traffic is encrypted and checked for changes while it travels. It protects the connection, but does not prove that the site at the other end is honest. protects the connection using TLS. The browser checks the server's certificateA signed statement that a public key belongs to a name, such as a website's hostname, for stated purposes and a limited period. A certificate authority signs it, so software that trusts the authority can connect the key to the name. for the hostname and the applicable trust requirements, and the protocolAn agreed set of rules for the messages two systems exchange and what each message means. HTTP, OAuth 2.0, OpenID Connect and SAML are all protocols. establishes the protected connection.
Keys explain how that check works. The certificate contains the server's public key, and the certificate authority signs the certificate, binding that public key to the hostnames it names. The browser verifies the authority's signatureA value made with a private key that lets anyone holding the matching public key check that a message came from the key's holder and has not been changed. It proves origin and integrity; it does not hide the message. with a public key it already trusts. Together, the authorities, their certificates and the rules for issuing them make up a public key infrastructure, or PKI, that lets the browser connect the server's public key to the hostname it requested. The server must also prove possession of the corresponding private keyThe half of a key pair that its owner keeps to themselves and uses to create signatures or decrypt data. Anyone who obtains it can act as its owner. during the TLS exchange. That private key is the secret that never leaves the server, described in Clients, servers, and addresses.
That protects the journey to this server. It does not establish that the site is honest, that Ava chose the right hostname, or that the server stores her password safely after receiving it.
How the browser checks
The hostnames it names
The server's public key
Signed by the certificate authority
What it establishes
- The journey to this server
- Protected
- The site is honest
- Not established
- Ava chose the right hostname
- Not established
- Stores her password safely
- Not established
Storing and handling secrets
A service normally does not need to recover Ava's password later. It needs to check whether a new submission matches. A password hashingTurning data into a short, fixed-size value called a hash, in a way that cannot be reversed and where changing one character changes the result completely. Services store password hashes instead of passwords, and signatures are made over a hash. scheme stores a verifier derived from the password, using a unique salt and deliberately costly computation to make guessing more expensive.
Some secrets do need to be recovered or used later, such as a secret an application uses to call another service, or a private signing key. They need storage with tightly controlled access and suitable encryptionTransforming data so that only someone holding the right key can read it. It protects confidentiality and, unlike hashing, is designed to be reversed by the key holder. or key protection. Hashing a value is not a substitute when the service must use the original.
The same care applies to ordinary troubleshooting. A password, session cookie, recovery code, or token copied into a log or screenshot has become another copy to protect. Useful logs record what happened and why without recording the credential itself.
Ava's account
- Password
- The same password
- Salt
- Unique salt A
- Hashing
- Deliberately costly computation
- Stored verifier
- Verifier A
Another account
- Password
- The same password
- Salt
- Unique salt B
- Hashing
- Deliberately costly computation
- Stored verifier
- Verifier B
At sign-in the service checks whether a new submission matches. Hashing a value is not a substitute when the service must use the original.
Reading is not validating
An application receives a token and decodes it. It can now read an account identifier, an issuerThe party that creates and signs a token, assertion, or certificate, named in a token's iss claim. A recipient must check that the issuer is exactly the one it expected and trusts., and an expiry time. That is a useful inspection step, but the token is still just input.
Before accepting it, the recipient must validate the protection and the rules for this token type. Depending on the protocol, that includes the expected issuer, intended audience, allowed algorithm and trusted key, lifetime, and connection to the request. A valid signature alone does not make a token suitable for every recipient or purpose.
The JWT format from Keys, encryption, and signatures is one way these fields are carried. A signed JWT is commonly readable; encryption is a separate choice. Treating its encoded appearance as secrecy, or its decoded contents as verified facts, misses the protection it actually provides.
Reading a token is a useful inspection step, but the token is still just input.
The audience it names
- Signature: valid under the expected key
- Expected issuer
- Intended audience
- Lifetime
- Connection to the request
Suitable for this recipient
A different application
- Signature: valid under the expected key
- Expected issuer
- Intended audience: names a different application
- Lifetime
- Connection to the request
Reject the token here.
Encoding
album: 42
YWxidW06IDQy
Changes representation
- Does not make data secret
Signing
album: 42
Enables checks of integrity and signing key
- Does not hide the message
Encryption
album: 42
Protects confidentiality
- Readable with the right decryption key
Accepting a token also requires issuer, audience, time and token-type checks.
Limiting reuse
Imagine someone obtains a bearer token. If possession is enough to use it, they may be able to replay it, presenting the same token again, until the recipient stops accepting it. Short lifetimes limit that window, while revocation, cancelling a credential before it would expire, can end some credentials earlier when the system supports it.
Other designs bind a token to a key the client holds. The client must prove it has that key each time it presents the token, so a copied token alone is insufficient. That adds a different protection; it does not remove the need for expiry, validation, and careful handling.
When a token expires, an inspection tool may still display its text. Expiry changes whether a recipient should accept it, not whether the bytes remain readable.
Bearer token
- A copy presented alone
- Accepted until the recipient stops accepting it
- Its bytes
- Readable
A copied bearer token may be usable by its holder.
After expiry or effective revocation
- A copy presented alone
- Rejected
- Its bytes
- May still be readable
The recipient rejects it.
Bound to a key the client holds
- A copy presented alone
- Insufficient
- Its bytes
- Readable
The client must prove it has that key each time.
Binding adds a different protection; it does not remove the need for expiry, validation, and careful handling.
Check your understanding
Try these questions before moving on. If an answer isn't right, use the feedback and try again.
Try it in the Lab
- Protect a password and recognize a token that is too oldTry a known breached password, inspect the safe audit record, and watch a genuine token expire while its signature still verifies.