Top 10 Secure Coding Practices - CERT Secure Coding (2024)

Top 10 Secure Coding Practices

  1. Validate input. Validate input from all untrusted data sources. Proper input validation can eliminate the vast majority of software vulnerabilities. Be suspicious of most external data sources, including command line arguments, network interfaces, environmental variables, and user controlled files [Seacord 05].
  2. Heed compiler warnings. Compile code using the highest warning level available for your compiler and eliminate warnings by modifying the code [C MSC00-A, C++ MSC00-A]. Use static and dynamic analysis tools to detect and eliminate additional security flaws.
  3. Architect and design for security policies. Create a software architecture and design your software to implement and enforce security policies. For example, if your system requires different privileges at different times, consider dividing the system into distinct intercommunicating subsystems, each with an appropriate privilege set.
  4. Keep it simple. Keep the design as simple and small as possible [Saltzer 74, Saltzer 75]. Complex designs increase the likelihood that errors will be made in their implementation, configuration, and use. Additionally, the effort required to achieve an appropriate level of assurance increases dramatically as security mechanisms become more complex.
  5. Default deny. Base access decisions on permission rather than exclusion. This means that, by default, access is denied and the protection scheme identifies conditions under which access is permitted [Saltzer 74, Saltzer 75].
  6. Adhere to the principle of least privilege. Every process should execute with the the least set of privileges necessary to complete the job. Any elevated permission should only be accessed forthe least amount of time required to complete the privilegedtask. This approach reduces the opportunities an attacker has to execute arbitrary code with elevated privileges [Saltzer 74, Saltzer 75].
  7. Sanitize data sent to other systems. Sanitize all data passed to complex subsystems [C STR02-A] such as command shells, relational databases, and commercial off-the-shelf (COTS) components. Attackers may be able to invoke unused functionality in these components through the use of SQL, command, or other injection attacks. This is not necessarily an input validation problem because the complex subsystem being invoked does not understand the context in which the call is made. Because the calling process understands the context, it is responsible for sanitizing the data before invoking the subsystem.
  8. Practice defense in depth. Manage risk with multiple defensive strategies, so that if one layer of defense turns out to be inadequate, another layer of defense can prevent a security flaw from becoming an exploitable vulnerability and/or limit the consequences of a successful exploit. For example, combining secure programming techniques with secure runtime environments should reduce the likelihood that vulnerabilities remaining in the code at deployment time can be exploited in the operational environment [Seacord 05].
  9. Use effective quality assurance techniques. Good quality assurance techniques can be effective in identifying and eliminating vulnerabilities. Fuzz testing, penetration testing, and source code audits should all be incorporated as part of an effective quality assurance program. Independent security reviews can lead to more secure systems. External reviewers bring an independent perspective; for example, in identifying and correcting invalid assumptions [Seacord 05].
  10. Adopt a secure coding standard. Develop and/or apply a secure coding standard for your target development language and platform.

Bonus Secure Coding Practices

  1. Define security requirements. Identify and document security requirements early in the development life cycle and make sure that subsequent development artifacts are evaluated for compliance with those requirements. When security requirements are not defined, the security of the resulting system cannot be effectively evaluated.
  2. Model threats. Use threat modeling to anticipate the threats to which the software will be subjected. Threat modeling involves identifying key assets, decomposing the application, identifying and categorizing the threats to each asset or component, rating the threats based on a risk ranking, and then developing threat mitigation strategies that are implemented in designs, code, and test cases [Swiderski 04].

Bonus Photograph

We like the following photograph because it illustrates how the easiest way to break system security is often to circumvent it rather than defeat it (as is the case with most software vulnerabilities related to insecure coding practices).

Top 10 Secure Coding Practices - CERT Secure Coding (1)

The photograph depicted a street (named Konsequenz) in the University Bielefeld, Germany, at lat/long. 52.036818, 8.491467. It is visible viaGoogle Street View.

We don't know who took this photograph. If you do, please let us know in the comments!

References

[Saltzer 74] Saltzer, J. H. "Protection and the Control of Information Sharing in Multics." Communications of the ACM 17, 7 (July 1974): 388-402.

[Saltzer 75] Saltzer, J. H. & Schroeder, M. D. "The Protection of Information in Computer Systems." Proceedings of the IEEE 63, 9 (September 1975), 1278-1308.

[Seacord 05] Seacord, R. Secure Coding in C and C++. Upper Saddle River, NJ: Addison-Wesley, 2006 (ISBN 0321335724).

[Swiderski 04] Swiderski, F. & Snyder, W. Threat Modeling. Redmond, WA: Microsoft Press, 2004.

Top 10 Secure Coding Practices - CERT Secure Coding (2024)

FAQs

Top 10 Secure Coding Practices - CERT Secure Coding? ›

However, the practice of hardcoding credentials is increasingly discouraged as they pose formidable security risks that continue to be exploited by malware and hackers.

What is the best secure code practice? ›

8 Secure Coding Best Practices
  • Security by Design.
  • Password Management.
  • Access Control.
  • Error Handling and Logging.
  • System Configuration.
  • Threat Modeling.
  • Cryptographic Practices.
  • Input Validation and Output Encoding.
Dec 27, 2023

