Secure Coding Practices
Secure Coding Practices
🌟🌟
🚀🚀
● OWASP Based Checklist
● 200+ Test Cases
Contents
1. Input Validation..........................................................................................................................................................2
2. Output Encoding.....................................................................................................................................................6
4. Session Management.........................................................................................................................................16
5. Access Control.........................................................................................................................................................20
6. Cryptographic Practices...................................................................................................................................26
8. Data Protection......................................................................................................................................................34
9. Communication Security................................................................................................................................ 38
15. Glossary......................................................................................................................................................................64
1. Input Validation
The "Input validation" section in your Secure Coding Practices checklist involves
measures to ensure that data coming into your application is safe and free from
potential security risks. It includes practices like conducting validation on trusted
systems, distinguishing between trusted and untrusted data sources, specifying
character sets, validating data types, lengths, and ranges, and being cautious about
potentially hazardous characters. The goal is to prevent malicious data from entering
your application and to handle it safely if it must be allowed. These practices help
safeguard against common security vulnerabilities, such as injection attacks, by
ensuring that only well-formed, expected, and safe data is processed.
1.1 Conduct all Ensure that all data When a user submits a form,
data validation validation is performed the server checks the input
on a trusted on the server, not on data for validity and rejects it
system the client side. This if it doesn't meet the criteria.
prevents validation Client-side JavaScript should
rules from being not be relied upon for
bypassed by validation.
manipulating
client-side code.
1.2 Identify all data Classify data sources as When processing data from
sources and trusted (e.g., internal user-submitted forms and
classify them databases) or external APIs, ensure that all
untrusted (e.g., user input is thoroughly validated,
input, external APIs). regardless of its source.
Validate all data from
untrusted sources to
prevent malicious
input.
2
https://www.linkedin.com/in/hariprasaanth/
1.4 Specify proper Define a consistent Ensure that all data,
character sets character set, such as regardless of its source, is
UTF-8, for all sources of consistently encoded using
input to avoid UTF-8 to prevent
encoding mismatches encoding-related issues.
and potential security
vulnerabilities.
1.8 Validate all Validate all input from When processing data from
client-provided the client, including client-side sources, such as
data parameters, URLs, form submissions and HTTP
HTTP headers, and headers, validate it rigorously
automated postbacks, to avoid code injection
to prevent malicious vulnerabilities.
code injection.
3
https://www.linkedin.com/in/hariprasaanth/
1.9 Verify header Ensure that header Check that header values are
values contain values in both requests limited to ASCII characters to
only ASCII and responses contain prevent security issues
characters only ASCII characters to stemming from character
prevent potential encoding variations.
attacks exploiting
character encoding
differences.
1.10 Validate data Validate data from When handling data from
from redirects redirects to prevent redirects, ensure that it is
malicious content from validated to prevent security
being directly bypasses.
submitted to the
redirect target,
bypassing application
logic.
1.11 Validate for Verify that input Check that input is of the
expected data matches the expected correct data type to avoid
types data type, such as errors and security issues
integer, string, or date, caused by data type
to prevent type-related mismatches.
errors and potential
vulnerabilities.
1.12 Validate data Check that input Ensure that input values are
range values fall within the within specified ranges to
expected range to prevent security issues
prevent overflow or related to data overflow or
underflow conditions underflow.
that could lead to
vulnerabilities.
1.13 Validate data Limit the length of Restrict the length of input
length input to prevent buffer data to mitigate security risks
overflows and other associated with buffer
length-based attacks. overflows and other
length-based vulnerabilities.
4
https://www.linkedin.com/in/hariprasaanth/
1.14 Validate all Whenever possible, Ensure that input is validated
input against a validate input against a against a predefined whitelist
"white" list whitelist of allowed of permissible characters to
characters to restrict minimize security risks.
the range of
acceptable input and
prevent malicious code
injection.
5
https://www.linkedin.com/in/hariprasaanth/
2. Output Encoding
The "output encoding" section in your Secure Coding Practices checklist focuses on
ensuring that data leaving your application is secure and properly formatted. It involves
practices such as conducting encoding on trusted systems, utilizing established
encoding routines, and contextually encoding or sanitizing data before returning it to
clients. This helps prevent security vulnerabilities by ensuring that all data is presented
in a safe and well-structured manner, especially when it originated from untrusted
sources. Proper output encoding safeguards against issues like cross-site scripting
(XSS) and injection attacks by ensuring that data is correctly processed for the
intended interpreter and presentation medium.
2.1 Conduct all Ensure that all When generating HTML for
encoding on a encoding of output a web page, the server
trusted system data is performed on should encode special
the server, not on the characters to prevent
client side, to prevent cross-site scripting (XSS)
tampering and security vulnerabilities.
vulnerabilities.
6
https://www.linkedin.com/in/hariprasaanth/
2.4 Encode all Encode all characters in Encode special characters
characters output data unless they like "<" and ">" in
unless they are are explicitly known to user-generated content to
known to be be safe for the intended prevent XSS attacks.
safe interpreter to prevent
malicious code
injection or data
manipulation.
7
https://www.linkedin.com/in/hariprasaanth/
3. Authentication and Password Management
8
https://www.linkedin.com/in/hariprasaanth/
3.4 Use a Implement a Authentication should be
centralized centralized handled through a
implementatio authentication centralized system that
n for all mechanism for all manages user credentials
authentication authentication-related and permissions.
controls processes, providing a
single point of control
for managing user
credentials and access
permissions.
9
https://www.linkedin.com/in/hariprasaanth/
3.8 Secure storage If the application Passwords should be stored
of password manages a credential securely using strong
hashes store, ensure that only hashing algorithms, and
cryptographically access to the storage should
strong one-way salted be tightly controlled.
hashes of passwords
are stored. The table/file
storing the passwords
and keys should be
writable only by the
application.
10
https://www.linkedin.com/in/hariprasaanth/
3.12 Use Utilize authentication When accessing external
authentication for connections to systems with sensitive data,
for external systems ensure that authentication is
connections to involving sensitive required to establish secure
external information or connections.
systems functions.
11
https://www.linkedin.com/in/hariprasaanth/
3.17 Enforce Enforce password Passwords should meet
password length requirements length requirements, which
length based on policy or may include a minimum
requirements regulations to ensure length of eight characters or
stronger passwords. more.
12
https://www.linkedin.com/in/hariprasaanth/
3.23 Set short Temporary passwords Temporary passwords should
expiration and links should have a only be valid for a short
times for short expiration time to period, such as 24 hours.
temporary reduce the risk of
passwords unauthorized access if
they are compromised.
13
https://www.linkedin.com/in/hariprasaanth/
3.28 Enforce Implement a policy Passwords should be
periodic requiring periodic changed at regular intervals
password password changes, with as specified by the policy.
changes the time between
resets being
administratively
controlled.
3.30 Report last Notify users of the last Users should be aware of the
account successful or last login attempts to detect
activity to unsuccessful login any suspicious activity.
users attempt to keep them
informed about
account activity.
14
https://www.linkedin.com/in/hariprasaanth/
3.33 Re-authenticat Require users to Users should re-enter their
e users before re-authenticate before credentials before
critical performing critical performing critical
operations operations, adding an operations like changing
extra layer of security account settings.
for sensitive actions.
15
https://www.linkedin.com/in/hariprasaanth/
4. Session Management
"Session Management" is all about ensuring secure and well-controlled user sessions
within your application. It involves practices like using trusted session management
controls, setting appropriate timeout periods, disallowing concurrent logins, and
protecting session data from unauthorized access. The primary goal is to safeguard
user sessions from common threats like session hijacking or Cross-Site Request
Forgery (CSRF) by implementing robust session management practices. These
practices help maintain the integrity and security of user sessions while allowing for
smooth and secure interactions with your application.
4.2 Create Session Generate session When a user logs in, the
Identifiers on a identifiers (like cookies) server generates a unique
Trusted System on the server to session ID and sends it to
prevent tampering. the user's browser.
16
https://www.linkedin.com/in/hariprasaanth/
4.5 Properly Ensure that the logout When a user clicks "Logout,"
Terminate function fully their session is invalidated,
Sessions on terminates the user's and they are redirected to
Logout session or connection. the login page.
4.9 Close Old If a user had a session When a user logs in, their
Session on before login, close that previous session becomes
Login session and create a invalid.
new one after
successful login.
17
https://www.linkedin.com/in/hariprasaanth/
4.12 Hide Session Do not expose session Avoid displaying session IDs
Identifiers identifiers in URLs, in the URL like
error messages, or logs. "example.com?session=123."
Store them securely in
the HTTP cookie
header.
18
https://www.linkedin.com/in/hariprasaanth/
4.17 Use Strong For highly sensitive or When processing a financial
Tokens for critical operations, use transaction, generate a
Critical per-request, rather unique token for each step
Operations than per-session, of the transaction.
strong random tokens
or parameters.
4.19 Use HttpOnly Set cookies with the Use HttpOnly to prevent
for Cookies HttpOnly attribute client-side scripts from
unless you specifically accessing cookies
need client-side scripts containing sensitive session
to read or set a cookie's information.
value.
19
https://www.linkedin.com/in/hariprasaanth/
5. Access Control
"Access Control" is about ensuring that only authorized users can access specific parts
of your application. This section includes practices such as using trusted system
objects for authorization decisions, enforcing access controls on every request,
segregating privileged logic, and restricting access to files, resources, URLs, functions,
and data. The primary goal is to prevent unauthorized access to sensitive areas of your
application and data by implementing strong access control practices. These practices
help protect your application from security threats, ensuring that users can only access
what they are allowed to and that sensitive information remains secure.
20
https://www.linkedin.com/in/hariprasaanth/
5.4 Deny all access if Deny all access if If the application is unable to
security the application access its security
configuration cannot access its configuration, it should
information is security default to denying access.
unavailable configuration
information,
ensuring that
security settings are
enforced even when
configuration data is
inaccessible.
21
https://www.linkedin.com/in/hariprasaanth/
5.8 Restrict access to Ensure that access Users should be required to
protected URLs to to protected URLs is authenticate before
authorized users restricted to only accessing protected URLs.
authorized users.
22
https://www.linkedin.com/in/hariprasaanth/
5.15 Ensure consistency Ensure that Access control rules should
between server-side be consistent between
server-side access implementation server-side implementation
control rules and presentation and the presentation layer.
layer
representations of
access control rules
match.
5.16 Use encryption If state data must be State data stored on the
and integrity stored on the client, client side should be
checking for use encryption and encrypted and protected to
client-stored state integrity checking prevent unauthorized
data on the server side to modifications.
prevent tampering.
5.18 Limit the number Limit the number of Implement transaction limits
of transactions per transactions a single to prevent abuse by
user or device user or device can automated systems or
perform within a malicious users.
given period to
deter automated
attacks.
5.19 Use the "referer" Use the "referer" The "referer" header can be
header as a header as a used as an additional
supplemental supplemental security measure but should
check check, but not as not be the only means of
the sole authorization.
authorization check,
as it can be spoofed.
23
https://www.linkedin.com/in/hariprasaanth/
5.20 Periodically If long Users with long sessions
re-validate user authenticated should have their
authorization sessions are allowed, authorization periodically
periodically re-validated to ensure that
re-validate a user's their privileges have not
authorization to changed.
ensure their
privileges have not
changed. Log the
user out and force
re-authentication if
necessary.
24
https://www.linkedin.com/in/hariprasaanth/
5.23 Assign least Service accounts or Service accounts should
privilege to service accounts used for have only the permissions
accounts connections to required for their specific
external systems tasks.
should have the
least privilege
necessary.
25
https://www.linkedin.com/in/hariprasaanth/
6. Cryptographic Practices
26
https://www.linkedin.com/in/hariprasaanth/
6.4 Use approved All random To create unpredictable
random number numbers, random values, use approved
generators for file names, random cryptographic random
un-guessable GUIDs, and random number generators rather
values strings should be than relying on standard
generated using the random functions.
cryptographic
module's approved
random number
generator when
these random
values are intended
to be un-guessable.
6.6 Implement key Establish and utilize Clearly defined policies and
management a policy and process processes for managing
policies and for how cryptographic keys should
processes cryptographic keys be in place to ensure their
will be managed to proper use and security.
maintain the
security and
integrity of
cryptographic
operations.
27
https://www.linkedin.com/in/hariprasaanth/
7. Error Handling and Logging
"Error Handling and Logging" is essential for maintaining the security and integrity of
your application. This section includes practices like not revealing sensitive information
in error responses, implementing custom error pages, and securely handling errors, as
well as logging important security events and failures. The primary goal is to enhance
application security by carefully managing how errors are handled and logged. Proper
error handling helps prevent attackers from exploiting vulnerabilities and allows you to
monitor and analyze security events effectively to detect and respond to potential
threats.
7.2 Use error handlers Error handlers Avoid showing stack trace
that do not display should be information in error
debugging or configured not to messages, as it can provide
stack trace reveal debugging or insights into the
information stack trace application's internal
information to workings.
potential attackers.
28
https://www.linkedin.com/in/hariprasaanth/
7.4 Handle application The application Implement custom error
errors without should handle its handling logic within the
relying on server errors application to manage and
configuration independently respond to errors effectively.
without relying
solely on server
configuration.
7.7 Implement All logging controls Ensure that log entries are
logging controls should be generated and stored on a
on a trusted implemented on a secure and trusted system to
system trusted system, such prevent tampering or
as the server. unauthorized access.
29
https://www.linkedin.com/in/hariprasaanth/
7.9 Ensure logs Log entries should Include relevant information
contain important contain essential such as timestamps, user
log event data event data to help in identities, and event
diagnosing and descriptions in log entries.
understanding
security incidents.
7.10 Prevent log entries Ensure that log Implement proper encoding
with un-trusted entries containing or escaping to prevent log
data from untrusted data entries with user input from
executing as code cannot execute as being interpreted as
code in log viewing executable code.
interfaces or
software.
30
https://www.linkedin.com/in/hariprasaanth/
7.14 Ensure Implement Use log analysis tools and
mechanisms exist mechanisms to processes to regularly review
for log analysis conduct log analysis and monitor log entries for
and monitoring of security events.
security events to
detect anomalies or
potential threats.
7.15 Log all input Record log entries Capture instances where
validation failures for input validation input data fails validation
failures to track and checks, which may indicate
investigate potential security vulnerabilities.
security issues.
7.17 Log all access Record log entries Document cases where
control failures for access control access control mechanisms
failures to monitor fail to prevent unauthorized
and address access or actions.
unauthorized access
incidents.
7.18 Log all apparent Log events that Monitor and log suspicious
tampering events, indicate potential events, like unauthorized
including tampering or changes to data or
unexpected unexpected configuration settings.
changes to state changes to the
data application's state
data.
31
https://www.linkedin.com/in/hariprasaanth/
7.19 Log attempts to Record log entries Capture and investigate any
connect with for attempts to attempts to use session
invalid or expired connect with invalid tokens that are no longer
session tokens or expired session valid or have been tampered
tokens to detect with.
potential
session-related
security threats.
7.20 Log all system Record log entries Capture and investigate
exceptions for system system exceptions that may
exceptions to indicate problems within the
identify and application.
troubleshoot
potential issues.
7.22 Log backend TLS Record log entries Monitor and log any failures
connection failures for backend TLS in secure connections
(Transport Layer between components of the
Security) connection application.
failures to detect
potential security
issues with secure
communication.
32
https://www.linkedin.com/in/hariprasaanth/
7.24 Use cryptographic Employ Use hash functions to create
hash functions to cryptographic hash checksums of log entries
validate log entry functions to verify and validate their integrity
integrity the integrity of log during log analysis.
entries and detect
tampering.
33
https://www.linkedin.com/in/hariprasaanth/
8. Data Protection
"Data Protection" is crucial for securing sensitive information within your application.
This section involves practices like implementing the principle of least privilege,
encrypting sensitive data, protecting cached or temporary files, and safeguarding
server-side source code. The primary goal is to ensure the confidentiality and integrity
of data, preventing unauthorized access or data leaks. Effective data protection
practices, like encryption and access controls, help keep sensitive information safe
from threats and unauthorized disclosure, ultimately enhancing the security of your
application.
34
https://www.linkedin.com/in/hariprasaanth/
8.4 Protect server-side Ensure that Use appropriate access
source code from server-side source controls and server
being downloaded code is protected configurations to prevent
by a user from being users from accessing
downloaded by server-side source code.
users.
35
https://www.linkedin.com/in/hariprasaanth/
8.8 Do not include Avoid sending Instead of sending sensitive
sensitive sensitive data as parameters in a URL,
information in information in HTTP use HTTP POST requests or
HTTP GET request GET request other secure methods.
parameters parameters as it
may be exposed in
URLs or logs.
36
https://www.linkedin.com/in/hariprasaanth/
8.12 Implement access Ensure that Implement access controls
controls for sensitive data stored to restrict access to cached
sensitive data on the server, data and temporary files to
stored on the including cached only specific system users or
server, including data and temporary roles.
cached data, files, is protected by
temporary files, appropriate access
and data controls.
accessible only by
specific users
37
https://www.linkedin.com/in/hariprasaanth/
9. Communication Security
38
https://www.linkedin.com/in/hariprasaanth/
9.3 Prevent failed TLS Ensure that when a If a client fails to establish a
connections from TLS connection fails, TLS connection, it should not
falling back to an it does not fall back proceed with an
insecure to an insecure or unencrypted connection but
connection unencrypted should display an error
connection, which message instead.
could expose
sensitive data.
9.4 Use TLS Utilize TLS (or its When users access their
connections for all equivalent) for email accounts, the
content requiring securing connection should use TLS to
authenticated connections to any protect the login credentials
access and other content that and email contents from
sensitive requires interception.
information authenticated
access or any other
sensitive
information.
39
https://www.linkedin.com/in/hariprasaanth/
9.7 Specify character Specify character When transmitting data
encodings for all encodings for all between a web server and a
connections data transmitted database, specify UTF-8
over connections to character encoding to ensure
avoid character compatibility and prevent
encoding issues encoding-related
that can lead to vulnerabilities.
security
vulnerabilities.
40
https://www.linkedin.com/in/hariprasaanth/
10. System Configuration
10.3 Turn off directory Disable directory When a web server receives a
listings listings to prevent request for a directory that
exposing sensitive doesn't contain a default
information about document (e.g., index.html),
the web server's it should return a "403
directory structure Forbidden" error instead of
to potential listing the directory's
attackers. contents.
41
https://www.linkedin.com/in/hariprasaanth/
10.4 Restrict the web Limit the A web server process should
server, process, permissions and run with minimal privileges,
and service access rights of web granting access only to the
accounts to the server, process, and directories and resources
least privileges service accounts to required for serving web
possible only what is pages, and should not have
necessary to write access to sensitive files.
perform their
functions, reducing
the risk of
unauthorized
access.
10.7 Remove test code Ensure that test Any test-related functionality
or any code or features not in the application's codebase
functionality not intended for should be excluded from the
intended for production use are production release,
production, prior removed from the preventing unintended
to deployment application before it exposure or vulnerabilities.
is deployed.
42
https://www.linkedin.com/in/hariprasaanth/
10.8 Prevent disclosure Avoid exposing If a website has directories
of your directory directory structures containing configuration files
structure in the by isolating or other sensitive data, these
robots.txt file directories not directories should be placed
intended for public within a parent directory that
indexing in an is disallowed in the robots.txt
isolated parent file to prevent search engine
directory and indexing.
disallowing the
entire parent
directory in the
robots.txt file.
43
https://www.linkedin.com/in/hariprasaanth/
10.11 Ensure the web Ensure that the web If a web server accepts both
server handles server is configured HTTP 1.0 and HTTP 1.1
HTTP 1.0 and 1.1 in to handle both requests, it should process
a similar manner HTTP 1.0 and 1.1 them in a consistent manner
or understands consistently or to prevent potential
any differences understands any vulnerabilities related to
distinctions version handling.
between the two
versions.
44
https://www.linkedin.com/in/hariprasaanth/
10.14 Implement an Establish an asset An organization should use
asset management an asset management
management system to catalog system to keep an inventory
system and and register all of all servers, network
register system system components devices, software, and
components and and software to hardware components used
software monitor and in the infrastructure.
maintain them
efficiently.
45
https://www.linkedin.com/in/hariprasaanth/
11. Database Security
"Database Security" is essential for ensuring the confidentiality and integrity of your
application's data. This section includes practices like using strongly typed
parameterized queries, input validation, and output encoding to prevent SQL injection
attacks. It also emphasizes the importance of utilizing secure credentials for database
access, storing connection strings securely, and minimizing privileges when interacting
with the database. The primary goal is to protect your database from unauthorized
access and data breaches, ensuring that sensitive information remains secure and
confidential. Effective database security practices help safeguard your application's
most critical asset – its data.
46
https://www.linkedin.com/in/hariprasaanth/
11.3 Ensure that Ensure that When passing variables to a
variables are variables used in database query, ensure that
strongly typed database operations their data types match the
are strongly typed expected data types in the
to prevent database schema to avoid
type-related type conversion issues or
vulnerabilities. unexpected behavior.
47
https://www.linkedin.com/in/hariprasaanth/
11.6 Connection strings Avoid hardcoding Instead of directly
should not be hard database embedding database
coded within the connection strings connection strings in the
application. in the application code, store them in an
Connection strings code. Store encrypted configuration file
should be stored in connection strings external to the application
a separate in a separate, for better security.
configuration file encrypted
on a trusted configuration file on
system and they a trusted system.
should be
encrypted.
48
https://www.linkedin.com/in/hariprasaanth/
11.9 Remove or change Eliminate or update When deploying a new
all default default database, change the default
database administrative administrative passwords to
administrative passwords for the strong, unique passwords, or
passwords. Utilize database, replacing implement multi-factor
strong them with strong authentication to enhance
passwords/phrases passwords or access security.
or implement implementing
multi-factor multi-factor
authentication authentication for
added security.
49
https://www.linkedin.com/in/hariprasaanth/
11.12 Disable any default Deactivate or If the database system
accounts that are disable any default includes default user
not required to user accounts that accounts that are not
support business are not needed to essential for the application's
requirements fulfill business functionality, disable or
requirements. remove them to reduce
potential security risks.
50
https://www.linkedin.com/in/hariprasaanth/
12. File Management
"File Management" is all about handling files securely within your application. This
section includes practices like not passing user-supplied data directly to dynamic
include functions, authenticating file uploads, validating file types, and avoiding saving
files in the same web context as the application. The primary goal is to prevent
malicious file uploads, limit access to files, and ensure that files are handled safely to
avoid security vulnerabilities. Effective file management practices help maintain the
integrity and security of your application's file system and protect it from potential
threats.
12.1 Do not pass user Avoid directly Instead of using user input
supplied data passing to dynamically include a file,
directly to any user-supplied data use a predefined and
dynamic include to dynamic include validated list of files to
function functions to prevent include.
code execution
vulnerabilities.
12.3 Limit the type of Allow only specific If your application only
files that can be types of files to be requires image uploads,
uploaded to only uploaded that are restrict file uploads to image
those types that relevant to the file types (e.g., JPEG, PNG)
are needed for application's and reject other file types.
business purposes business
requirements.
51
https://www.linkedin.com/in/hariprasaanth/
12.4 Validate uploaded Verify the file type of When processing an
files are the uploaded files by uploaded file, check its
expected type by examining their header information to
checking file headers to ensure confirm its actual format
headers. Checking they match the rather than solely relying on
for file type by expected format, as the file extension provided
extension alone is relying solely on file by the user.
not sufficient extensions is
insufficient.
12.5 Do not save files in Store uploaded files Store uploaded files in a
the same web in a location directory outside the web
context as the separate from the server's root directory to
application. Files web application's prevent direct access from
should either go to context to avoid the web.
the content server security risks.
or in the database. Uploaded files
should be placed in
a content server or
database.
52
https://www.linkedin.com/in/hariprasaanth/
12.8 Implement safe Secure file When dealing with file
uploading in UNIX uploading in UNIX uploads on UNIX systems,
by mounting the environments by ensure that the uploaded
targeted file mounting the files are placed in an isolated
directory as a target directory as a directory or chroot
logical drive using logical drive or environment to enhance
the associated using the chrooted security.
path or the environment to
chrooted isolate the uploaded
environment files.
53
https://www.linkedin.com/in/hariprasaanth/
12.11 Do not pass Avoid passing When handling user input
directory or file directory or file for file or directory paths, use
paths, use index paths as user input, predefined index values to
values mapped to and instead, use reference specific paths
pre-defined list of index values rather than directly
paths associated with a accepting arbitrary paths
predefined list of provided by users.
paths to enhance
security.
12.12 Never send the Avoid disclosing When returning file paths or
absolute file path absolute file paths URLs to the client, ensure
to the client to clients, as this that they are relative paths
information can and do not reveal the
potentially be absolute file system
exploited by structure of the server.
attackers.
54
https://www.linkedin.com/in/hariprasaanth/
13. Memory Management
13.1 Utilize input and Employ input and When accepting user input,
output control for output controls to apply input controls such as
un-trusted data manage data from input validation to validate
untrusted sources, and sanitize the data before
ensuring that the using it in the application.
data is processed Similarly, use output controls
safely and securely. like output encoding to
prevent data from being
executed as code when
displayed to users.
13.2 Double check that Verify that buffer When using functions that
the buffer is as sizes match the copy data into a buffer,
large as specified expected size to double-check that the
prevent buffer destination buffer is of the
overflows and specified size and that it can
memory corruption accommodate the data to
vulnerabilities. be copied.
55
https://www.linkedin.com/in/hariprasaanth/
13.3 When using Exercise caution When using strncpy(), be
functions that when using aware of its behavior and
accept a number functions like make sure to manually
of bytes to copy, strncpy() and NULL-terminate the string if
such as strncpy(), understand that if necessary to avoid issues
be aware that if the destination with string manipulation.
the destination buffer size is the
buffer size is equal same as the source
to the source buffer size, the string
buffer size, it may may not be
not NULL-terminated,
NULL-terminate which can lead to
the string unexpected
behavior.
13.5 Truncate all input Limit the length of Before using copy or
strings to a input strings to a concatenation functions,
reasonable length reasonable size truncate input strings to a
before passing before using copy predefined reasonable
them to the copy and concatenation length to ensure they fit
and concatenation functions to prevent within the buffer's allocated
functions buffer overflows. space.
56
https://www.linkedin.com/in/hariprasaanth/
13.7 Use Employ If your operating system or
non-executable non-executable platform supports
stacks when stacks when non-executable stacks,
available possible to enhance enable this feature to reduce
security and prevent the risk of stack-based buffer
stack-based overflow attacks.
vulnerabilities.
13.8 Avoid the use of Steer clear of using Instead of using functions
known vulnerable functions that are like printf, strcat, or strcpy,
functions (e.g., known to be opt for safer alternatives that
printf, strcat, strcpy vulnerable to do not exhibit known
etc.) security issues, such vulnerabilities, such as
as printf, strcat, and printf-safe functions or string
strcpy. manipulation functions with
boundary checks.
57
https://www.linkedin.com/in/hariprasaanth/
14. General Coding Practices
"General Coding Practices" encompass a set of guidelines for writing secure and
reliable code. These practices encourage the use of approved managed code,
task-specific APIs, and explicit variable initialization. They also emphasize avoiding
direct interaction with the operating system and preventing concurrent access issues
in multi-threaded applications. Additionally, the checklist promotes safe calculation
handling, secure privilege management, and safeguarding against code injection and
unsafe code alterations. Following these practices helps ensure that your code is
robust, secure, and free from common vulnerabilities.
58
https://www.linkedin.com/in/hariprasaanth/
14.3 Use checksums or Verify the integrity Before loading a dynamically
hashes to verify of interpreted code, linked library, verify its
the integrity of libraries, integrity by comparing its
interpreted code, executables, and hash value with a
libraries, configuration files precomputed hash to ensure
executables, and using checksums or it has not been tampered
configuration files cryptographic with.
hashes to detect
unauthorized
modifications.
59
https://www.linkedin.com/in/hariprasaanth/
14.6 Explicitly initialize Ensure that all Initialize variables with
all your variables variables and data appropriate default values
and other data stores are explicitly during declaration or
stores, either initialized either initialize them just before
during during declaration their first use. For instance,
declaration or just or right before their initialize an integer variable
before the first first usage to with zero (0) to avoid using
usage prevent the use of uninitialized data.
uninitialized or
unpredictable
values.
60
https://www.linkedin.com/in/hariprasaanth/
14.8 Avoid calculation Prevent calculation When performing
errors by errors by having a mathematical calculations in
understanding deep a programming language, be
your understanding of aware of issues like integer
programming your programming overflow, floating-point
language's language's numeric precision, and type
underlying representation and conversion. Always ensure
representation how it handles that numeric operations are
and how it various numeric consistent with your
interacts with operations and data expectations and the
numeric types. Pay attention language's behavior.
calculation. Pay to issues like
close attention to precision,
byte size signed/unsigned
discrepancies, distinctions, byte
precision, size limitations, type
signed/unsigned conversion, and
distinctions, handling extreme
truncation, values.
conversion and
casting between
types,
"not-a-number"
calculations, and
how your
language handles
numbers that are
too large or too
small for its
underlying
representation
14.9 Do not pass Avoid passing data Do not allow users to provide
user-supplied provided by users to input that is directly passed
data to any functions that to functions capable of
dynamic dynamically execute executing code dynamically,
execution code, as this can such as eval() or dynamic
function lead to code SQL execution. This can
injection prevent code injection
vulnerabilities. attacks.
61
https://www.linkedin.com/in/hariprasaanth/
14.10 Restrict users Prevent users from Avoid providing users with
from generating generating or the capability to write or
new code or modifying code to execute arbitrary code within
altering existing maintain control the application, as this can
code over the lead to security risks.
application's
behavior and
security.
62
https://www.linkedin.com/in/hariprasaanth/
14.12 Implement safe Implement secure When delivering automatic
updating. If the update updates for your application,
application will mechanisms, ensure that the updates are
utilize automatic especially if your digitally signed with a
updates, then use application cryptographic signature to
cryptographic supports automatic guarantee their authenticity.
signatures for updates. Utilize The download client should
your code and cryptographic verify these signatures before
ensure your signatures to verify applying updates. Encrypt
download clients code authenticity, the communication channel
verify those and ensure between the host server and
signatures. Use download clients the client to protect the code
encrypted validate these updates from interception.
channels to signatures.
transfer the code Additionally, use
from the host encrypted channels
server to transfer code
updates from the
host server.
63
https://www.linkedin.com/in/hariprasaanth/
15. Glossary
★ Access Control: A set of controls that grant or deny a user, or other entity, access
to a system resource. This is usually based on hierarchical roles and individual
privileges within a role, but also includes system to system interactions.
★ Authentication: A set of controls that are used to verify the identity of a user, or
other entity, interacting with the software.
★ Data Protection: A set of controls that help ensure the software handles the
storing of information in a secure manner.
★ Database Security: A set of controls that ensure that software interacts with a
database in a secure manner and that the database is configured securely.
64
https://www.linkedin.com/in/hariprasaanth/
★ Error Handling and Logging: A set of practices that ensure the application
handles errors safely and conducts proper event logging.
★ File Management: A set of controls that cover the interaction between the code
and other system files.
★ General Coding Practices: A set of controls that cover coding practices that do
not fit easily into other categories.
★ HTML Entity Encode: The process of replacing certain ASCII characters with their
HTML entity equivalents. For example, encoding would replace the less-than
character "<" with the HTML equivalent "<". HTML entities are 'inert' in most
interpreters, especially browsers, which can mitigate certain client-side attacks.
★ Impact: A measure of the negative effect on the business that results from the
occurrence of an undesired event; what would be the result of a vulnerability
being exploited.
★ Input Validation: A set of controls that verify the properties of all input data
match what is expected by the application, including types, lengths, ranges,
acceptable character sets, and does not include known hazardous characters.
★ Integrity: The assurance that information is accurate, complete, and valid and
has not been altered by an unauthorized action.
65
https://www.linkedin.com/in/hariprasaanth/
★ Log Event Data: This should include the following:
★ Memory Management: A set of controls that address memory and buffer usage.
★ Mitigate: Steps taken to reduce the severity of a vulnerability. These can include
removing a vulnerability, making a vulnerability more difficult to exploit, or
reducing the negative impact of a successful exploitation.
★ Sanitize Data: The process of making potentially harmful data safe through the
use of data removal, replacement, encoding, or escaping of the characters.
★ State Data: When data or parameters are used by the application or server to
emulate a persistent connection or track a client's status across a multi-request
process or transaction.
66
https://www.linkedin.com/in/hariprasaanth/
★ System: A generic term covering the operating systems, web server, application
frameworks, and related infrastructure.
★ Threat Agent: Any entity that may have a negative impact on the system. This
may be a malicious user who wants to compromise the system's security
controls; however, it could also be an accidental misuse of the system or a more
physical threat like fire or flood.
67
https://www.linkedin.com/in/hariprasaanth/