Domain 8: Software Development Security Module 62 of 84

Secure Coding Guidelines and Standards

CISSP Domain 8 — Software Development Security A — Secure Development 10–12 minutes

Standards That Actually Change Developer Behavior

A security team publishes a 200-page secure coding standard. It covers every possible vulnerability class, references three international frameworks, and includes code examples in four programming languages. Nobody reads it. A year later, the organization’s applications still contain the same injection flaws, the same broken authentication patterns, and the same hardcoded secrets.

A coding standard that developers do not follow is not a standard. It is a document. The security manager’s job is not to write perfect standards — it is to ensure that standards are adopted, enforced, and measured.

This module covers CISSP exam objective 8.5: define and apply secure coding guidelines and standards. The exam tests this at the governance level — not whether you can write a parameterized query, but whether you know why parameterized queries should be mandated, how that mandate is enforced, and what happens when it is not.


OWASP Top 10 as a Governance Tool

The OWASP Top 10 is not a coding standard. It is an awareness document that identifies the most common and impactful web application security risks. Its value for the CISSP is at the governance and awareness level.

  • Risk awareness — The OWASP Top 10 provides a shared vocabulary for communicating application security risks to developers, managers, and executives. When the security team says “injection,” everyone should understand the category of risk.
  • Training baseline — Developer security training should, at minimum, cover the OWASP Top 10 categories and how they apply to the organization’s technology stack.
  • Assessment benchmark — Security testing should verify that applications are not vulnerable to OWASP Top 10 categories. This is a minimum bar, not a complete assessment.
  • Policy reference — Organizational secure coding policies should reference the OWASP Top 10 as a foundation, supplemented by organization-specific requirements.

The exam does not expect you to memorize the current OWASP Top 10 list. It expects you to understand how the OWASP Top 10 fits into a security governance program.


Input Validation

Input validation is the practice of verifying that all data received by the application conforms to expected formats, types, ranges, and lengths before processing.

  • Principle — All input is untrusted. Data from users, APIs, databases, files, and even internal services should be validated before use.
  • Allowlisting over denylisting — Define what is allowed (allowlist) rather than what is blocked (denylist). Denylists are always incomplete because attackers find encodings and bypasses that are not on the list.
  • Server-side enforcement — Client-side validation improves user experience but provides no security. An attacker bypasses client-side checks trivially. Validation must be enforced on the server.
  • Governance — Secure coding standards should mandate input validation for every data entry point and define the validation approach for common data types (email, phone, currency, free text).

Output Encoding

Output encoding transforms data before it is rendered to prevent injection attacks, particularly cross-site scripting (XSS).

  • Context-specific encoding — Data rendered in HTML requires HTML encoding. Data inserted into JavaScript requires JavaScript encoding. Data placed in URLs requires URL encoding. Using the wrong encoding for the context leaves the application vulnerable.
  • Separation of code and data — Output encoding ensures that user-supplied data is treated as data, never as executable code. When a user submits <script> as input, encoding transforms it into displayable text rather than executable markup.
  • Framework defaults — Modern frameworks (React, Angular, Django) encode output by default. The governance concern is ensuring developers do not bypass these defaults through raw HTML insertion or template overrides.

Parameterized Queries and SQL Injection Prevention

SQL injection occurs when user input is concatenated directly into SQL statements, allowing attackers to modify the query’s logic. It has been the most persistent application vulnerability category for over two decades.

  • Parameterized queries — Separate the SQL command structure from user-supplied data. The database engine treats parameters as data values, never as SQL commands, regardless of their content.
  • Stored procedures — When properly implemented, stored procedures can also prevent SQL injection by pre-defining the query structure. However, stored procedures that dynamically build SQL internally are still vulnerable.
  • ORM safety — Object-Relational Mapping (ORM) frameworks generally prevent SQL injection through parameterization. The risk returns when developers use raw SQL queries within the ORM.
  • Governance standard — Secure coding policies should mandate parameterized queries for all database interactions, with automated SAST rules to detect string concatenation in SQL statements.

Session Management

