Laravel Security Checklist
Laravel Security Checklist
Laravel Security Checklist
Security Checklist
INTRODUCTION
Damn, but security is hard.
It’s not always obvious what needs doing, and the payoffs of good security are at best
obscure. Who is surprised when it falls off our priority lists?
We’d like to offer a little help if you don’t mind. And by « help » we don’t mean « pitch
you our product »—we genuinely mean it.
Sqreen’s mission is to empower engineers to build secure web applications. Laravel already
comes with great out-of-the-box security features but it’s often not enough. We’ve put
our security knowledge to work in compiling an actionable list of best practices to help
you get a grip on your security priorities. It’s all on the following pages.
We hope you find it useful. If you do, share it with your network. And if you don’t, please
take to Twitter to complain loudly—it’s the best way to get our attention.
!1
CODE
✔ Use PHP 7!
Laravel 5.5 requires PHP 7 or above. PHP 7 includes a range of built-in security-specific
improvements (such as libsodium in PHP 7.2) and deprecates older, insecure features and
functionality. As a result, it is far easier to create more secure applications with PHP 7,
than any previous version of PHP. Use it whenever possible.
Read more:
• Deprecated features in PHP 7.0.x
• Deprecated features in PHP 7.1.x
• Deprecated features in PHP 7.2.x
• Deprecated features in PHP 7.3.x
• Migrating a PHP 5 App to PHP 7
Read more:
• Read about new Laravel CVEs
• Upgrade guides
• Shift
✔ Use a SAST
• A SAST is a Static Application Security Tester (or testing service). A SAST scans
source code looking for vulnerable code or potentially vulnerable code. Pre-
production tools come with a number of false positives and false negatives, but still
add some value.
!2
Read more:
• 11 Best PHP Code Security Scanners to Find Vulnerabilities
• SAST, DAST, and RASP: A guide to the new security alphabet soup
✔ Use a DAST
A DAST is a Dynamic Application Security Tester (or testing service). A DAST searches
for weaknesses and vulnerabilities in running applications. Pre-production tools come with
a number of false positives and false negatives, but still add some value.
Read more:
• Common Approaches to Automated Application Security Testing - SAST and
DAST
• Acunetix
!3
✔ Whitelist, Never Blacklist
Never attempt to filter out unacceptable input. Just filter for only what is acceptable. To
attempt to filter out anything that is unacceptable leads to unnecessarily complicated
code, which likely leads to defects and security flaws.
!4
• PHP 7.2: The First Programming Language to Add Modern Cryptography to its
Standard Library
• Libsodium
• Laravel Encryption
✔ Set open_basedir
The `open_basedir` directive limits the files that PHP can access to the filesystem from
the `open_basedir` directory and downward. No files or directories outside of that
directory can be accessed. That way, if malicious users attempt to access sensitive files,
such as `/etc/passwd`, access will be denied.
Read more:
• open_basedir configuration directive
• PHP Filesystem Security
• Isolated Execution Environments by DigitalOcean
!5
> By default, PHP will coerce values of the wrong type into the expected scalar type if
possible.
Use strict type checking to ensure that when comparing two items that they are of the
same type. And in PHP 7.1, use `declare (strict_types=1);`.
Read more:
• PHP 7 type hinting: inconsistencies and pitfalls
• PHP strict typing
✔ Use libxml_disable_entity_loader(true)
To avoid XML External Entity Injections, when working with XML content, use
`libxml_disable_entity_loader` to disable external entity resolution.
Read more:
• XML external entity attack
• XML External Entity (XXE) Prevention Cheat Sheet
• libxml_disable_entity_loader
• libxml
!6
✔ Integrate Security Scanners Into Your CI Pipeline
Security scanners can help to detect questionable code and code that contains obvious
security defects. Continuous Integration (CI) tools can use these scanners to test your
code and fail the build if the scanner meets or surpasses acceptable thresholds.
Read more:
• ircmaxell/php-security-scanner
• PHP Quality Assurance
!7
• Session fixation attack
• OWASP Session Management Cheat Sheet
!8
Read more:
• Best practice for caching sensitive data
!9
• AuditJS
!10
✔ Disable Unsafe and Unrequired Functionality
Some PHP installations can be preconfigured with unsafe and unrequired functionality
already enabled. Ensure that you review your PHP configuration and `phpinfo()` output
for any unsafe settings and disable or limit them.
Read more:
• OWASP PHP Configuration Cheat Sheet
!11
INFRASTRUCTURE
!12
• Free and Auto-Renewing SSL Certificates: Letsencrypt Quick Setup (2017
Edition)
!13
✔ Do Not Store Sensitive Data In Configuration Files
Just like you shouldn’t store sensitive data in cache entries, you also should not store
sensitive data in configuration files. This includes ssh keys, access credentials, and API
tokens. Store them in environment variables instead.
Read more:
• The Twelve-Factor App
• PHP dotenv
!14
PROTECTION
Read more:
• Content Security Policy (CSP) via MDN web docs
• Content Security Policy (CSP) via the Google Chrome extensions documentation
• CSP Evaluator
• Content Security Policy (CSP) Validator
• Easily add and manage a CSP with Sqreen
!15
Learn more:
• Sqreen
• Blocking Bruteforce attacks - OWASP
XXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXX
!16
www.sqreen.com