OWASP Top 10 and secure coding
The few web security bugs that cause most damage, and the plain coding habits that stop them.
Updated since you finished it. We changed this lesson after you marked it done. Your progress is kept.
What broke
On 8 March 2017, a US government security team publicly warned about a flaw in Apache Struts. Struts is a widely used, open-source framework for web apps. The flaw let an attacker run commands on the server. 1
Two days later, someone scanned Equifax's systems for it. They found an online dispute portal still running the old version, broke in, and confirmed they could run commands. They took no data that time. 1
Equifax did send the warning to its system administrators. But the list of people was out of date, so the people who should install the patch never got it. A scan a week later also missed the flaw. 1
From 13 May 2017, attackers used the portal again. They found a store of usernames and passwords kept unencrypted. With those, they reached 48 more databases. They ran about 9,000 queries, far more than normal work needs, and nothing limited them. 1
A device that inspected network traffic should have seen this. But its digital certificate had expired about 10 months before the breach, so it was not inspecting encrypted traffic. On 29 July 2017, an administrator replaced the certificate and saw the attack. It had lasted about 76 days. The attackers reached personal data of at least 145.5 million people in the US. 1
One unpatched framework let them in. Plain-text passwords, databases that were not separated and blind monitoring did the rest. This lesson covers the habits that stop each of these.
The idea in simple words
The OWASP Top 10 is "a standard awareness document" about the most critical security risks to web applications. 2 Treat it as a list of bug types to learn, not a full checklist.
The current edition is OWASP Top 10:2025, the eighth one. For it, OWASP used data from over 2.8 million applications. Eight categories come from testing data and two from a survey of practitioners. 3
| # | 2025 category 2 |
|---|---|
| A01 | Broken Access Control |
| A02 | Security Misconfiguration |
| A03 | Software Supply Chain Failures |
| A04 | Cryptographic Failures |
| A05 | Injection |
| A06 | Insecure Design |
| A07 | Authentication Failures |
| A08 | Software or Data Integrity Failures |
| A09 | Security Logging and Alerting Failures |
| A10 | Mishandling of Exceptional Conditions |
Two changes since 2021 matter for daily work. Server-side request forgery is now part of A01. A03 grows the old "Vulnerable and Outdated Components" to cover builds and distribution too. 3
The key idea. Many of these bugs happen when your code trusts something it should not: user input, a library, a default setting or its own network. Check on the server, keep data apart from code, and give each part the least power it needs.
How it works
Here are six to start with, each with one example and one fix.
Broken access control (A01)
A user changes /accounts/123 to /accounts/124 and sees someone else's account. The server never checked ownership. 4 OWASP found some form of broken access control in 100% of the applications tested. 4
Fix: deny by default, write the check once and reuse it everywhere, and enforce record ownership. Add access control cases to your unit and integration tests. 4 The full story is in Authentication and authorization.
Injection (A05)
Injection happens when untrusted input reaches an interpreter, such as a SQL database, as part of a command. 7 Step through the classic attack.
- An attacker calls the accounts API. Instead of a real account id, they send the text ' OR '1'='1.
- Code A glues the input into the SQL text. The quote ends the string early, and OR '1'='1' becomes part of the query. It is always true, so the database returns every account.
- Code B sends the SQL with a placeholder, ?, and sends the input as a separate value. The SQL is fixed before the input arrives.
- The database treats the whole input as one value. No account has that id, so it returns zero rows. The input could not change the query.
Fix: use a parameterized query. With it, "the database will always distinguish between code and data". 9 Most drivers and ORMs support it.
# Wrong: input becomes part of the SQL
cur.execute("SELECT * FROM accounts WHERE id = '" + acc_id + "'")
# Right: a placeholder, so the driver passes input only as a value
cur.execute("SELECT * FROM accounts WHERE id = %s", (acc_id,))Placeholders cannot hold table or column names. For a "sort by" field, map the user's choice to a fixed list of allowed names. 9 Also, never give your app's database account admin rights. 9
Security misconfiguration (A02)
Examples: an admin console with its default password, sample apps left on a production server, or stack traces shown to users. 5 At Equifax, an expired certificate left a traffic monitor misconfigured, so it missed the attack. 1
Fix: build each environment from a script, with the same hardened settings everywhere and different credentials in each. Remove features and samples you do not use. Add one central setting that stops detailed error messages from reaching users. 5
Software supply chain failures (A03)
Your app is mostly other people's code. You are exposed if you do not know every version you run, including dependencies of dependencies, or you do not scan them regularly. 6 OWASP lists a 2017 Apache Struts 2 flaw, CVE-2017-5638, and Log4Shell among its example attacks. 6 A CVE is the public ID of one known flaw.
Fix: keep a software bill of materials (SBOM), remove unused packages, and watch for new flaws in what you use all the time. 6 A tool like Dependabot compares your dependency list with a database of known flaws. It alerts you when a new flaw is published for a version you use. 14
Server-side request forgery (part of A01)
Your app has a feature "import an image from a URL". An attacker gives http://169.254.169.254/, a cloud metadata address. Your server, which sits inside your network, fetches it. SSRF often aims at such endpoints to steal cloud credentials. 10
Fix: if you know the target hosts, use an allow-list. Do not accept full URLs from users, and turn off redirects. If you must call any address, block private, loopback and link-local ranges and metadata endpoints. Check the address the name resolves to, and connect only to that address. 10 On AWS, move to IMDSv2. 10
Logging and alerting failures (A09)
"Without logging and monitoring, attacks and breaches cannot be detected." 8 A common gap is logging only successful logins, so failed attempts go unseen. 8
Fix: log security events, including failures, with enough user context. Encode log data so attackers cannot inject fake lines. Keep personal data and secrets out of logs, and set alerts that people act on. 8
Input validation versus output encoding
These two are often mixed up.
- Input validation checks data when it arrives. Use allow-lists ("this field is 1 to 64 letters"), not lists of bad strings. Always validate on the server, because browser checks can be skipped. 11
- Output encoding changes data when you display it, so the browser shows it as text and does not run it. HTML, JavaScript, URLs and CSS each need their own encoder. 12
Validation alone does not stop SQL injection or cross-site scripting. You still need parameterized queries and output encoding. 11 Modern frameworks help by escaping output automatically. Escape hatches like React's dangerouslySetInnerHTML skip that protection. 12
Secrets out of code, and least privilege
Never put passwords or API keys in code, config files or Docker ENV lines. Load them at run time from a secrets manager, like AWS Secrets Manager or HashiCorp Vault. 13 Run a secret scanner in a pre-commit hook. If a secret leaks: revoke it, rotate it, then delete it from code and logs. 13
Give each service the smallest access it needs. Equifax's attackers jumped to 48 more databases because they were not separated, and plain-text credentials let them in. 1
Trade-offs
| Defense | Stops | Does not stop | Cost |
|---|---|---|---|
| Parameterized queries | Yes SQL injection through values. 9 | Bad table or column names. Use an allow-list. 9 | Low. Most libraries support it. |
| Escaping input by hand | Some injection. | No OWASP calls it fragile and strongly discourages it. 9 | Low to write, high to get right. |
| Allow-list input validation | Bad formats, wrong values. 11 | No It does not replace parameterized queries or output encoding. 11 | Low. |
| Output encoding | Most XSS when you show user data. 12 | Not every case. "Output encoding is not perfect." 12 | Low with a framework. |
| SSRF allow-list | Calls to any host you did not list. 10 | Features that must call any URL. | Medium. You keep the list. |
| SSRF block-list | Known private ranges and metadata. 10 | Tricks like DNS rebinding, unless you connect to the address you checked. 10 | Medium. A last resort. |
| Dependency scanning | Known flaws in versions you use. 14 | Flaws not yet in the advisory database. Alerts cannot catch every issue. 14 | Low to start. Ongoing work to update. |
Simple rule: prefer the defense that makes the bug impossible, like a parameterized query or an allow-list. Use filters and block-lists only as extra layers.
At work: how a senior uses this
- In review, ask of every new endpoint: "Who may call this, and where do we check it?"
- Search the diff for string-built SQL, shell commands and HTML. Each one needs a parameter, an argument list or an encoder.
- For any feature that fetches a URL, ask: "Which hosts may it reach?" Write the answer as an allow-list.
- Keep dependency alerts at zero open critical items. Agree on a patch deadline with your team, and track it like a bug.
- Give each service its own database user with only the tables it needs.
- Check that failed logins and access denials are logged and alerted. Ask: "Would we notice this attack within a day?"
- Treat certificates, keys and secrets as things that expire. Put their dates in monitoring.
With AI
What to ask the agent
"Find every place in this repo that builds SQL, shell commands or HTML with string concatenation or f-strings. For each, show the safe version."
"List every endpoint that fetches a URL given by the user. For each, say which hosts it can reach, and whether it follows redirects."
"Scan the repo and its history for hard-coded secrets. List each one with file and commit, but do not print the secret."
What to check yourself
- Every query uses placeholders. Table and column names come from a fixed list.
- An AI agent may add packages to fix a problem. Check that each new package is real, maintained and pinned, and that it shows up in your scanner.
- No secret appears in code, test fixtures, prompts or logs that the agent wrote.
- New handlers have the ownership check, not only the login check.
- Read the agent's SSRF fix. A check on the host name alone is not enough. It must check the resolved address and connect to that same address.
Check yourself
Your progress is saved only in this browser. Export it to keep it safe.
You have finished 5 lessons. Your progress lives only in this browser. Export a copy so you don’t lose it.
Go deeper
Show 14 sources and related lessons
- U.S. Government Accountability Office, GAO-18-559, Data Protection: Actions Taken by Equifax and Federal Agencies in Response to the 2017 Breach (August 2018) (opens in a new tab)
Pages 11 to 16 explain how attackers got in through Apache Struts, what helped them, and how the breach was found. - OWASP Top 10:2025, home page (opens in a new tab)
The ten categories of the current edition, with links to each one. - OWASP Top 10:2025, Introduction (opens in a new tab)
What changed since 2021, how the categories were chosen, and how much data was used. - OWASP Top 10:2025, A01 Broken Access Control (opens in a new tab)
Examples like changing an ID in the URL, and the "deny by default" prevention list. - OWASP Top 10:2025, A02 Security Misconfiguration (opens in a new tab)
Default passwords, stack traces shown to users, open cloud storage, and how to harden. - OWASP Top 10:2025, A03 Software Supply Chain Failures (opens in a new tab)
Real supply chain attacks and a list of defenses, from an SBOM to signed packages. - OWASP Top 10:2025, A05 Injection (opens in a new tab)
The classic ' OR '1'='1 example and why a safe API beats escaping. - OWASP Top 10:2025, A09 Security Logging and Alerting Failures (opens in a new tab)
What to log, what never to log, and why alerts matter. - OWASP Cheat Sheet Series, SQL Injection Prevention Cheat Sheet (opens in a new tab)
Prepared statements first, allow-lists for table and column names, and no admin rights for app accounts. - OWASP Cheat Sheet Series, Server Side Request Forgery Prevention Cheat Sheet (opens in a new tab)
Allow-lists, no redirects, blocking private addresses and cloud metadata endpoints. - OWASP Cheat Sheet Series, Input Validation Cheat Sheet (opens in a new tab)
Allow-lists over deny-lists, server-side checks, and why validation alone does not stop injection. - OWASP Cheat Sheet Series, Cross Site Scripting Prevention Cheat Sheet (opens in a new tab)
Output encoding for each context, and the risky escape hatches in React and Angular. - OWASP Cheat Sheet Series, Secrets Management Cheat Sheet (opens in a new tab)
Secrets managers, rotation, detection before commit, and what to do when a secret leaks. - GitHub Docs, About Dependabot alerts (opens in a new tab)
How a dependency scanner compares your packages with a database of known flaws.
Related: Authentication and authorization · Secrets and key management · Dependency and supply-chain security · Threat modelling and zero trust · REST API design
- Authentication and authorization: A01 and A07 in depth.
- More on this line: Secrets and key management, Dependency and supply-chain security and Threat modelling and zero trust.