This article is part of the CakeDC Advent Calendar 2024 (December 20th 2024)
We all know the importance of security in our sites, so here we have 5 quick tips that can improve the security of your site quickly:
- Ensure all cookies are configured for security
- They say they are going away soon... but meanwhile... keep them secure. ALL the cookies produced in your site, unless you have very specific reasons, should be configured as Secure, HttpOnly, SameSite Strict. See https://book.cakephp.org/5/en/controllers/request-response.html#creating-cookies when creating cookies. Here's a code snippet for your session cookie:
- Audit your dependencies
- Both backend and frontend dependencies could be impacted by security issues. In the case of the backend, you can have a quick look by running
composer audit
. In case of issues, you'll see an output similar to:
- Both backend and frontend dependencies could be impacted by security issues. In the case of the backend, you can have a quick look by running
- Use CSRF
- CSRF attacks https://owasp.org/www-community/attacks/csrf can be mitigated by using the CakePHP CSRF Middleware. Check your code, usually
/src/Application.php
for the Middleware:
- CSRF attacks https://owasp.org/www-community/attacks/csrf can be mitigated by using the CakePHP CSRF Middleware. Check your code, usually
- Enforce HTTPS
- Ensure your live applications are enforcing HTTPS to prevent downgrading to HTTP. You can handle that in a number of ways, for example using your webserver configuration, or a Proxy. If you want to handle it via CakePHP builtins, add
- Implement security headers
- It's an additional layer of defense agains attacks, like XSS https://owasp.org/www-community/attacks/xss/ and others
This is just a quick example of 5 changes in code you could apply today to improve your CakePHP website security. Keep your projects safe!
This article is part of the CakeDC Advent Calendar 2024 (December 20th 2024)