Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

What makes a sign-in or session weak

After this lesson: I can say what makes a sign-in or a session weak.

55 min lesson3 commandsWebGoat lab: guided web security lessons with WebWolf in your own copy

The password was 123456

A small firm's staff site lets people sign in with any password. Half of them chose 123456.

One evening someone tries a short list of common passwords against every name in the staff list. Within minutes they are in as the finance manager. The site had no limit on guesses.

The one rule

Warning

This lab is a set of lessons that are insecure on purpose. Attack your own private copy and nothing else. It has no way out to the internet. Never try these things on a site that is not yours: in the UK that is a crime under the Computer Misuse Act 1990.

By the end of this lesson

Note

I can say what makes a sign-in or a session weak.

Key words

WordWhat it meansExample
Sessionthe time during which a site remembers you are signed in
Cookiea small value the browser keeps and sends back to the site
Tokena value that proves you signed ina long string
Hashingturning a password into a fixed string that cannot be turned back
Brute forcetrying many guesses one after another
Expirythe time after which a session or token stops working

The cells students fill in are left blank in this preview.

Weak passwords fall to guessing

People choose short, common passwords. An attacker does not need cleverness, only a list of the common ones and a site that allows endless tries. That is brute force.

Three defences work together. Ask for length, not odd symbols. Refuse passwords on a common list. Slow or lock repeated failures.

Worked example: judging four passwords

PasswordVerdictWhy
123456RefuseOn every common list
Summer2024!WeakA word, a year and a symbol is a pattern guessers know
bakery-lorry-seven-hatsGoodLong, and not a pattern
anaRefuseToo short, and the same as the user name

The cells students fill in are left blank in this preview.

A site stores a hash, not the password

A site must never keep passwords as typed. If its records leak, every account leaks.

It stores a hash of the password and adds a random salt first, so two people with the same password have different hashes. To check a sign-in, it hashes the attempt and compares.

A session cookie is a key

After you sign in, the site gives your browser a session cookie and recognises you by it on every request. Anyone who holds that value is you.

So it must be random, long, sent only over HTTPS, hidden from script with HttpOnly, and it must expire. A site also issues a fresh one at sign-in.

Look at the lab's sessions

Your lab runs WebGoat. Start it and wait a minute. These three Runs look at the front door without signing in. The second asks for a page that needs a sign-in. The third shows the cookie the lab sets for it.

Is the sign-in page up?

Command
curl -s -o /dev/null -w "%{http_code} %{redirect_url}\n" http://web/WebGoat/login

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

A page that needs a sign-in

Command
curl -s -o /dev/null -w "%{http_code} %{redirect_url}\n" http://web/WebGoat/welcome.mvc

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

The cookie that reply sets

Command
curl -s -I http://web/WebGoat/welcome.mvc | grep -i "^set-cookie"

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

What the three answers tell you

The first prints 200 and no address. The second prints 302 and the sign-in address, so a page behind sign-in sends strangers to the door. The third prints a JSESSIONID cookie with Path=/WebGoat; HttpOnly.

The value is random and changes every time. HttpOnly is present. It has no Secure, because this lab uses plain HTTP.

A common mistake

Warning

Many people think a token that looks like random letters is hidden. Encoding is not encryption. A token that only encodes the user name can be read and edited by anyone. Use a random session id the server looks up, or a token with a signature the server checks. Check the expiry too.

A token must be signed and must expire

Some sites give a signed token with the user name, a role and an expiry inside. The server checks the signature before it believes anything in it.

A token with no signature, a token the server does not check, or one that never expires is a weak token. Refuse all three.

Worked example: three tokens

Token saysSigned?Verdict
user ana, role customer, expires tomorrowYesAccept
user ana, role admin, expires tomorrowNoRefuse: nobody vouches for admin
user ana, role customer, expired last weekYesRefuse: expired

The cells students fill in are left blank in this preview.

About this lab and its source: WebGoat lab: guided web security lessons with WebWolf in your own copy

Teaching a class? Set this module for your students with a teacher guide, marked assignments and a lab for every student.