Sample questions
Question 1Easy
Which Python module should be used to generate secure tokens?
- random
- math
- string
- secrets
Answer: D. secrets
Explanation
The secrets module uses the OS's secure random source; random is for simulations, not security.
Step-by-step solution
- The secrets module uses the operating system's secure random source.
- The random module is for simulations and is predictable.
- Math and string do not generate random tokens.
- So the answer is secrets.
Why the other options are wrong
- A. Random is not secure for tokens.
- B. Math has no random token generator.
- C. String holds character constants and has no secure token generator.
Tip: In Python, use secrets for tokens and passwords, never random.
Question 2Easy
Which is the safest way to handle user input in a web application?
- Execute it directly to save time
- Validate it and treat it as untrusted
- Store it without any checks
- Trust it if it comes from a logged-in user
Answer: B. Validate it and treat it as untrusted
Explanation
All external input should be validated, and encoded or parameterised when used.
Step-by-step solution
- All external input can be malicious, even from logged-in users.
- Input should be validated against what is expected.
- It should be encoded or parameterised before use.
- So the safest way is to validate it and treat it as untrusted.
Why the other options are wrong
- A. Running input directly allows injection.
- C. Storing input without checks lets bad data in.
- D. Logged-in users can still send malicious input or be compromised.
Tip: Treat all input as untrusted: validate, then encode or parameterise.
Question 3Easy
A CVE identifier refers to:
- A type of encryption key
- A disclosed vulnerability
- A firewall configuration
- A cloud vendor's product
Answer: B. A disclosed vulnerability
Explanation
Common Vulnerabilities and Exposures gives each publicly disclosed vulnerability a unique ID.
Step-by-step solution
- CVE stands for Common Vulnerabilities and Exposures.
- It is a catalogue that gives each publicly disclosed vulnerability a unique ID.
- A CVE ID names a specific disclosed flaw.
- So a CVE identifier refers to a disclosed vulnerability.
Why the other options are wrong
- A. A CVE is not an encryption key.
- C. A firewall configuration is not a CVE.
- D. A CVE is not a vendor product.
Tip: CVE-YYYY-NNNN names one disclosed vulnerability.
Question 4Medium
Which is the safest approach to cryptography in application code?
- Invent a custom cipher
- Use Base64 as encryption
- Reuse one IV for every message
- Use vetted libraries
Answer: D. Use vetted libraries
Explanation
Home-made crypto almost always has flaws; vetted libraries implement algorithms and modes correctly.
Step-by-step solution
- Custom ciphers and modes are very hard to get right.
- Vetted libraries have been reviewed and implement algorithms correctly.
- Base64 is encoding, not encryption, and IV reuse breaks security.
- So the safest approach is to use vetted libraries.
Why the other options are wrong
- A. Home-made ciphers almost always have flaws.
- B. Base64 is only encoding and gives no secrecy.
- C. Reusing an IV weakens many modes of encryption.
Tip: Do not invent crypto. Use well-known libraries and standard modes.
Question 5Medium
Code signing of software releases lets users verify:
- The code runs faster
- The code is open source
- The code has no bugs
- Publisher identity and integrity
Answer: D. Publisher identity and integrity
Explanation
A valid signature ties the binary to the publisher's key and detects tampering.
Step-by-step solution
- The publisher signs the release with a private key.
- Users verify with the public key/certificate.
- A valid check proves who published it and that the code was not altered.
Why the other options are wrong
- A. Signing says nothing about speed.
- B. Closed-source software can be signed too.
- C. A signature does not prove the code is bug-free or safe.
Question 6Medium
Static Application Security Testing (SAST) analyses:
- Source code without running it
- A running application from outside
- Physical access logs
- Network traffic only
Answer: A. Source code without running it
Explanation
SAST finds issues such as injection patterns in code; DAST tests the running app.
Step-by-step solution
- SAST is a static analysis method.
- It examines source code without running the program.
- It finds patterns such as injection risks in the code.
- So SAST analyses source code without running it.
Why the other options are wrong
- B. Testing a running app from outside is DAST.
- C. Physical access logs are outside application security testing.
- D. Network traffic is examined by network tools, not SAST.
Tip: SAST = code without running it. DAST = running app from outside.
Question 7Medium
Why should applications "fail securely"?
- So users see full stack traces
- So crashes restart forever
- Errors must deny access
- To skip logging
Answer: C. Errors must deny access
Explanation
If an authorisation check throws an error, the default should be to deny access.
Step-by-step solution
- If an access check throws an error, the code might skip the check.
- A failing system should therefore default to denying access.
- Failing open would let an attacker cause errors to gain access.
- So errors must deny access.
Why the other options are wrong
- A. Showing stack traces leaks information and is not the goal.
- B. Crash loops are a reliability issue, not the security reason.
- D. Skipping logs makes incidents harder to investigate.
Tip: Fail closed: an error in an access check means no access.
Question 8Medium
Hard-coding database passwords in source code is risky because:
- Anyone who sees the code gets them
- Databases refuse hard-coded passwords
- It makes the code run slower
- Compilers reject passwords in code
Answer: A. Anyone who sees the code gets them
Explanation
Secrets belong in a secrets manager or environment configuration, not in version control.
Step-by-step solution
- Source code is shared, committed and often leaked.
- Anyone who can read it sees the password.
- Use environment variables or a secrets manager.
Why the other options are wrong
- B. Databases accept them.
- C. No effect on speed.
- D. Compilers do not check.
Question 9Hard
Why is using a cryptographically secure random number generator important for generating session tokens?
- It makes tokens shorter
- Guessable tokens are risky
- It removes the need for HTTPS
- Secure RNGs are always faster
Answer: B. Guessable tokens are risky
Explanation
Ordinary PRNGs like Math.random or rand() can be predicted;
use secrets or SecureRandom.
Step-by-step solution
- A session token must be hard to guess.
- Ordinary random generators like rand or Math.random can be predicted.
- A cryptographically secure generator gives unpredictable values.
- So guessable tokens are the risk that secure randomness removes.
Why the other options are wrong
- A. Secure tokens are not made shorter by a secure generator.
- C. A secure generator does not replace HTTPS.
- D. Secure generators are not always faster.
Tip: Use a secure random source (for example Python secrets) for tokens.
Question 10Hard
A developer escapes user input for HTML but inserts it inside a JavaScript string in a script block. Why can this still be vulnerable?
- JavaScript cannot contain user data
- HTML escaping is always enough
- Contexts need different encoding
- Browsers ignore script blocks
Answer: C. Contexts need different encoding
Explanation
Escaping rules differ between HTML body, attributes, JavaScript, CSS and URLs; use context-specific encoding.
Step-by-step solution
- HTML escaping protects text in the HTML body.
- Inside a JavaScript string, the rules are different.
- Text escaped for HTML can still break out of a JS string.
- So contexts need different encoding.
Why the other options are wrong
- A. User data can be placed in a JS string, but it must be encoded for that context.
- B. HTML escaping alone is not enough for JavaScript.
- D. Browsers do run script blocks, so this is not the reason.
Tip: Encode for the context: HTML body, attribute, JavaScript, CSS or URL each need their own rules.
Practise all 22 questions free
The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.
Open this topic in the app →