JS-290 · Lesson 9 of 12 · 27 min
Security and accessibility review
▶ Video coming soon A video version of this lesson is on the way.
The week of May 7 is set aside for review, the first week of hardening. In February, Mira was on the reviewing side of WEB-230's review of everything the studio had built for the Food Hub. Now her own team's work is the subject, and Theo and Sana take the same roles they took then: Theo leads security and privacy, and Sana leads accessibility. The rules are the same too. Testing happens on staging only, with invented data, within a written scope, and every finding gets a severity, an owner and a date.
Gareth tells the team that a review is not a test they pass or fail. Every project of any size has findings, and a review with none usually means nobody looked hard. What matters is that findings are found before real people's data is in the system, that the serious ones are fixed before launch, and that each fix comes with a test that keeps it fixed. The team has already done much of the work: lesson 3's architecture, lesson 6's validation and object-level checks and lesson 8's accessibility checks in every journey were all designed with this week in mind.
Scope and rules of engagement
Theo starts with a one-page scope, the same format as WEB-230's. In scope: the rescue web app at /rescue/ on staging, the rescue service API, its database schema and the new token endpoint in Theo's PHP application. Out of scope: everything else on the Food Hub's systems, which was reviewed in February. The rules of engagement say who may test, from where and when; that no test may try to make the service unavailable; and that anything found outside scope is reported, not explored. Lucy signs the scope for the Food Hub, because testing a system without the owner's permission is not a review.
Refreshing the threat model
The data flow diagram from WEB-230 gets three new elements: the rescue web app, the rescue service and its schema, and two new outside users, donor staff and drivers. Mira walks each new element through STRIDE, as WEB-230 taught, and writes a question for each threat that applies. The questions become the review's checklist, so that nothing depends on someone remembering to look.
// STRIDE questions for the new elements, using the common rule of thumb for each kind.
const applies = { process: 'STRIDE', store: 'TID', flow: 'TID', external: 'SR' };
const ask = {
S: (n) => `Can someone act as another ${n.who ?? 'caller'} in ${n.name}?`,
T: (n) => `Can data in ${n.name} be changed by someone who should not?`,
R: (n) => `Could someone deny an action they took in ${n.name}?`,
I: (n) => `Can ${n.name} reveal data to the wrong person?`,
D: (n) => `Can ${n.name} be made unusable for others?`,
E: (n) => `Can a caller of ${n.name} gain powers they should not have?`,
};
const elements = [
{ name: 'the rescue service', kind: 'process', who: 'driver' },
{ name: 'the rescue schema', kind: 'store' },
{ name: 'donor photo uploads', kind: 'flow' },
{ name: 'donor staff', kind: 'external', who: 'donor' },
];
let n = 0;
for (const el of elements) {
for (const letter of applies[el.kind]) console.log(`${String(++n).padStart(2)}. [${letter}] ${ask[letter](el)}`);
}1. [S] Can someone act as another driver in the rescue service? 2. [T] Can data in the rescue service be changed by someone who should not? 3. [R] Could someone deny an action they took in the rescue service? 4. [I] Can the rescue service reveal data to the wrong person? 5. [D] Can the rescue service be made unusable for others? 6. [E] Can a caller of the rescue service gain powers they should not have? 7. [T] Can data in the rescue schema be changed by someone who should not? 8. [I] Can the rescue schema reveal data to the wrong person? 9. [D] Can the rescue schema be made unusable for others? 10. [T] Can data in donor photo uploads be changed by someone who should not? 11. [I] Can donor photo uploads reveal data to the wrong person? 12. [D] Can donor photo uploads be made unusable for others? 13. [S] Can someone act as another donor in donor staff? 14. [R] Could someone deny an action they took in donor staff?
What this code does
Each kind of element has a string of the STRIDE letters that usually apply to it, and each letter has a function that writes a question about a named element. Looping over the new elements and their letters produces a numbered checklist of fourteen questions. Writing the questions down turns the threat model into something two people can work through and tick off.
Question 9, *Can donor photo uploads reveal data to the wrong person?*, looked like a formality and turned out to be the most interesting finding of the week.
The security findings
Theo and Mira work through the checklist on Monday and Tuesday, with Odalys and Tavish fixing as they go. Each finding is rated with the scale from WEB-230: critical, high, medium or low, from likelihood and impact, with a fix deadline that runs from the date the finding is reported.
| Id | Finding | Severity | Fix |
|---|---|---|---|
| S1 | GET /runs/{id} returned the donor contact's phone number to any signed-in driver, not only the driver who claimed the run | High | Contact details only in the claimer's view; other drivers get 404; regression test added |
| S2 | Donor photos kept their location metadata, including the exact latitude and longitude where they were taken | High | Photos re-encoded on upload with all metadata removed; file type checked by its first bytes, not its name |
| S3 | The /rescue/ path was not covered by the Content Security Policy on Theo's server | Medium | Strict nonce policy added, report-only for three days, then enforced |
| S4 | An offline pickup time could be any time in the past | Medium | Accepted only within the window plus two hours and not in the future |
| S5 | Expired idempotency keys were never deleted | Low | Nightly clean-up job; keys older than 24 hours removed |
S1 is a textbook case of the first entry in the OWASP Top 10 2025, broken access control, and it slipped through because the run detail handler loaded the run by id alone. The fix follows the rule from lesson 6: load the object with the caller in the query. The regression test signs in as one driver, claims a run, signs in as a second driver and asks for the same run, and expects 404. It failed before the fix and passes after, and it runs on every push from now on.
S2 came from question 9. Phones store details about each photo inside the file, including, on most phones, the GPS position where it was taken. A donor photographing leftover trays in the back room is not sharing anything sensitive. But Tavish noticed that one test photo, taken by Odalys at home while trying the app, carried her home's coordinates, and the photo was visible to any driver who opened the offer. Real donors might well post from home on a day off. The fix re-encodes every image on the server, which removes all metadata, and the upload check from JS-240 already refused files whose first bytes were not a JPEG, PNG or WebP image.
// Check an upload by its first bytes, not its file name.
const signatures = [
{ type: 'image/jpeg', bytes: [0xff, 0xd8, 0xff] },
{ type: 'image/png', bytes: [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a] },
{ type: 'image/webp', bytes: [0x52, 0x49, 0x46, 0x46], also: { at: 8, bytes: [0x57, 0x45, 0x42, 0x50] } },
];
const matches = (buf, bytes, at = 0) => bytes.every((b, i) => buf[at + i] === b);
function sniff(buf) {
for (const s of signatures) {
if (matches(buf, s.bytes) && (!s.also || matches(buf, s.also.bytes, s.also.at))) return s.type;
}
return null;
}
const files = {
'trays.jpg': [0xff, 0xd8, 0xff, 0xe1, 0x00, 0x10],
'bread.png': [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00],
'photo.jpg': [0x3c, 0x73, 0x76, 0x67, 0x20],
'buns.webp': [0x52, 0x49, 0x46, 0x46, 0x10, 0x00, 0x00, 0x00, 0x57, 0x45, 0x42, 0x50],
};
for (const [name, bytes] of Object.entries(files)) {
const type = sniff(Uint8Array.from(bytes));
console.log(`${name.padEnd(10)} ${type ?? 'refused: not an allowed image'}`);
}trays.jpg image/jpeg bread.png image/png photo.jpg refused: not an allowed image buns.webp image/webp
What this code does
Each allowed image type has a signature, the bytes its files always start with, and WebP also needs a second marker eight bytes in. The sniff function compares the start of the uploaded bytes with each signature and returns the type only when one matches. The file named photo.jpg actually starts with the text of an SVG drawing, so it is refused even though its name says JPEG.
Headers and the policy
S3 is the kind of finding that happens when something new is added to an old server. The Content Security Policy from WEB-230 was configured for each path Theo's server already served, and /rescue/ was new. Theo uses the same short script WEB-230 wrote to check a response's security headers, now run in CI against staging after every deployment, so a new path cannot ship without them again.
// Check a response's security headers against the studio's baseline.
const baseline = {
'strict-transport-security': (v) => /max-age=(\d+)/.test(v) && Number(v.match(/max-age=(\d+)/)[1]) >= 31536000,
'content-security-policy': (v) => /script-src[^;]*'nonce-/.test(v) && /object-src 'none'/.test(v),
'x-content-type-options': (v) => v === 'nosniff',
'referrer-policy': (v) => ['strict-origin-when-cross-origin', 'no-referrer'].includes(v),
'permissions-policy': (v) => /geolocation=\(\)/.test(v),
};
function check(headers) {
const h = Object.fromEntries(Object.entries(headers).map(([k, v]) => [k.toLowerCase(), v]));
return Object.entries(baseline).map(([name, ok]) => `${h[name] !== undefined && ok(h[name]) ? 'ok ' : 'MISSING'} ${name}`);
}
const before = { 'Strict-Transport-Security': 'max-age=31536000', 'X-Content-Type-Options': 'nosniff', 'Referrer-Policy': 'strict-origin-when-cross-origin' };
const after = { ...before,
'Content-Security-Policy': "default-src 'self'; script-src 'nonce-r4nd0m' 'strict-dynamic'; object-src 'none'; base-uri 'none'",
'Permissions-Policy': 'geolocation=(), camera=(self)' };
console.log('before:'); check(before).forEach((l) => console.log(' ', l));
console.log('after:'); check(after).forEach((l) => console.log(' ', l));before: ok strict-transport-security MISSING content-security-policy ok x-content-type-options ok referrer-policy MISSING permissions-policy after: ok strict-transport-security ok content-security-policy ok x-content-type-options ok referrer-policy ok permissions-policy
What this code does
The baseline maps each header name to a test of its value, such as an HSTS max-age of at least a year or a script source that requires a nonce. Header names are lower-cased first because HTTP header names are not case-sensitive. The before and after responses show the two headers the /rescue/ path was missing, and the permissions policy now allows the camera for photo posting while denying location to the page.
The permissions policy line is a small privacy decision of its own. The web app never needs the phone's location, because distance sorting uses start areas, so the policy denies geolocation entirely. If a future feature asks for it, the denial will fail the feature's tests and force a conversation, instead of a new permission slipping in unnoticed.
The accessibility review
Sana runs the accessibility half the way WEB-230's lessons 9 and 10 describe: automated checks first, then keyboard, zoom and reflow checks, then screen readers, then a session with a disabled user. The automated checks in every end-to-end journey had already caught several problems during the sprints, such as a missing label on the temperature field. What remained needed people.
| Id | Finding | WCAG 2.2 | Fix |
|---|---|---|---|
| A1 | The weight field's error appeared below the field but was not linked to it, so screen readers did not read it with the field | 1.3.1, 3.3.1 | Error linked with aria-describedby; the field marked invalid; focus moved to the first error |
| A2 | The chilled badge's blue outline against white was 2.5:1, below the 3:1 for non-text contrast | 1.4.11 | Darker blue, 6.7:1; the word chilled added beside the icon |
| A3 | The undo message after Picked up disappeared after ten seconds | 2.2.1 | Stays until dismissed or until the next action |
| A4 | At 400 zoom the coordinator's day table needed scrolling in two directions | 1.4.10 | Table becomes a list of cards on narrow screens |
// WCAG contrast ratio from two sRGB values.
function luminance(hex) {
const [r, g, b] = [1, 3, 5].map((i) => parseInt(hex.slice(i, i + 2), 16) / 255)
.map((c) => (c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4));
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
}
function ratio(a, b) {
const [hi, lo] = [luminance(a), luminance(b)].sort((x, y) => y - x);
return (hi + 0.05) / (lo + 0.05);
}
const white = '#ffffff';
for (const [name, fg, need] of [['old badge outline', '#6fa8dc', 3], ['new badge outline', '#1f5f99', 3], ['badge text', '#1f5f99', 4.5]]) {
const r = ratio(fg, white);
console.log(`${name.padEnd(18)} ${r.toFixed(1)}:1 needs ${need}:1 ${r >= need ? 'pass' : 'FAIL'}`);
}old badge outline 2.5:1 needs 3:1 FAIL new badge outline 6.7:1 needs 3:1 pass badge text 6.7:1 needs 4.5:1 pass
What this code does
The luminance function converts each color channel from the sRGB curve to linear light and weights the channels the way the eye does, which is the formula WCAG uses. The contrast ratio divides the lighter luminance by the darker, each plus 0.05, giving a number from 1 to 21. The old outline fails the 3:1 required for graphical parts of controls, and the new color passes both that and the 4.5:1 needed for the badge's text.
On Wednesday, May 9, Beatrix spends ninety minutes with the app on staging, using her own phone with its screen reader and a laptop with another. She is not a driver, but she volunteers on Thursdays at the warehouse receiving desk, so Sana asks her to do the receiver's tasks. She records three deliveries without help. Her one problem became A1: when she typed a weight of 0 by mistake, the page said nothing she could hear, and she only discovered the error when the form refused to submit. With the fix, her screen reader reads *Weight, invalid entry, enter a weight of at least 0.1 kilograms* as soon as focus returns to the field.
Beatrix also said something the team writes at the top of the review report. In December she had phoned Lucy because she could not use the portal. This time she was asked to test before anything was released, and she was paid for her time, as WEB-230 recommended. The difference, she said, was that she was treated as an expert rather than as a problem to be fixed.
Deadlines and regression tests
The review report goes to Lucy and Paul on Friday, May 11, with nine findings: five security and privacy, four accessibility, none critical. The team's rule is that every high finding is fixed before production and every medium one before the end of hardening. The deadlines come from the severity scale WEB-230 agreed with Paul.
// Fix deadlines from the report date, by severity.
const days = { critical: 7, high: 30, medium: 90 };
const reported = new Date(Date.UTC(2029, 4, 11));
const addDays = (d, n) => new Date(d.getTime() + n * 86400000).toISOString().slice(0, 10);
const findings = [
['S1', 'high', '2029-05-08'], ['S2', 'high', '2029-05-10'], ['S3', 'medium', '2029-05-14'],
['S4', 'medium', '2029-05-09'], ['S5', 'low', null], ['A1', 'high', '2029-05-10'],
['A2', 'medium', '2029-05-09'], ['A3', 'medium', '2029-05-15'], ['A4', 'medium', null],
];
for (const [id, sev, fixed] of findings) {
const due = sev in days ? addDays(reported, days[sev]) : 'next update';
const state = fixed ? `fixed ${fixed}` : 'open';
console.log(`${id} ${sev.padEnd(7)} due ${due.padEnd(11)} ${state}`);
}
const highOpen = findings.filter(([, s, f]) => (s === 'high' || s === 'critical') && !f).length;
console.log(highOpen === 0 ? 'no high or critical findings open: production may go ahead' : `${highOpen} high findings open`);S1 high due 2029-06-10 fixed 2029-05-08 S2 high due 2029-06-10 fixed 2029-05-10 S3 medium due 2029-08-09 fixed 2029-05-14 S4 medium due 2029-08-09 fixed 2029-05-09 S5 low due next update open A1 high due 2029-06-10 fixed 2029-05-10 A2 medium due 2029-08-09 fixed 2029-05-09 A3 medium due 2029-08-09 fixed 2029-05-15 A4 medium due 2029-08-09 open no high or critical findings open: production may go ahead
What this code does
Each severity has a number of days to fix, counted from the report date, and low findings wait for the next scheduled update. Dates are worked out in UTC and printed as ISO dates, so the calculation does not depend on the computer's own time zone. The last line is the team's go or no-go rule for production: no high or critical finding may still be open.
By the end of hardening, every finding except S5 and A4 is fixed, and both of those have dates. Each fix has a test that failed before it and passes after: an authorization test for S1, a metadata test that uploads a photo with GPS data and checks that the stored file has none for S2, the header check for S3, a property test of allowed pickup times for S4, and Playwright checks for A1 to A3. Lucy signs the report on Monday, May 14, which is the formal approval for staging with real accounts the next day.
Worked problem
Rating a new finding
On Thursday, Tavish finds that the coordinator's monthly report endpoint accepts a month such as 2029-13 and returns an empty report instead of an error. The likelihood that anyone sends such a month is 2 on the 1 to 3 scale; the impact is 1, since nobody sees data they should not. With high at 6 or more, medium 3 to 5 and low below 3, how is it rated, and what is the fix?
Show solution
- Score: 2 × 1 = 2.
- Level: below 3, so low.
- Fix: validate the month with the schema, returning 422 for anything that is not a real year and month.
- Deadline: low findings are fixed in the next scheduled update, but this one takes five minutes, so Tavish fixes it the same day with a test.
Answer: The finding scores 2 and is low, but it is fixed immediately because the fix is small and the test is easy. Severity decides the latest acceptable date, not the earliest.
Common mistakes
MistakeExpecting a review with no findings.
InsteadExpect findings; the aim is to find and fix them before real data arrives.
MistakeLoading an object by id and checking access later.
InsteadLoad it with the caller's identity in the query, and return 404 if nothing matches.
MistakeStoring uploaded photos as they arrive.
InsteadCheck the file type by its first bytes and re-encode images to remove metadata such as location.
MistakeAssuming a new path inherits the server's security headers.
InsteadCheck every response's headers in CI after each deployment.
MistakeFixing a finding without a test.
InsteadAdd a regression test that fails before the fix and passes after it.
Summary and key terms
- A security and accessibility review is planned with a written scope and rules of engagement, signed by the system's owner, and runs on staging with invented data.
- The threat model is refreshed for new elements and turned into a STRIDE checklist.
- Findings are rated by likelihood and impact, with deadlines by severity.
- The rescue review found broken object-level access, location metadata in photos, a path missing its Content Security Policy, unchecked offline timestamps and keys never deleted.
- Uploads are checked by their first bytes and re-encoded.
- Header checks run in CI after every deployment.
- The accessibility review combined automated checks, keyboard, zoom, screen readers and a paid session with Beatrix, and found an unlinked error, low contrast, a timed message and reflow problems.
- No high finding may be open at launch, and every fix has a regression test.
- Rules of engagement
- The agreed limits on how, when and by whom a system is tested.
- Finding
- A problem identified in a review, with a description, severity, owner and fix date.
- Severity
- How serious a finding is, from its likelihood and impact.
- Image metadata
- Information stored inside an image file, such as the camera, the time and often the location.
- File signature
- The bytes a file of a given type always starts with.
- Permissions policy
- An HTTP header that controls which browser features, such as location or camera, a page may use.
- Contrast ratio
- A WCAG measure from 1 to 21 comparing the luminance of two colors.
- Regression test
- A test that checks a fixed problem stays fixed.
Practice problems
Work each problem on paper first, then reveal the answer to check.
Why did S1 happen, and how was it fixed?
Show answer
The run detail handler loaded the run by id alone; it now loads it with the caller in the query and returns 404 otherwise.
Why were donor photos a privacy risk?
Show answer
Phone photos often contain the GPS position where they were taken, which could reveal a home address.
Why check an upload's first bytes instead of its name?
Show answer
A name can say anything; the signature shows what the file actually is.
What is the team's go or no-go rule for production?
Show answer
No high or critical finding may still be open.
Try it yourself
Contrast ratio
Complete ratio(a, b) for two colors given as six-digit hex strings such as #1f5f99.
Use the WCAG relative luminance formula from the lesson and return the ratio rounded to two decimal places as a number.
function ratio(a, b) {
return 1;
}
console.log(ratio('#000000', '#ffffff'));
console.log(ratio('#1f5f99', '#ffffff'));
console.log(ratio('#777777', '#ffffff'));Try it yourself
Fix deadline
Complete due(reportedIso, severity). Critical findings are due 7 days after the report date, high 30, medium 90, and low returns next update.
reportedIso is a date such as 2029-05-11. Return the due date in the same format, working in UTC.
function due(reportedIso, severity) {
return reportedIso;
}
console.log(due('2029-05-11', 'critical'));
console.log(due('2029-05-11', 'high'));
console.log(due('2029-05-11', 'medium'));
console.log(due('2029-05-11', 'low'));Lesson quiz · 5 questions
Score 60% or more to complete this lesson.
Create a free account to save your progress, take quizzes and earn a certificate.