Check list format that can be integrated into the software development lifecycle.
- Generally it is much cheaper to build secure software than fixing security issues.
- Security breaches can have much cost themselves (coding secure, is much better)
- From SANS 2009 Study:
- More than 60% of attacks on internet, are against web application
(application layer)
- More than 60% of attacks on internet, are against web application
- Developers team should assess their level of secure coding knowledge
- The goal of software security is to maintain the
confidentiality
,integrity
, andavailability
of information resources - Primary focus of this document is web application
Risk
is a combination of factors that threaten the success of the business- This can be described conceptually as follows: a
threat agent
interacts with asystem
, which may have avulnerability
that can beexploited
in order to cause animpact
. - Client-side controls are good, but not enough!
- Attackers can bypass client-side controls easily by proxies like Burp
- The security controls must be implemented in server-side
- Software vulnerabilities can have a scope beyond the software itself:
- Software and its information
- Operating System
- Backend Database
- Other APPs in a shared environment
- User's System
- Other Software that the user interacts with
- Perform Data Validation on
Server
- Classify data sources into
trusted
oruntrusted
:- validate the untrusted data sources
- There should be a centralized input validation routine for the app
- Specify proper character sets, such as UTF-8 for all sources
- Encode data to a common character set before validating
- All validation failure should result in input rejection
- Determine if the system supports UTF-8 and if so, validate after UTF-8 decoding is completed
- Validate client data before processing
- all parameters
- headers
- cookies
- values
- Verify that header values in both request and responses contain only ASCII characters
- Validate data before redirection
- Validate for expected data types
- Validate data range
- Validate data length
- Validate all input against a
white
list of allowed characters, whenever possible - If any
dangerous (Hazardous) character
must be allowed, extra controls like output encoding should be implemented. Examples of hazardous include:<
,>
"
,'
%
(
,)
&
\
,\'
,\"
- Extra checks:
- Null bytes:
%00
- New Line Characters:
%0d
,%0a
,\r
,\n
- Check for "dot-dot-slash" (
../
or..\
) - If UTF-8 extended character set encoding is supported:
- address alternate representation like:
%c0%ae%c0%ae/
- address alternate representation like:
- Null bytes:
- all encoding on a trusted system e.g.,
the Server
- Utilize a standard method for each type of output encoding
- Encode output
based on the context
it will be in. - Encode all characters unless they are known to be safe for the intended interpreter
- Sanitize output of un-trusted data to queries based on
context
e.g. SQL, XML, LDAP - Sanitize output of un-trusted data to
OS Commands
- Require Authentication for
all routes & resources
, except for those which intented to be public - All authentication controls must be enforced on a trusted system e.g.
Server
- Use and implement standard, tested auth services
- Use a
centralized implementation
for all auth controls, including libraries that call external auth services Separate
authentication logic and the resource being requested and use redirection to and from centralized auth control- All authentication controls should fail securely
- All administrative and account management functions must be at least as secure as the primary auth mechanism
- If application stores credential
- Ensure using only
cryptographically strong one-way salted
hashes of password - Password table and keys are
write-able
only by application Do not use MD5
- Ensure using only
- Password hashing must be implemented on a trusted system, e.g.
Server
- Validate authentication data only on completion of all data input
- Especially when the authentication mechanism is sequential (steps by steps, and order is important)
- Authentication failure process should not show which part was incorrect.
- Instead of 'invalid username' or 'invalid password', just show
Invalid username and/or password
- Errors must be identically in both
display and source code
- Instead of 'invalid username' or 'invalid password', just show
- Use authentication when using external systems, if they involve sensitive information
- Authentication credentials for accessing services should be stored in a protected location on a trusted system (e.g.
Server
)- Source code is not a secure location
- Use only HTTP POST Request to transit authentication credentials
- Only send non-temporary passwords over an encrypted connection or as encrypted data, such as in an encrypted email. Temporary passwords associated with email resets may be an exception
- Enforce password complexity requirements based on policy or regulations.
- Enforce password length requirements based on policy or regulations.
- Password entry should be hidden on the user's system
- Enforce account disabling after an established number of invalid login attempts
- account must be locked temporary
- but not so long to allow Denial of Service attack
- Password reset and changing operations require the same level of controls as account creation and authentication.
- Password reset questions should support sufficiently random answers. (e.g., "favorite book" is a bad question because “The Bible” is a very common answer)
- If using email based resets, only send email to a pre-registered address with a temporary link/password
- Temporary links and password should have short expiration time
- Enforce the changing of temporary passwords on the next use
Notify users when a password reset occurs
- Prevent password
re-use
- Passwords should be at least one day old before they can be changed, to prevent attacks on password re-use
- Enforce password changes based on requirements in a policy or regulations.
- Critical systems may require more frequent changes
- Disable
remember me
functionality for password fields - The last successful or unsuccessful of a user account should be reported to the user at the next successful login
- implement monitoring to identify attacks against multiple user accounts, using same password.
- Change all vendor-supplied default passwords and user IDs or disable associated accounts
- Re-authenticate users prior to performing critical operations
- e.g. get password before changing e-mail, password &...
- Use Multi-Factor Authentication for highly sensitive accounts
- If using third party code for authentication, inspect the code carefully to ensure it is not affected by any malicious code
- Use the server or framework's session management controls.
- Session identifier creation must always be done on a trusted system e.g.
Server
- Session management controls should use well vetted algorithms that ensure sufficiently random session identifiers
- Set the
domain
andpath
for cookies containing authenticated session identifiers to an appropriately restricted value for the site - Logout functionality should
fully
terminate the associated session or connection - Logout functionality should be available from
all pages protected by authorization
- Establish a session inactivity timeout that is a short as possible
- Balance
Risk
&Business Functional
requirement\ - In most cases, it should be
no more than several hours
- Balance
- Disallow persistent logins and enforce periodic session terminations, even when the session is active
- user should receive notification to mitigate negative impact
- If a session was established before login:
- close the session first
- then establish a new session
- Generate a new session ID on any re-authentication
- Do not allow concurrent logins with the same user ID
- Do not expose session IDs in
URLs
,error messages
orlogs
- session IDs should only be located in HTTP Cookie header.
- Do not pass it as a GET parameter
- Protect server side session data from unauthorized access:
appropriate access control on server
- Generate a new session ID and deactivate the old ones periodically:
avoid session hijacking
- generate new session ID if the connection changes from HTTP to HTTPS
- Supplement standard session management for sensitive server-side operations, like account management, by utilizing per-session strong random tokens or parameters. This method can be used to prevent Cross Site Request Forgery attacks
- Supplement standard session management for highly sensitive or critical operations by utilizing per-request, as opposed to per-session, strong random tokens or parameters
- Set the
secure
attribute for cookies transmitted ofr HTTPS - Set cookies with the
HttpOnly
attribute, unless you specifically require client-side access to cookie
- Use only trusted system objects, e.g. server side session objects, for making access authorization decisions
- Use a single site-wide component to check access authorization. This includes libraries that call external authorization services
- Access controls should fail securely
- Deny all access if the application cannot access its security configuration information
- Enforce authorization controls on every request, including those made by server side scripts, "includes" and requests from rich client-side technologies like AJAX and Flash
- Separate privileged logic from other application code
- Restrict access to
files
orother resources
, including thoseoutside
the application's direct control, to only authorized users - Restrict access to
protected URLs
to only authorized users - Restrict access to
protected functions
to only authorized users - Restrict
direct object references
to only authorized users - Restrict access to
services
to only authorized users - Restrict access to
application data
to only authorized users - Restrict access to
user and data attributes
andpolicy information
used by access controls - Restrict access security-relevant configuration information to only authorized users
- Server side implementation and presentation layer representations of access control rules must match
- If state data must be stored on the client, use
encryption
andintegrity
checking on it - Enforce application login flows to comply with business rules
- Limit the number of transactions a single user or device can perform in a given period of time
- Use the "referer" header as a
supplemental check
only, it should never be the sole authorization check, as it can be spoofed - If long authenticated sessions are allowed, periodically re-validate a user’s authorization to ensure that
their privileges have not changed
and if they have, log the user out and force them to re-authenticate - Implement account auditing and enforce disable of unused accounts
- e.g. After no more than 30 days from the expiration of an account’s password
- the application must support disabling of accounts and terminating sessions when authorization ceases
- Service accounts or accounts supporting connections to or from external systems should have the least privilege possible
- Create an Access Control Policy to document an application's business rules, data types and access authorization criteria and/or processes so that access can be properly provisioned and controlled. This includes identifying access requirements for both the data and system resources
- All cryptographic functions must be implemented on a trusted e.g.
server
- Protect master secrets from unauthorized access
- Cryptographic modules should fail securely
- All random numbers, random file names, random GUIDs, and random string should be generated using the cryptographic module's approved random number generator when these random values are intended to be un-guessable
- Cryptographic modules used by the application should be compliant to
FIPS 140-2
or an equivalent standard - Establish and utilize a policy and process for how cryptographic keys will be managed
- Do not disclose information in error messages, including system details, session identifiers or account information
- Use error handlers that do not display debugging or stack trace information
- Implement generic error messages and use custom error pages
- The application should handle application errors and not rely on server configuration
- Properly free allocated memory, when error conditions error
- Error handling logic associated with security controls should
deny access by default
- All logging controls should be implemented on a trusted system e.g.
server
- Logging controls should support both success and failure of specified security events
- Ensure logs contain important
log event data
- Ensure log entries that include un-trusted data will not execute as code in the intended log viewing interface or software
- Restrict access to logs to only authorized individuals
- Utilize a master routine for all logging operations
- Do not store sensitive information in logs, including
unnecessary system details
,session IDs
orpasswords
- Ensure that a mechanism exists to conduct log analysis
- Log all
input validation failures
- Log all authentication attempts,
especially failures
- Log all
access control failures
- Log all
tempering events
, including unexpected changes to state data - Log attempts to connect with
invalid
orexpired
session tokens - Log all
system exceptions
- Log all
administrative functions
, including changes to the security configuration settings - Log all
backend TLS connection failures
- Log
cryptographic module failures
- Use a cryptographic hash function to validate log entry integrity
- implement least privilege
- user must only access to things that really needs
- Protect all
cached
ortemporary
copies of sensitive data stored on the server from unauthorized access and purge those temporary working files as soon as they are no longer required - Encrypt highly
sensitive stored information
, like authentication verification data, even on the server side. Always use well vetted algorithms, see "Cryptographic Practices" for additional guidance - Protect server-side source code from being downloaded by a user
- Do not store
passwords
,connection strings
or othersensitive information
in clear text or in any non-cryptographically secure manner on the client side - Remove
comments
in user accessible production code that may reveal backend or other sensitive information - Remove unnecessary application and system documentation as this can reveal useful information to attackers
- Do not include sensitive information in
HTTP GET
request parameters - Disable
auto complete features
on forms expected to contain sensitive information - Disable
client side caching
on pages containing sensitive information.Cache-Control: no-store
, may be used in conjunction with the HTTP header controlPragma: no-cache
, which is less effective, but is HTTP/1.0 backward compatible - The application should
support the removal of sensitive data
when that data is no longer required - Implement appropriate access controls for sensitive data stored on the server. This includes cached data, temporary files and data that should be accessible only by specific system users
- Implement encryption for the
transmission
of all sensitive information - TLS certificates should be
valid
and have thecorrect domain name
,not be expired
, and beinstalled with intermediate certificates
when required - Failed TLS connections
should not fall back
to an insecure connection - Utilize TLS connections for all content requiring authenticated access and for all other sensitive information
- Utilize TLS for connections to external systems that involve sensitive information or functions
- Utilize a single standard TLS implementation that is configured appropriately
- Specify character encodings for all connections
- Filter parameters containing sensitive information from the
HTTP referer
, when linking to external sites
- Ensure servers, frameworks and system components are
running the latest version
- Ensure servers, frameworks and system components have
all patches issued
for the version in use - Turn off
directory listings
- Restrict the web server, process and service accounts to the
least privileges possible
- When exceptions occur, fail securely
- Remove all unnecessary functionality and files
- Remove test code or any functionality
not intended for production
, prior to deployment - Prevent disclosure of your directory structure in the
robots.txt
file by placing directories not intended for public indexing into an isolated parent directory. Then "Disallow" that entire parent directory in the robots.txt file rather than Disallowing each individual directory Define which HTTP methods
, GET or POST, the application will support and whether it will be handled differently in different pages in the application- Disable unnecessary HTTP methods, such as
WebDAV extensions
. If an extended HTTP method that supports file handling is required, utilize a well-vetted authentication mechanism - if the web server handles both
HTTP 1.0
and1.1
, ensure that both are configured in a similar way or ensure that you understand any difference that may exist (e.g. handling of extended HTTP methods) - Remove unnecessary information from HTTP response
headers
related to theOS
,web-server version
andapplication frameworks
- The security configuration store for the application should be able to be output in
human-readable
form to support auditing - Implement an
asset management
system and register system components and software in it - Isolate Production environment and Development environment (network)
- test or Development environments are often less secure
- test environment must be access only by authorized test groups
- Implement a
software change control system
to manage and record changes to the code both in development and production
- Use strongly
typed parameterized queries
- Utilize
input validation
andoutput encoding
and be sure to address meta characters. If these fail, do not run the database command - Ensure that variables are
strongly typed
- The application should use the
lowest
possible level of privilege when accessing the database - Use secure credentials for database access
- Connection strings
should not be hard coded within the application
. Connection strings should be stored in a separate configuration file on a trusted system, and they should beencrypted
. - Use stored procedures to abstract
data access
and allow for the removal of permissions to the base tables in the database Close the connection
as soon as possible- Remove or change all
default database administrative passwords
. Utilize strong passwords/phrases or implementmulti-factor authentication
- Turn off all
unnecessary database functionality
- (e.g., unnecessary stored procedures or services, utility packages, install only the minimum set of features and options required (surface area reduction))
- Remove unnecessary
default vendor content
(e.g., sample schemas) - Disable any
default accounts
that are not required to support business requirements - The application should connect to the database with
different credentials
for every trust distinction (e.g., user, read-only user, guest, administrators)
- Do not pass user supplied data
directly
to any dynamic include function - Require authentication
before allowing
a file to be uploaded - Limit the type of files that can be uploaded to
only those types
that are needed for business purposes - Validate uploaded files are the expected type by
checking file headers
. Checking for file type by extension alone is not sufficient - Do not save files in the
same web context
as the application. Files should either go to thecontent server
or in thedatabase
- Prevent or restrict the uploading of any file that
may be interpreted
by the web server - Turn off
execution privileges
on file upload directories - Implement safe uploading in UNIX by mounting the targeted file directory as a
logical drive
using the associated path or thechrooted environment
- When referencing existing files, use a
white list of allowed file names and types
. Validate the value of the parameter being passed and if it does not match one of the expected values, either reject it or use a hard coded default file value for the content instead - Do not pass
user supplied data
into adynamic redirect
. If this must be allowed, then the redirect should acceptonly validated
,relative path URLs
- Do not pass directory or file paths, use
index values mapped to pre-defined list of paths
- Never send the
absolute file path
to the client - Ensure application files and resources are
read-only
- Scan user uploaded files for
viruses and malware
- Utilize
input and output control
for un-trusted data - Double check that the
buffer is as large as specified
- When using functions that accept a number of bytes to copy, such as strncpy(),
be aware that if the destination buffer size is equal to the source buffer size
, it may not NULL-terminate the string Check buffer boundaries
if calling the functionin a loop
and make sure there is no danger of writing past the allocated space- Truncate all input strings to a
reasonable length
before passing them to thecopy and concatenation
functions - Specifically
close resources
, don’t rely on garbage collection. (e.g., connection objects, file handles, etc.) - Use
non-executable stacks
when available - Avoid the use of
known vulnerable functions
(e.g.,printf
,strcat
,strcpy
etc.) - Properly
free allocated memory
upon the completion of functions andat all exit points
- Use
tested and approved managed code
rather than creating new unmanaged code for common tasks - Utilize task specific built-in APIs to conduct operating system tasks
- Do not allow application to
directly execute OS commands
- Do not allow application to
- Use
checksums
orhashes
to verify the integrity ofinterpreted code
,libraries
,executables
, andconfiguration files
- Utilize
locking
to prevent multiple simultaneous requests or use a synchronization mechanism to prevent race conditions - Protect shared variables and resources from
inappropriate concurrent access
- Explicitly
initialize
all yourvariables
and otherdata stores
, either during declaration or just before the first usage - In cases where the application must run with elevated privileges,
raise privileges as late as possible
, and drop them as soon as possible - Avoid calculation errors by understanding your programming language's underlying representation and how it interacts with numeric calculation. Pay close attention to
byte size
discrepancies, precision, signed/unsigned distinctions, truncation, conversion and casting between types, "not-a-number" calculations, and how your language handles numbers that aretoo large
ortoo small
for its underlying representation - Do not pass user supplied data to any
dynamic execution function
- Restrict users from
generating new code
oraltering existing code
Review all secondary applications
,third party code
andlibraries
to determine business necessity and validate safe functionality- Implement safe updating
- if applications uses automate updating, implement ways to verify signature of updates
- Use encrypted channels to transfer the code from the host server