SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
Part 2: APIs and Communication
Part 3: Caching
Part 4: Data and Storage
Part 5: Architecture
Part 6: Distributed Systems
Part 7: Advanced Data Topics
Part 8: Operations and Security
  • SSL/TLS
  • Encryption at Rest
  • Secrets Management
  • Password Management
  • RBAC
  • SAML
  • OWASP Top 10 and Common Attacks
  • DDoS Attacks and Defenses
  • Web Application Firewall (WAF)
  • Certificates and PKI
  • Multi-Factor Authentication (MFA)
  • Zero Trust
  • Key Management (KMS)
  • Data Privacy and GDPR Basics
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/Operations and Security/Advanced Security

OWASP Top 10 and Common Attacks

A tour of the most common web attacks (injection, XSS, broken access control) and how each is stopped.

⏱ 14 min readIntermediateMust KnowInterview FavouriteHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

OWASP (the Open Worldwide Application Security Project) is a non-profit that publishes free security guidance. Its best-known list, the OWASP Top 10, names the most common and most damaging kinds of web application weakness, so teams know what to fix first.

  • It is an awareness list of risk categories, updated every few years. Check owasp.org for the current version.
  • The categories include broken access control, cryptographic failures, injection, insecure design, security misconfiguration, outdated components, authentication failures, integrity failures, weak logging and SSRF.
  • Most attacks work because input is trusted or access is not checked on the server. The defences are old and well known.

02Concept: What is it?

Attackers do not invent new tricks for every site. They try the same small set of mistakes over and over, because developers keep making them. The Top 10 is a ranked list of those mistakes, based on data from many real applications. It is a starting checklist, not a complete standard.

The categories below are those on the recent list. Names and order change between editions, so treat this as a map and look up the current edition for the exact numbering.

