Web Security MCQs

8 MCQs  — Web Development MCQs

Practice Web Security MCQs with correct answers and explanations. These questions are from the Web Development MCQs section.

Which approach is the correct primary defense against SQL injection?
Hiding error messages
Using HTTPS
Parameterized queries (prepared statements)
Client-side input validation
What is CSRF (Cross-Site Request Forgery)?
Tricking a logged-in user's browser into sending an unwanted request to a site where the user is authenticated
Guessing passwords
Stealing a database through SQL
Injecting scripts into pages
How should user passwords be stored?
Encrypted with AES, so they can be decrypted later
In plain text in a secure database
As salted hashes using a slow algorithm such as bcrypt, scrypt, or Argon2
As MD5 hashes
Does a correct CORS configuration protect an API from being called by scripts or tools such as curl?
Yes, but only for POST requests
No; CORS only controls which web origins a browser lets read the responses. Server-side authentication is still required
CORS encrypts API traffic
Yes, it blocks all unauthorized clients
Which HTTP header helps prevent clickjacking?
X-Frame-Options (or CSP frame-ancestors)
Content-Type
Cache-Control
Accept-Language
What does a Content Security Policy (CSP) primarily mitigate?
XSS and data injection, by restricting where scripts and other resources can load from
Slow page loads
DDoS attacks
SQL injection
Which statement about sessions is correct?
Session data is stored on the server; the client usually keeps only a session ID in a cookie
Sessions do not use cookies at all
Sessions are stored in DNS
All session data is stored in the cookie