Is credential hard coding a secure coding practice? ›

However, the practice of hardcoding credentials is increasingly discouraged as they pose formidable security risks that continue to be exploited by malware and hackers.

What does the OWASP top 10 list name the classification for this vulnerability? ›

OWASP Top 10 Vulnerabilities
  • A01. Broken Access Control. ...
  • A02: Cryptographic Failures. ...
  • A03: Injection. ...
  • A04: Insecure Design. ...
  • A05: Security Misconfiguration. ...
  • A06: Vulnerable and Outdated Components. ...
  • A07 Identification and Authentication Failures. ...
  • A08: Software and Data Integrity Failures.

Which of the following is secure coding practice? ›

Secure Coding Practices

Formalize and document the software development life cycle (SDLC) processes to incorporate a major component of a development process: Requirements. Architecture and Design. Implementation.

What is the most secure code in the world? ›

Java: Java, a stalwart in the programming world, incorporates robust security features. Its sandboxing mechanism and bytecode verification ensure a secure execution environment. The sandbox isolates Java applications, preventing potentially harmful actions.

Is coding easier than cyber security? ›

Entry Barrier: Cybersecurity often presents a lower entry barrier, making it accessible to those without extensive technical skills. Coding requires a higher level of technical proficiency to initiate a career.

How hard is coding actually? ›

Yes, it can get complicated if you try to do too much too soon—without help, a purpose, or learning fundamental skills. But then no, it's also not hard to learn to code if you start learning where you're at. It's easier when you start with foundational skills, like-minded people, mentors, and a goal in mind.

What is the most critical OWASP Top 10 risk? ›

What is the OWASP Top 10?
  1. Injection. ...
  2. Broken Authentication. ...
  3. Sensitive Data Exposure. ...
  4. XML External Entities (XEE) ...
  5. Broken Access Control. ...
  6. Security Misconfiguration. ...
  7. Cross-Site Scripting. ...
  8. Insecure Deserialization.

What is the latest OWASP Top 10? ›

What is the OWASP Top 10?
  • A01:2021-Broken Access Control.
  • A02:2021-Cryptographic Failures.
  • A03:2021-Injection.
  • A04:2021-Insecure Design.
  • A05:2021-Security Misconfiguration.
  • A06:2021-Vulnerable and Outdated Components.
  • A07:2021-Identification and Authentication Failures.
  • A08:2021-Software and Data Integrity Failures.

Why is the OWASP Top 10 important? ›

The OWASP Top 10 is a standard awareness document for developers and web application security. It represents a broad consensus about the most critical security risks to web applications. Globally recognized by developers as the first step towards more secure coding.

What are the three techniques used in secure coding? ›

Secure Coding Practices Checklist
  • Conduct all input validation on a trusted system (server side not client side)
  • Identify all data sources and classify them into trusted and untrusted.
  • Validate all data from untrusted sources (databases, file streams, etc)

How to practice secure coding? ›

Use effective quality assurance techniques (for example, penetration testing, source code audits, application scanning) to identify and eliminate vulnerabilities. Conduct application scanning before major changes or revisions are moved to production.

What is the best practice of secure code review? ›

Incorporating automated code security tools and libraries in your security code review process can significantly streamline and enhance input validation. These tools help identify vulnerabilities that might be overlooked and ensure consistent application of validation rules. However, validation is not a one-time task.

What is the best practice for securing passwords? ›

These 7 tips will help make your digital life more secure.
  • Never reveal your passwords to others. ...
  • Use different passwords for different accounts. ...
  • Use multi-factor authentication (MFA). ...
  • Length trumps complexity. ...
  • Make passwords that are hard to guess but easy to remember.
  • Complexity still counts. ...
  • Use a password manager.

What is security best practice? ›

Using strong passwords, updating your software, thinking before you click on suspicious links, and turning on multi-factor authentication are the basics of what we call “cyber hygiene” and will drastically improve your online safety.

What is the best practice for authentication? ›

Authentication Best Practices
  • Use Strong Authentication Mechanisms: Prefer token-based mechanisms like OAuth 2.0 and JWT for their robustness and suitability for RESTful APIs.
  • Implement Rate Limiting and Throttling: Protect APIs against brute-force attacks by limiting the number of authentication attempts.
Jan 19, 2024

What is the best practice for code review? ›

Review fewer than 400 lines of code at a time

The brain can only effectively process so much information at a time; beyond 400 LOC, the ability to find defects diminishes. In practice, a review of 200-400 LOC over 60 to 90 minutes should yield 70-90% defect discovery.

References

Top Articles
Latest Posts
Article information

Author: Horacio Brakus JD

Last Updated:

Views: 5327

Rating: 4 / 5 (51 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Horacio Brakus JD

Birthday: 1999-08-21

Address: Apt. 524 43384 Minnie Prairie, South Edda, MA 62804

Phone: +5931039998219

Job: Sales Strategist

Hobby: Sculling, Kitesurfing, Orienteering, Painting, Computer programming, Creative writing, Scuba diving

Introduction: My name is Horacio Brakus JD, I am a lively, splendid, jolly, vivacious, vast, cheerful, agreeable person who loves writing and wants to share my knowledge and understanding with you.