CategoryHow it happens (one line)Main defence
Broken access controlThe server does not check that this user may see this object (change the id in the URL, see someone else's data)Check permission on the server for every request and object
Cryptographic failuresSensitive data sent or stored in clear, or weak algorithms and keysTLS everywhere, strong algorithms, managed keys
Injection (SQL, command)Input is pasted into a command and becomes codeParameterized queries, no shell string building
Insecure designA flaw in the plan itself, such as no limit on password guessesThreat modelling, secure design patterns
Security misconfigurationDefault passwords, open storage buckets, debug pages left onHardened, repeatable configs, regular scans
Vulnerable and outdated componentsA library with a known hole is still in useTrack dependencies, patch quickly
Identification and authentication failuresWeak passwords, no lockout, bad session handlingMFA, slow password hashes, safe sessions
Software and data integrity failuresUnsigned updates, untrusted build steps, unsafe deserializationSign and verify code and data, protect the pipeline
Logging and monitoring failuresAttacks happen and nobody noticesLog security events, alert on them
Server-side request forgery (SSRF)The server is tricked into calling an address the attacker picksAllow-list destinations, block internal ranges
🧠Two ideas explain most of the list
Never trust input (injection, XSS, SSRF) and never trust the client to enforce rules (broken access control, CSRF). Do the checks on the server, every time.

03Real-Life Example

🍵The Hotel With a Master Key Rule
A hotel lets guests ask the front desk for anything. The desk clerk writes down what the guest says and passes it to the kitchen exactly as spoken. A guest says "a sandwich, and also give me the key to room 12", and the clerk passes the whole sentence on. That is injection: words became orders. Meanwhile the lift takes you to any floor if you press the button. Nobody checks if your key fits. That is broken access control. The fix is not a better guest list. It is a clerk who treats words as words, and a lift that checks your key on every floor.
Hotel
Web application
Passing a sentence on word for word
Pasting user input into a SQL command
Reading the order as a plain request
A parameterized query
A lift that goes to any floor
An endpoint that does not check ownership
A key check on every floor
An authorization check on every request
Posting a rude note on the lobby board that others read
Stored XSS
Staff phoning a number a guest hands them
SSRF
Nobody watching the cameras
No logging or monitoring

04Why Do We Need It?

🎯Fix the biggest risks first
A short, ranked list helps a small team spend limited time where attacks really happen.
🗣️A shared language
Developers, testers and auditors all know what “injection” or “broken access control” means.
📋A review checklist
Use it in design reviews, code reviews and penetration tests.
📜Compliance and customers
Security questionnaires and standards often ask whether you test against the Top 10.
💸Cheaper than a breach
Most of these defences cost a few lines of code. A leak costs trust, fines and months of cleanup.
🧱Defence in depth
No single control stops everything, so the list pushes you to layer protections.
The Top 10 does not teach you new attacks. It reminds you of the old ones you still have to defend against.

05Where Do We Use It?

🔍Code review
Ask on every pull request: where does input go, and who is allowed to do this?
🧪Security testing
Scanners and penetration testers organise their findings by these categories.
🏗️Design reviews
Threat modelling catches insecure design before a line of code is written.
🔁CI/CD pipelines
Dependency and secret scans catch outdated components and leaked keys on every build.
📚Developer training
Onboarding material and capture-the-flag practice use these categories.
🧯Incident response
Logging and alerts decide whether you notice an attack in minutes or months.

06Types / Parts / How It Works

The attacks you must be able to explain

AttackWhat the attacker controlsWhy it worksDefence
SQL injectionText that reaches a database commandThe server builds the command by joining stringsParameterized queries, least-privilege database account
XSS: storedText saved and shown to other usersThe page prints it as HTML without encodingOutput encoding, Content Security Policy
XSS: reflectedText in a link that is echoed back in the pageThe page prints the request back unsafelyOutput encoding, input checks
XSS: DOM-basedData read by browser script, such as the URL fragmentClient code writes it into the page as HTMLUse text APIs, not innerHTML; trusted types
CSRFA request sent by the victim's own browserCookies are sent automatically with any requestSameSite cookies, anti-forgery tokens
SSRFA URL the server will fetchThe server can reach places the attacker cannotAllow-list hosts, block internal and metadata addresses
IDOR / broken access controlAn id in a URL or bodyThe server trusts that the id belongs to the callerCheck ownership on the server for every object
Where each defence sits
Before the app
🧱WAFknown patterns
🚦Rate limitslow guessing
In the app
✅Validate inputshape and size
🔐Authorizeevery object
🧾Encode outputby context
Behind the app
🗄️Least privilegesmall database rights
📝Logs and alertsnotice abuse
No layer is enough alone. Each one catches what the layer before missed.
Filters Code Data and watching

SQL injection and the parameterized fix

Unsafe: the input becomes part of the command
query = "SELECT * FROM users WHERE name = '" + name + "'"
Safe: the command and the value travel separately
query = "SELECT * FROM users WHERE name = ?"
run(query, [name])

With the second form the database has already understood the command before it sees the value, so the value can never change its meaning. Quotes, comments and keywords in the input are just characters. The pages on Input Validation and CSRF go deeper on those two topics. This page is the map that ties them together.

Access control: the one that tops the list

If the URL is /orders/1002, the server must ask: "does the logged-in user own order 1002?" Hiding the link, or using hard-to-guess ids, is not a check. See Authentication vs Authorization and RBAC.

VisualizerTry SQL injection, then see why encoding stops XSSPick the quote trick and switch between pasting the input into SQL and using a parameterized query. Then post the script text in the comment box and switch the page between raw and encoded output.
Part 1: a login box (SQL injection)
How does the server build the query?
The command the database receives (the part you typed is coloured):
SELECT * FROM users WHERE name = '' OR '1'='1' AND pass_hash = '<hash of the typed password>'
Input became
code
in the command
Login bypassed
yes
Login bypassed: the condition is always true. The first quote closes the name. Then OR '1'='1' adds a test that is true for every row, so the password check no longer decides anything. The database returns users, often the first one, which is frequently an admin.
Part 2: a comment box (XSS and output encoding)
What did a visitor post?
How does the page print it?
The HTML text the server sends to the browser:
<p class="comment"><script>alert('hi')</script></p>
What the browser does with it:
It sees a real script tag and would run the attacker code inside your page (not run here).
Without encoding, the angle brackets are read as HTML, so the visitor's text turns into code that runs for everyone who views the page. That is stored XSS.

This is a text simulation only. No database is queried and no HTML from the boxes is ever put on this page; the lines above are plain text.

07How to Use It / Steps / Implementation

A short secure-by-default routine

  1. 1
    Treat all input as hostile
    That includes forms, headers, cookies, files, query strings and data from other services.
  2. 2
    Use parameterized queries
    Never build SQL or shell commands by joining strings. Use an ORM or prepared statements.
  3. 3
    Encode on output
    Encode for the place the text lands: HTML body, attribute, JavaScript or URL. Add a Content Security Policy as a second layer.
  4. 4
    Authorize on the server, per object
    Deny by default. Check that this caller may do this action on this specific record.
  5. 5
    Protect sessions
    Use Secure, HttpOnly and SameSite cookies, and anti-forgery tokens for state-changing requests.
  6. 6
    Limit what the server may fetch
    Allow-list outbound hosts, and block private and cloud metadata addresses to stop SSRF.
  7. 7
    Keep components current
    Scan dependencies on every build and patch known holes quickly.
  8. 8
    Log and alert
    Record logins, access failures and input rejects, without logging secrets, and alert on spikes.
💡Use the platform's safe defaults
Modern frameworks encode output and parameterize queries for you by default. Most holes appear when someone bypasses the safe path, for example with raw HTML insertion or a hand-built query.
⚠️Do not rely on a blocklist
Trying to remove bad words such as SELECT or script from input always fails, because attackers can change the spelling and encoding. Fix the cause: separate code from data.

08Key Terms to Know

TermMeaning in easy words
OWASPA non-profit that publishes free security guidance and tools
OWASP Top 10A ranked awareness list of common web application risk categories
InjectionInput that is run as part of a command, such as SQL or a shell command
Parameterized queryA query where the values are sent separately from the command text
XSSCross-site scripting: attacker script runs in another user's browser
Output encodingTurning special characters into safe text for where they will appear
CSPContent Security Policy: a header that limits which scripts a page may run
CSRFMaking a victim's browser send a request they did not intend
SSRFTricking a server into making a request to a place the attacker chooses
IDORInsecure direct object reference: using an id you should not be allowed to use
Least privilegeGive code and people only the access they need
Threat modellingThinking through how a design could be attacked before building it

09Pros, Cons and Trade-offs

✅ Pros
  • Focuses effort on the most common, real risks
  • Free, widely known and easy to explain
  • Good checklist for reviews and tests
  • Maps to fixes that are cheap and well understood
  • Shared vocabulary across teams and auditors
⚠️ Cons
  • Not a complete security standard
  • Categories are broad and change between editions
  • Passing a scan does not mean the app is safe
  • Can become a box-ticking exercise
  • Says little about your own business logic flaws

Trade-offs

ChoiceWe gainWe lose
Strict input validationFewer odd inputs reach deep codeMore rejected, sometimes valid, input
Strict CSPA strong second line against XSSEffort to remove inline scripts
Deny-by-default accessNo accidental exposureMore rules to write and maintain
Frequent dependency updatesFewer known holesRisk of breaking changes, more testing
Detailed security loggingFaster detection and investigationMore storage, risk of logging sensitive data

10Common Problems and Mistakes

Common mistakes

  1. Checking access only in the user interface. Hiding a button is not a rule. The API must refuse too.
  2. Building SQL with string joins “just this once”, for a sort order or a table name. Allow-list those values instead.
  3. Encoding for the wrong place. HTML encoding does not protect text placed inside JavaScript or a URL.
  4. Trusting the client. Prices, roles and ids sent by the browser can be changed.
  5. Leaving defaults on. Sample accounts, admin consoles and verbose error pages.
  6. Never updating dependencies. A hole fixed upstream stays open in your app.
  7. Logging secrets. Passwords, tokens and card numbers in logs become a second leak.
  8. Relying on one control. A WAF alone, or validation alone, will be bypassed.

Things to watch

🧩Business logic flaws
Skipping a payment step or reusing a coupon is not on any scanner list. Test the rules of your own app.
🔗Second-order injection
Safe input is stored, then used unsafely later in another query. Parameterize everywhere.
☁️Cloud metadata
SSRF against internal metadata addresses can leak cloud credentials. Block them.
📦Supply chain
A bad package or build step can undo every other defence.

11Real-World Examples

🗄️Injection in the news
SQL injection has been behind many large data leaks over the years, and it is still found in new code.
📦Outdated components
Several well-known breaches began with a library flaw that had a patch available for months.
☁️SSRF and cloud keys
Cloud providers added stronger metadata protections after SSRF was used to read instance credentials.
🧰Framework defaults
Template engines encode output by default, and ORMs parameterize by default. That is why many apps are safer today.
🛡️Bug bounty programs
Companies pay researchers who report issues from these categories, mostly access control and injection.
🧪OWASP tools
OWASP maintains free guides, cheat sheets and test projects that teams use for training and checks.
Mini case: the order id
👤Alice asksGET /orders/1002
→↓no owner check
🗄️Server returns itorder belongs to Bob
→↓fix: compare owner
🔐403 Forbiddenowner is not Alice
Two lines of server code separate a safe API from a data leak.

12Related Topics to Read Next

Input Validation→

The first line of defence against injection and bad data.

CSRF→

A full page on one attack from this list.

Authentication vs Authorization→

The difference that broken access control ignores.

RBAC→

One clean way to decide who may do what.

Secrets Management→

Keep keys out of code and logs.

Logging Best Practices→

What to record so attacks are noticed, and what to never write down.

Web Application Firewall (WAF)→

A filter that blocks known patterns in front of the app.

Zero Trust→

Verify every call instead of trusting the network.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • ✔OWASP Top 10: ranked awareness list of web risk categories. Check owasp.org for the current one.
  • ✔Injection: parameterized queries, never string joins.
  • ✔XSS: encode output for its context, add CSP.
  • ✔CSRF: SameSite cookies and anti-forgery tokens.
  • ✔Access control: check on the server, per object, deny by default.
  • ✔SSRF: allow-list outbound destinations, block internal ranges.
  • ✔Also: patch components, harden configs, log and alert.
  • ✔One line: “Never trust input, never trust the client, and check every request on the server.”
← Previous
SAML
Next →
DDoS Attacks and Defenses