The Security Checklist22 Jun 2016
This is a part of the Security Guide for Developers (in progress)
AUTHENTICATION SYSTEMS (Signup/Signin/2 Factor/Password reset)
- Use HTTPS everywhere.
- Store password hashes using
Bcryptwith a random
- Destroy the session identifier after
- Must have the
stateparameter in OAuth2
- No open redirects after successful login or in any other intermediate redirects.
- Set secure, httpOnly cookies.
- In Mobile
OTPbased mobile verification, do not send the OTP back in the response when
Resend OTPAPI is called.
- Limit attempts to
generate OTPAPIs for a particular user. Have an exponential backoff set or/and something like a captcha based challenge.
- Check for randomness of reset password token in the emailed link or SMS
- Set an expiration on the reset password token for a reasonable period.
- Expire the reset token after it has been successfully used.
- Destroy the logged in user’s session everywhere after successful reset of password.
USER DATA & AUTHORIZATION
- Any resource access like,
my historyshould check the logged in user’s ownership of the resource using session id.
- Serially iterable resource id should be avoided. Use
/user/37153/orders. This acts as a sanity check in case you forgot to check for authorization token.
Edit email/phone numberfeature should be accompanied by a verification email to the owner of the account.
- Any upload feature should sanitize the filename provided by the user. Also, for generally reasons apart from security, upload to something like S3 (and post-process using lambda) and not your own server capable of executing code.
Profile photo uploadfeature should sanitize all the
EXIFtags also if not required.
- For user ids and other ids, use RFC complaint
UUIDinstead of integers. You can find an implementation for this for your language on Github.
- JWT are awesome, use them if required for your single page app/APIs.
ANDRIOD / IOS APP
saltfrom payment gateways should not be hardcoded.
auth tokenfrom 3rd party SDK’s should not be hardcoded.
- API calls intended to be done
server to servershould not be done from the App.
- In Android, all the granted permissions should be carefully evaluated.
- Certificate pinning is highly recommended.
SECURITY HEADERS & CONFIGURATIONS
AddCSP header to mitigate XSS and data injection attacks. This is important.
AddCSRF header to prevent cross site request forgery.
AddHSTS header to prevent SSL stripping attack.
AddX-Frame-Options to protect against Clickjacking.
AddX-XSS-Protection header to mitigate XSS attacks.
UpdateDNS records to add SPF record to mitigate spam and phishing attacks.
Userandom CSRF tokens and expose buisness logic APIs as HTTP POST requests. Do not expose CSRF tokens over HTTP for example in a inital request upgrade phase.
Do not usecritical data or tokens in GET request parameters. Exposure of server logs or a machine/stack processing them would expose user data in turn.
SANITIZATION OF INPUT
Sanitizeall user inputs or any input parameters exposed to user to prevent XSS
Sanitizeall user inputs or any input parameters exposed to user to prevent SQL Injection
Sanitizeuser input if using it directly for functionalites like CSV import.
Sanitizeuser input for special cases like robots.txt as profile names in case you are using a url pattern like coolcorp.io/username.
Do nothand code or build JSON by string concatentation ever, no matter how small the object is. Use your langauge defined libraries or framework.
Sanitizeinputs that take some sort of URLs to prevent SSRF.
SanitizeOutputs before displaying to users.
- If you are small and inexperienced, evaluate using AWS elasticbeanstalk or a PaaS to run your code.
- Use a decent provisioning script to create VMs in the cloud.
- Check for machines with unwanted publicly
- Check for no/default passwords for
databasesespecially MongoDB & Redis. BTW MongoDB sucks, avoid it.
- Use SSH to access your machines, do not setup a password.
- Install updates timely to act upon zero day vulnerabilities like Heartbleed, Shellshock.
- Modify server config to use TLS 1.2 for HTTPS and disable all other schemes. (The tradeoff is good)
- Do not leave the DEBUG mode on. In some frameworks, DEBUG mode can give access full-fledged REPL or shells or expose critical data in error messages stacktraces.
- Be prepared for bad actors & DDOS - use Cloudflare
- Setup monitoring for your systems and log stuff (use Newrelic or something like that)
- If developing for enterprise customers, adhere to compliance requirements. If AWS S3, consider using the feature to encrypt data. If using AWS EC2, consider using the feature to use encrypted volumes (even boot volumes can be encypted now).
- Setup an email (e.g. [email protected]) and a page for security researchers to report vulnerabilities.
- Depending on what you are making, limit access to your user databases.
- Be polite to bug reporters.
- Have your code review done by a fellow developer from a secure coding perspective. (More eyes)
- In case of a hack or data breach, check previous logs for data access, ask people to change passwords. You might require an audit by external agencies depending on where you are incorporated.
- Setup Netflix Scumblr to hear about talks about your organization on social platforms and Google search.