Web Application Security MCQs for NSCT
Web application security protects web apps and their users from attacks that abuse the application's own logic and inputs, such as SQL injection, cross-site scripting (XSS) and cross-site request forgery (CSRF). The OWASP Top 10 is the standard list of the most critical of these risks. It is the sixth topic in the Cyber Security area, which carries 5% of the NSCT according to HEC's Areas of Competencies. Candidates averaged 47.2% accuracy in this area in 2026, per the HEC NSCT report and APP.
OWASP Top 10
OWASP (the Open Worldwide Application Security Project) publishes a ranked list of web risks. This page uses the 2021 edition, which most textbooks and courses still teach. OWASP has since published a 2025 update that renumbers several entries, so always check which edition a question means.
| Rank | 2021 category | Example |
|---|---|---|
| A01 | Broken Access Control | Changing /invoice?id=101 to 102 shows another user's invoice (IDOR) |
| A02 | Cryptographic Failures | Passwords stored with unsalted MD5; login page over HTTP |
| A03 | Injection | SQL injection, OS command injection, XSS |
| A04 | Insecure Design | No rate limit designed into a password-reset flow |
| A05 | Security Misconfiguration | Default admin password, stack traces shown to users |
| A06 | Vulnerable and Outdated Components | An old library with a known CVE |
| A07 | Identification and Authentication Failures | No lockout; session ID not changed after login |
| A08 | Software and Data Integrity Failures | Unsigned updates, insecure deserialisation |
| A09 | Security Logging and Monitoring Failures | Failed logins never logged or alerted |
| A10 | Server-Side Request Forgery (SSRF) | App fetches a user-supplied URL such as http://169.254.169.254/ |
Exam angle: in 2021, XSS was merged into Injection (A03), and Broken Access Control moved to A01.
SQL injection
SQL injection happens when user input is pasted into a SQL string, so the input changes the query's structure. Given this login query:
SELECT username FROM users WHERE username='<u>' AND password='<p>'
Entering admin'-- as the username turns the rest of the line into a comment, so the password check disappears and the query returns admin. We ran this in SQLite: it returned admin, while the same input passed as a parameterised query returned no rows, because the input was treated purely as data.
Variants: UNION-based (appends a second SELECT with the same number of columns), blind (infers data from true/false page differences or time delays) and second-order (stored input is used unsafely later).
Defences: parameterised queries or prepared statements first, then allow-list validation, least-privilege database accounts and error messages that reveal nothing.
Exam angle: escaping quotes by hand is a weak fix; parameterisation is the primary defence.
XSS
Cross-site scripting injects script into a page that other users' browsers then run in the site's origin, so it can steal session cookies or act as the user.
| Type | Where the payload lives |
|---|---|
| Stored | Saved on the server (a comment, a profile field) and served to every visitor |
| Reflected | In the request (often a URL parameter) and echoed straight back |
| DOM-based | Handled only by client-side JavaScript, for example writing location.hash into innerHTML |
The primary defence is context-aware output encoding. HTML-encoding <script>alert("x")</script> gives <script>alert("x")</script>, which the browser shows as text instead of running. Content Security Policy (CSP) adds a second layer, and the HttpOnly cookie flag stops script from reading the session cookie.
Exam angle: XSS exploits the user's trust in the site.
CSRF
Cross-site request forgery makes a logged-in victim's browser send a request the victim did not intend, such as a hidden form on an attacker's page that posts to bank.example/transfer. The browser attaches the victim's cookies, so the bank sees a valid session. The attacker never sees the response; they only need the action to happen.
Defences: an unpredictable anti-CSRF token in each state-changing form, SameSite cookies, checking the Origin header, and re-authentication for critical actions. Making state changes only through POST helps but is not enough alone.
Exam angle: CSRF exploits the site's trust in the user's browser, the mirror image of XSS.
Common traps
- Calling XSS a server-side attack. The script runs in the victim's browser.
- Thinking HTTPS stops SQL injection or XSS. TLS protects transport, not application logic.
- Believing CORS prevents CSRF. CORS controls reading responses; a forged form post still gets sent.
- Assuming input validation alone stops XSS. Output encoding for the right context is the main control.
- Numbering OWASP from memory of an older list: Injection was A1 in 2017 but A03 in 2021.
- Forgetting that an XSS flaw on the site can read the page's anti-CSRF token, defeating it.
Worked examples
1. Understanding. Which 2021 OWASP category covers a user reading another user's records by changing an ID in the URL? Answer: A01 Broken Access Control. The server authenticates the user but never checks that the requested record belongs to them, an insecure direct object reference.
2. Application. A search page shows "Results for: " followed by the q parameter without encoding. A link with q=<script>...</script> is emailed to victims. Which XSS type is this?
Answer: reflected XSS. The payload travels in the request and is echoed in the immediate response; nothing is stored on the server.
3. Analysis. The login query above is fed username ali' OR '1'='1 and a wrong password. Which rows come back?
Answer: only ali's row. The WHERE clause becomes username='ali' OR '1'='1' AND password='wrong'. AND binds tighter than OR, so the condition is username='ali' OR ('1'='1' AND password='wrong'), which is true only for ali. We confirmed this in SQLite. The attacker still logs in as ali without the password.
Practise
The quiz below has 100 questions on Web Application Security, filterable by tier and difficulty.
Practise: 100 questions
FAQs
What is the difference between XSS and SQL injection?
SQL injection targets the server's database: crafted input changes a SQL query, exposing or altering data. XSS targets other users: crafted input becomes script that runs in their browsers. Parameterised queries stop SQL injection; context-aware output encoding stops XSS. Both are in the Injection category of the OWASP Top 10 (2021).
How do anti-CSRF tokens work?
The server puts a random, secret token in each form or request header and checks it when the request arrives. An attacker's page cannot read the token because the same-origin policy blocks it, so a forged request arrives without a valid token and is rejected.
Is the OWASP Top 10 a security standard?
Not strictly. OWASP describes it as an awareness document listing the most critical web risks. For a testable checklist, OWASP publishes the Application Security Verification Standard (ASVS). In exams, the Top 10 is still the reference list for naming web vulnerability categories.
Does HttpOnly stop XSS?
No. HttpOnly stops JavaScript from reading the cookie, which blocks the classic session-theft payload. The injected script still runs and can act inside the page as the user, so output encoding and CSP remain necessary.
Next step
Continue with Malware & Attack Techniques MCQs, and go deeper on the risk list with OWASP Top 10. Revisit Network Security and Operating System Security, browse the Cyber Security hub, then take an NSCT mock test.