Session management governs how the application identifies and tracks authenticated users across multiple requests.

  • Session ID generation — Session identifiers must be generated using cryptographically secure random number generators. Predictable session IDs enable session hijacking.
  • Session expiration — Sessions should have both absolute timeouts (maximum session lifetime) and idle timeouts (inactivity limit). The values should be proportional to the sensitivity of the application.
  • Session fixation prevention — Generate a new session ID after successful authentication. If the application reuses a pre-authentication session ID, an attacker can set the session ID before the user logs in and then hijack it afterward.
  • Secure transmission — Session tokens must be transmitted over encrypted channels (HTTPS) and stored with appropriate cookie flags: Secure (HTTPS only), HttpOnly (not accessible via JavaScript), and SameSite (CSRF protection).

Error Handling and Logging

Error handling and logging are security functions, not just debugging tools.

Error Handling

  • Fail secure — When an error occurs, the application should deny access by default rather than granting it. An authentication error should result in access denied, not access granted.
  • No information leakage — Error messages displayed to users should be generic. Stack traces, database error messages, file paths, and internal system details must never be exposed to end users. These details assist attackers in refining their approach.
  • Consistent error handling — Centralized error handling ensures consistent behavior across the application. Scattered try-catch blocks with inconsistent handling create unpredictable security behavior.

Security Logging

  • What to log — Authentication events (success and failure), authorization failures, input validation failures, administrative actions, and data access events.
  • What not to log — Passwords, session tokens, credit card numbers, social security numbers, or any sensitive data that would create a second data protection problem in the log files themselves.
  • Log integrity — Logs must be protected from tampering. An attacker who gains application access should not be able to modify or delete logs that record their activity.

Memory Safety and Buffer Overflow Prevention

