Web Application Security MCQs for NSCT

By the NSCT Exam Editorial Team · Updated 2026-11-24 · Facts checked against official sources on 2026-11-24

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 &lt;script&gt;alert(&quot;x&quot;)&lt;/script&gt;, 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

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

Interactive quiz loading. The first 10 questions are shown below.

  1. In the OWASP Top 10 (2021), which risk is ranked A01?

    1. Injection
    2. Cryptographic Failures
    3. Broken Access Control
    4. Security Misconfiguration
    Show answer

    Answer: C. Broken Access Control

    The 2021 edition moved Broken Access Control to the top spot, as it was found in the largest share of tested applications. Injection, which was A1 in 2017, dropped to A03, and Cryptographic Failures is A02.

  2. What is Server-Side Request Forgery (SSRF), A10 in the OWASP Top 10 (2021)?

    1. Tricking a user's browser into sending a forged request to a trusted site
    2. Injecting script that runs in other users' browsers
    3. Tricking the server into sending requests to a URL the attacker chooses, often an internal one
    4. Stealing a session ID by sniffing traffic
    Show answer

    Answer: C. Tricking the server into sending requests to a URL the attacker chooses, often an internal one

    In SSRF the vulnerable server itself fetches an attacker-supplied URL, so it can reach internal services or cloud metadata endpoints that the attacker cannot reach directly. Forged browser requests describe CSRF; injected script describes XSS.

  3. A malicious script is saved in a forum post and runs in the browser of every user who views the post. Which XSS type is this?

    1. Stored (persistent) XSS
    2. Reflected XSS
    3. DOM-based XSS
    4. Cross-site request forgery
    Show answer

    Answer: A. Stored (persistent) XSS

    The payload is stored on the server and served to every visitor, which makes it stored XSS and usually the most damaging type. Reflected XSS needs each victim to open a crafted link.

  4. Which attack makes a logged-in user's browser send an unwanted, state-changing request to a site that trusts the user's session cookie?

    1. Cross-site scripting (XSS)
    2. Cross-site request forgery (CSRF)
    3. SQL injection
    4. Server-side request forgery (SSRF)
    Show answer

    Answer: B. Cross-site request forgery (CSRF)

    CSRF abuses the fact that browsers attach cookies automatically. The attacker's page triggers the request; the trusted site sees a valid session and performs the action.

  5. What is the primary defence against SQL injection recommended by OWASP?

    1. Parameterised queries (prepared statements)
    2. Hiding database error messages
    3. Using HTTPS for all pages
    4. Limiting passwords to letters and digits
    Show answer

    Answer: A. Parameterised queries (prepared statements)

    Parameterised queries send the SQL structure and the user data separately, so input can never change the query's logic. Hiding errors and HTTPS are useful but do not stop the injection itself.

  6. What does the HttpOnly flag on a session cookie do?

    1. Sends the cookie only over HTTPS
    2. Blocks the cookie on cross-site requests
    3. Encrypts the cookie value
    4. Stops JavaScript in the page from reading the cookie
    Show answer

    Answer: D. Stops JavaScript in the page from reading the cookie

    HttpOnly hides the cookie from document.cookie, which limits session theft through XSS. Sending only over HTTPS is the Secure flag, and cross-site restrictions come from SameSite.

  7. Under which OWASP Top 10 (2021) category does cross-site scripting fall?

    1. A07 Identification and Authentication Failures
    2. A05 Security Misconfiguration
    3. A03 Injection
    4. A01 Broken Access Control
    Show answer

    Answer: C. A03 Injection

    In 2021 OWASP merged XSS, which had its own entry (A7) in 2017, into A03 Injection, because both come from untrusted data being interpreted as code.

  8. A search page echoes the q parameter from the URL into the page without encoding, and the attacker emails victims a crafted link. Which XSS type is this?

    1. Stored XSS
    2. DOM-based XSS only
    3. Second-order SQL injection
    4. Reflected XSS
    Show answer

    Answer: D. Reflected XSS

    The payload travels in each victim's request and is reflected straight back in the response; nothing is saved on the server. That is reflected XSS, which typically needs a crafted link per victim.

  9. A user changes /orders?id=1001 to /orders?id=1002 and sees another customer's order. What is this vulnerability called?

    1. Insecure direct object reference (IDOR), a broken access control flaw
    2. SQL injection
    3. Cross-site scripting
    4. Session fixation
    Show answer

    Answer: A. Insecure direct object reference (IDOR), a broken access control flaw

    The server trusts the ID in the request and never checks that the record belongs to the logged-in user. OWASP groups IDOR under A01 Broken Access Control.

  10. A page runs element.innerHTML = location.hash.substring(1). Which XSS type can this cause?

    1. Stored XSS
    2. Reflected XSS produced by the server
    3. CSRF
    4. DOM-based XSS
    Show answer

    Answer: D. DOM-based XSS

    The untrusted data (the URL fragment) flows from a source to a dangerous sink entirely in client-side JavaScript, which defines DOM-based XSS. Using textContent instead of innerHTML removes the sink.

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.