Secure Coding For Devs 2022
Secure Coding For Devs 2022
2. Cryptographic Failures
Happens when sensitive data may get leaked. To prevent, identify data that is sensitive
(Personal Identifiable Information, Personal Health Information, Financial Information, Internal
business information) and try to collect as less data as possible (less data to encrypt, the better)
and try to discard data from persistent storage once work is finished.
Compliance Requirements:
Guidance and Standards like NIST and ISO can help get started. Check for Service Level
Agreements (SLAs) when working for others. Some industries like healthcare, finance and govt
have expectations and regulations, be sure to familiar beforehand. Geographical storage and
processing of data also matters due to regional laws (like GDPR or CCPA). Also check the user’s
data since they can be minors since some geographies legally don’t allow processing of this
data.
Coding tips:
Use authenticated encryption (encryption ensures confidentiality since data can only be read
with the decryption key, authenticated encryption ensures confidentiality and integrity since only
certain people can access the data)
Use cryptographically secure protocols (enforce encryption for browsers by forcing HTTPS and
using software libraries like OPEN SSL. To reduce risk of data leakage, disable caching of
sensitive data.
Document your selection of code libraries, encryption standards, padding methods and hashing
functions for the coding language you are using. Do not hardcode keys or passwords into
application code, instead generate cryptographically random keys and store them in memory as
byte arrays.
Remember to hash and salt user passwords.
3. Injection
Possible when there is improper validation, filtering or sanitisation of data entered by users
(attackers can insert malicious code). End users can be effected by loss of their sensitive data or
by XSS attack affecting other user’s machine. XSS can be Persistent XSS or Reflected XSS.
Persistent XSS is when malicious code is injected into the application database, and when victim
tries to use the app, the server will pull and run the malicious code ( eg: link to malicious website
to steal user cookies being posted as a comment on a web forum).
Reflected XSS starts with a HTTP request to an application including a malicious script which
will return and may successfully compromise a victim’s browser and in turn their machine. (eg:
attacker sends link to malicious script to user which may steal cookies).
Prevention techniques
Perform static, dynamic, and interactive app testing to identify possible issues before
development.
Search for any syntax which makes requests to interpreters in the environment and ensure input
validation is in place.
Check all places where input from an HTTP req could possibly make it’s way into any of these
calls.
Make considerations for special characters and try to escape special character input.
Incorporate limits on results to queries.
Log suspicious queries after deployment and review them consistently to identify attempted
exploits.
4. Insecure Design
Refers to many weaknesses related to 'missing or ineffective control design'.
To ensure secure design
The Secure Software Development Lifecycle (SSDLC) refers to putting an emphasis on security
during development. It creates a balance of security and coding best practices.
Develop use and misuse cases (Misuse cases are things we do not expect to happen).
When testing the app, UT’s and IT’s should reflect the threat we have developed.
Incorporate access controls based on anticipated attacks (eg: locking out and terminating
inactive sessions, limiting number of concurrent sessions, limiting results from queries, etc)
Limit the resource consumption from user which is more complex than a simple Denial of service.
Identify any design changes and document them since they can impact the security
requirements and decisions made previously.
Incorporate plausibility checks (sanity checks) into both the front-end and back-end to quickly
determine if values fall within expected ranges and variables into expected data types.
5. Security Misconfiguration
This can happen when out-of-the-box features are utilised which may overlook some
security problems. Examples: enabling unnecessary accounts/privileges, using default
passwords, error handling messages which provide information to users which can be used to
prepare for an attack).
Vulnerable and outdated software components may compromise security and constantly
reviewing and updating configurations to account for new components to be misconfigured
during the patch management process.
Additional protections:
Consistent configurations across development, QA and production.
Separate credentials for dev, QA and production must be used.
Minimise attack features by limiting features, components, documentation and frameworks to
only what is necessary.
Taking time to change default accounts and passwords.