Memory safety vulnerabilities — buffer overflows, use-after-free, null pointer dereferences — remain among the most dangerous software defects because they can enable arbitrary code execution.

  • Language choice — Memory-safe languages (Java, C#, Python, Rust) prevent most buffer overflow conditions through managed memory. Languages like C and C++ require manual memory management and are prone to these defects. The governance decision of which languages to use has direct security implications.
  • Safe functions — When C/C++ is required, coding standards should mandate safe alternatives to known-dangerous functions (e.g., strncpy instead of strcpy, snprintf instead of sprintf).
  • Compiler protections — Address Space Layout Randomization (ASLR), stack canaries, Data Execution Prevention (DEP), and other compiler/OS protections provide defense in depth. These should be enabled by default in build configurations.
  • Fuzz testing — As covered in Module 60, fuzz testing is particularly effective at discovering memory safety issues through random input generation.

API Security Standards

APIs are the dominant interface for modern applications. Governing API security requires standards that address the unique characteristics of machine-to-machine communication.

  • Authentication — API authentication should use token-based mechanisms (OAuth 2.0, JWT) rather than embedding credentials in requests. API keys alone do not provide sufficient authentication for sensitive operations.
  • Authorization — Every API endpoint must enforce authorization checks. Object-level authorization (can this user access this specific record?) is a common gap — broken object-level authorization is consistently in the OWASP API Security Top 10.
  • Rate limiting — APIs must enforce rate limits to prevent brute-force attacks, denial of service, and data scraping.
  • Schema validation — API requests should be validated against a defined schema (OpenAPI specification) that enforces data types, required fields, and value constraints.

Secure Coding Standards and Governance

Several established standards provide frameworks for organizational secure coding policies.

  • CERT Secure Coding Standards — Language-specific standards (C, C++, Java, Perl) from Carnegie Mellon’s CERT division. Each standard defines rules and recommendations organized by vulnerability category.
  • MISRA — Motor Industry Software Reliability Association guidelines, primarily for C and C++. Widely used in safety-critical systems (automotive, medical devices, industrial control) where memory safety is paramount.
  • OWASP Secure Coding Practices — A technology-agnostic checklist of secure coding practices organized by category (input validation, output encoding, authentication, session management, access control, and others).

Code Review Checklist Governance

Code review checklists operationalize secure coding standards by providing reviewers with specific items to verify during each code review.

  • Standard alignment — Checklist items should map directly to the organization’s secure coding standard so that every review reinforces the same requirements.
  • Automation support — Items that can be automated (SAST rules, linting) should be, freeing human reviewers to focus on logic, context, and design-level issues.
  • Living document — Checklists should be updated when new vulnerability patterns emerge, when the technology stack changes, or when post-incident analysis reveals review gaps.

Pattern Recognition

Secure coding questions on the CISSP tend to follow these structures:

  • Vulnerability scenario — The question describes an application vulnerability. The answer identifies the secure coding practice that would have prevented it (input validation for injection, output encoding for XSS, parameterized queries for SQL injection).
  • Governance vs. implementation — The question asks what the security manager should do. The answer is about policy, standards, and enforcement — not about writing or reviewing code.
  • Standard selection — The question describes an environment (embedded systems, web applications, enterprise Java). The answer matches the appropriate coding standard (MISRA for embedded, OWASP for web, CERT for language-specific).
  • Error handling failure — The application reveals internal information during an error. The answer addresses fail-secure design and information leakage prevention.

Trap Patterns

Watch for these wrong answers:

  • “Input validation alone prevents all injection attacks” — Input validation is one layer. Parameterized queries, output encoding, and least-privilege database accounts are also needed. Defense in depth applies to coding practices too.
  • “Client-side validation is sufficient” — Client-side checks are a user experience feature. Security validation must happen server-side because client-side controls can be bypassed entirely.
  • “Detailed error messages help users understand problems” — Helpful error messages for users should never include technical details. Stack traces and database errors go to logs, not to the user interface.
  • “Modern languages eliminate the need for secure coding standards” — Memory-safe languages prevent buffer overflows but do not prevent injection, authentication flaws, authorization bypasses, or business logic errors. Secure coding standards address the full spectrum of application vulnerabilities.

Scenario Practice


Question 1

A security audit reveals that a web application displays detailed database error messages to users when invalid input is submitted. The error messages include table names, column names, and the SQL query that failed.

What TWO risks does this create?

A. Performance degradation and increased logging costs
B. Information leakage that helps attackers craft SQL injection attacks and failure to implement the fail-secure principle
C. User confusion and increased help desk calls
D. Database corruption and data loss

Answer & reasoning

Correct: B

Detailed database error messages provide attackers with the exact information they need to refine injection attacks: table and column names reveal the database structure, and the failed query shows how the application constructs SQL statements. This is both an information leakage vulnerability and a failure to implement fail-secure error handling, which should display generic messages to users while logging details internally.


Question 2

An organization developing software for medical devices needs to select a secure coding standard. The software is written in C for embedded systems where memory safety and reliability are paramount.

Which standard is MOST appropriate?

A. OWASP Secure Coding Practices
B. MISRA C, because it is specifically designed for safety-critical embedded systems using C
C. PCI DSS coding requirements
D. NIST 800-53 development controls

Answer & reasoning

Correct: B

MISRA C is the industry standard for safety-critical embedded systems written in C. It addresses memory safety, undefined behavior, and reliability concerns specific to embedded development. OWASP focuses on web applications. PCI DSS addresses payment card environments. NIST 800-53 provides general security controls, not language-specific coding standards.


Question 3

A development team uses an ORM framework and believes they are protected from SQL injection. During a code review, the security team discovers several instances where developers use raw SQL queries within the ORM to handle complex reporting requirements.

What should the security team recommend?

A. Replace the ORM with direct database access for consistency
B. Ensure all raw SQL queries use parameterized statements, update the coding standard to require parameterization for any SQL outside the ORM, and add SAST rules to detect unparameterized raw SQL
C. Prohibit all raw SQL queries and rewrite the reporting features using only the ORM
D. Accept the risk since raw SQL is only used for reporting, which is read-only

Answer & reasoning

Correct: B

The practical response addresses the immediate risk (ensure raw SQL uses parameterized statements), updates governance (modify the coding standard), and adds enforcement (SAST rules). Prohibiting all raw SQL may not be feasible for complex queries. Accepting the risk because queries are read-only is incorrect — SQL injection in read queries can still extract data, bypass authentication, or escalate through UNION-based attacks.


Key Takeaway

Secure coding standards exist at the intersection of technical practice and organizational governance. The CISSP does not expect you to write secure code, but it does expect you to know which standards to mandate, how to enforce them through automation and review processes, and why specific practices (input validation, parameterized queries, output encoding, fail-secure error handling) prevent specific vulnerability categories. This is the final content module in the CISSP curriculum. You have now covered all eight domains — from governance and risk management through software development security. Every domain connects back to the same principle: security is a management discipline that uses technical controls to achieve business objectives. Carry that perspective into the exam.

Next Module Section A Review: Secure Development