Secure Software Development MCQs for NSCT
Secure software development means building security into every stage of writing software: secure coding habits, strict input validation, and a secure software development life cycle (SDLC) with threat modelling and security testing. It is the ninth topic in the Cyber Security area, which carries 5% of the NSCT according to HEC's Areas of Competencies. That area had 47.2% accuracy in 2026, per the HEC NSCT report and APP.
This page follows the software security chapters of Stallings and Brown, Computer Security: Principles and Practice, plus the OWASP and Microsoft SDL guidance that exam questions draw on. Specific web attacks such as XSS and CSRF are covered in Web Application Security.
Secure coding
Secure coding means writing code that stays safe when it gets hostile input or hits an error. The core habits:
- Never trust input. Treat everything from users, files, the network and other services as untrusted.
- Bounds checking. In C and C++, a buffer overflow writes past the end of an array and can overwrite a return address. Use length-limited functions and check every index.
- Integer overflow. In C, an 8-bit unsigned value holding 200 + 100 keeps (300 mod 256) = 44. A buffer sized from that number is too small.
- Fail safely. On an error, deny access (fail closed) and show a generic message. Log the details privately; never show stack traces to users.
- Do not invent cryptography. Use vetted libraries, for example bcrypt or Argon2 for passwords.
- Keep secrets out of code. A key committed to Git stays in its history, so it must be revoked and rotated.
These follow Saltzer and Schroeder's design principles, such as fail-safe defaults (deny unless explicitly allowed), least privilege and complete mediation (check every access).
Compiler and OS mitigations reduce the damage but do not fix the bug: stack canaries detect overwrites of the return address, ASLR randomises addresses, and NX/DEP stops code running from the stack.
Exam angle: if the error path returns "allow", the code fails open, which is the bug to spot.
Input validation
Input validation checks that data has the expected type, length, format and range before the program uses it.
| Approach | How it works | Verdict |
|---|---|---|
| Allow-list | Accept only known-good values or patterns | Preferred |
| Deny-list | Reject known-bad strings such as <script> |
Easy to bypass |
| Client-side only | JavaScript checks in the browser | Convenience only; attackers skip it |
| Server-side | Checks on the server before use | Required |
Two rules that catch many students:
- Canonicalise first.
%2e%2e%2fdecodes to../. A filter that checks before decoding misses it, so decode to a single standard form, then validate. - Validate the whole string. In Python,
re.match(r"\d+", "7; rm")succeeds because it only anchors at the start.re.fullmatchchecks the whole input.
Validation is not the only defence. Put data into queries with parameterised statements, so input can never change the SQL logic. When you write it into HTML, use context-aware output encoding (< becomes <).
Exam angle: deny-list answers are almost always the distractor.
Secure SDLC
A secure SDLC adds security activities to each phase instead of testing only at the end. Microsoft's classic Security Development Lifecycle (SDL) has seven phases: Training, Requirements, Design, Implementation, Verification, Release and Response.
Threat modelling in design maps data flows and trust boundaries and asks what can go wrong. Microsoft's STRIDE gives the checklist:
| Threat | Property violated |
|---|---|
| Spoofing | Authentication |
| Tampering | Integrity |
| Repudiation | Non-repudiation |
| Information disclosure | Confidentiality |
| Denial of service | Availability |
| Elevation of privilege | Authorisation |
Security testing tools differ in what they see:
| Tool | Needs running app? | Finds |
|---|---|---|
| SAST (static) | No | Unsafe code patterns, hard-coded secrets |
| DAST (dynamic) | Yes | Runtime and configuration flaws |
| SCA (composition analysis) | No | Known CVEs in third-party libraries |
| Fuzzing | Yes | Crashes from malformed input |
Shift left (the DevSecOps idea) means doing these checks as early as possible, because a design flaw found in design costs far less to fix than one found after release.
Exam angle: "flaw in an open-source library" points to SCA, not SAST.
Common traps
- Relying on JavaScript validation. Attackers send requests straight to the server.
- Escaping quotes and calling it SQL injection protection. Numeric inputs such as
1 OR 1=1need no quotes; parameterised queries are the fix. - Choosing a deny-list because it "blocks attacks". Allow-lists are the recommended default.
- Mixing up SAST (reads code) and DAST (attacks the running app).
- Treating ASLR or canaries as a fix for a buffer overflow. They are mitigations; bounds checking is the fix.
- Assuming a penetration test before release can replace design-stage threat modelling.
Worked examples
1. Understanding. In STRIDE, an attacker denies having placed an order because the system keeps no log of who did what. Which category is this? Answer: Repudiation. The threat is to non-repudiation. Secure audit logs, and digital signatures where needed, are the mitigations.
2. Application. A Python filter removes the string .. once from a file name using name.replace("..", "", 1). What is left of the input ....//secret.txt?
Answer: ..//secret.txt. Only the first .. is removed, leaving ..//secret.txt, which still climbs a directory. Validate the canonical path against the base folder instead of stripping strings.
3. Analysis. Code review finds if (check_license() != ERROR) grant_access();, where check_license() returns OK, INVALID or ERROR. Why is this unsafe?
Answer: an INVALID licence still gets access. The condition grants access for anything except ERROR, which breaks fail-safe defaults. It should grant access only when the result equals OK.
Practise
The quiz below has 98 questions on this topic, filterable by tier and difficulty.
Practise: 98 questions
FAQs
What is the difference between input validation and output encoding?
Input validation checks that incoming data has the right type, format and range, and rejects anything else. Output encoding changes special characters when data is written into a particular context, such as HTML, so the browser treats it as text. You need both: validation narrows what enters, and encoding makes what leaves safe for its context.
What is the difference between SAST and DAST?
SAST analyses source code or binaries without running them, so it can run on every commit and points to the exact line. DAST attacks a running application from the outside and finds runtime and configuration problems, but cannot show the faulty line. Most teams use both, plus SCA for third-party libraries.
What is a secure SDLC?
A secure SDLC adds security work to every phase of development: security requirements, threat modelling in design, secure coding and code review in implementation, security testing in verification, and an incident response plan after release. Microsoft's SDL is the best-known example. The goal is to find flaws early, when they are cheapest to fix.
Is NSCT cyber security related to software engineering?
Partly. HEC lists Secure Software Development under Cyber Security, while Software Engineering is a separate 10% area. The ideas overlap with Software Security Engineering, so studying both together saves time.
Next step
Continue with Wireless & Mobile Security MCQs. For the attacks these practices prevent, see OWASP Top 10. Browse all topics on the Cyber Security hub, then take an NSCT mock test.