Application Security
Check the security controls that match your app's real boundaries. Test the requests that should be refused, show the proof in the code, and say plainly what you did not cover.
Content date: October 16, 2026.
Plain English
Application security is what your app actually enforces, not what a label or a successful build says. Start from your threat model and ask which paths can read data, change data, or use someone's authority. Match a control to each path, then prove the refusals as well as the successes: show that the wrong person is denied and that nothing changed. Bring in the evidence from your work on identity, data, dependencies, secrets, and workspaces without repeating their setup. OWASP's Top 10:2025 puts broken access control first, which is why this lesson tests who is allowed to do what.
Use this when
Do it before a workflow handles real data or has effects outside your app. Do it again after permission or dependency changes, and as part of any readiness review.
If you are just starting
Use the local booking fixture to compare five cases: the real owner, a different user, a request with no identity, malformed input, and a request that is too large. Check the response, and also check whether any data changed. In a disposable copy, remove one ownership check, confirm the test catches it, then put the check back. This shows one boundary working. It is not a complete login system.
When your project grows
Use your framework's built-in protections and check how they are configured. Cover server-side permission checks, session handling, input rules, safe output and queries, secret storage, encrypted connections, dependencies, and browser protections. CORS controls which websites a browser lets call your API, and it is not user permission. Cookie-based actions need protection against cross-site request forgery (CSRF, where another site tricks a logged-in browser into sending a request). Cross-site scripting (XSS) is when text a visitor typed, such as a name or comment, runs as code in someone else's browser, where it can act as that person. Show visitor text as plain text. Most frameworks, including React, already do this, so the danger sits in the shortcuts: `dangerouslySetInnerHTML`, `innerHTML`, HTML built by joining strings, and links that start with `javascript:`. If people must be able to format text, clean it with a maintained sanitizer such as DOMPurify and do not change it afterward. Filtering text when you save it is not enough, because the danger depends on where the text is shown later. A content security policy limits which scripts a page may run. Treat it as a second layer, not the fix. Read scanner findings and clean results against your own workflow. List what you left out and the tests still needed. For payment, health, or student data, have a security professional review before launch.
Worked example
A cancellation endpoint returns 403 to the wrong user but writes the change before checking ownership. A test that checks only the status code passes, yet the booking is cancelled. The fixture counts writes for every refused request, so a late check shows up as a failure. Even then, it says nothing about real session expiry, CSRF protection, or HTTPS on a live site.
Practice
Demonstrate a security regression and repair
- Run the architecture fixture's baseline checks in an isolated folder and write down your Node version.
- For each case (owner, other user, missing session, unexpected fields, oversized input), write which requirement its check proves.
- In a disposable copy, remove the ownership check and confirm the other-user test fails.
- Put the check back and rerun. Confirm that refused requests leave the stored data untouched.
- Write the small change, your observations, and the controls a real app would still need into the shared readiness report.
Deliverable: A before, failing, and after record for one permission regression, plus a written list of what the fixture covers and what it does not.
Common mistakes to watch for
- An AI tool says "fully secure" after a scan, but nobody sent a request as the wrong user.
- A test checks for a 403 status but misses that the record was already changed.
- The cancel route checks ownership, but a second route to the same action does not.
- A role flag stored in the browser, or CORS, is treated as permission.
- The fixture's public demo tokens are copied into real login code.
- An AI tool adds bold text to comments by switching to `dangerouslySetInnerHTML`, and a visitor's comment now runs as a script.
Prompting
A weak prompt
Make this app secure and give it a security score.
A better prompt
Using our threat model and this exact app version, review the security boundaries for [workflow]. Trace where allowed and denied actions are enforced, and run small tests in my local or test environment only. Check what changed in the data as well as the response code. Label each item as an implemented control, a confirmed bug, a guess, or untested. For any bug, propose the smallest fix with a test that fails before and passes after, and add it to the readiness report. Do not call the app certified.
It swaps confidence and checkbox lists for proof that a control refuses what it should, and a list of what is still open.
Check before you move on
- You listed the boundaries that matter.
- You tested allowed and refused requests.
- Refused writes changed nothing.
- You reproduced and fixed one regression.
- Configuration assumptions are written down.
- Your report says what you did not cover.
You are done when
- The bug you planted is visible in a failing test before the fix and is refused correctly after it.
- Your report separates the demo fixture from real login and from security in a deployed app.
Questions to think about
A wrong-user request gets a 403, but the record was already changed. Did authorization work?
No. A refusal must stop the change from happening at all. The status code is only the message, so check the stored data too.
Your API allows only your own site's origin through CORS. Is it safe from unauthorized callers?
No. CORS only tells browsers which sites may read responses. A script or another server can still call the endpoint, so the server must check identity and permission itself.
The fixture's tests pass using public demo identities. Can you reuse them in production?
No. They are made-up inputs for testing one boundary. Anyone who can read the fixture knows them, and they are not a session system.
Your framework escapes text, and a visitor sets their name to a script tag. What happens, and what would change that?
The framework shows the tag as plain text, so the script does not run. That changes if code uses a shortcut such as dangerouslySetInnerHTML, innerHTML, or a built HTML string, which skips the escaping. Then clean the text with a sanitizer first, and treat a content security policy only as a backup.