Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Cakefest 2021 Workshop 1

Cakefest 2021 Workshop 1

We are going to play with useful CakePHP features for your existing projects:

* Middlewares
* Security
* Performance optimization & Caching
* Events

Jorge M. González Martín

October 07, 2021
Tweet

More Decks by Jorge M. González Martín

Other Decks in Programming

Transcript

  1. Workshop 1 • 3x2.5h sessions (this is the first one)

    • Slides and code • Code - https:/ /github.com/cakephp/cakefest2021/ (check branches) • Database - https:/ /bit.ly/3Ao1rO8 • Slides - https:/ /speakerdeck.com/steinkel/cakefest-2021-workshop-1
  2. About Jorge González @steinkelz • CakePHP Developer at CakeDC [email protected]

    https:/ /www.cakedc.com • Trainer at Cake Software Foundation https:/ /training.cakephp.org
  3. Setup dev environment • docker / docker-compose • PostgreSQL 13

    as a dependency • PHP stack as a dependency • git clone [email protected]:cakephp/cakefest2021.git • cd cakefest2021 • docker-compose up • ./dk.sh • Use ./initdb.sh from host to restore a dbdump 5
  4. Bots • All your public forms will be spammed •

    Honeypot • Google reCaptcha is another option… or both 10
  5. SQL Injection • A good old friend is worth a

    mention • ORM • Raw queries 11
  6. XSS Injection • First step to more dangerous attacks https:/

    /cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sh eet.html 12
  7. DDoS • Good choice for a poorly optimized stack •

    Do it yourself • OR Let others do if for you (Cloudflare, Akamai, Cloudfront and others) 13
  8. CSRF • They force you to do something while authenticated

    in another site • How it works? • Cookie AND hidden field in your generated form • Check on POST PUT PATCH DELETE 14
  9. Bottlenecks • How to detect bottlenecks in your application? •

    DIY • DebugKit • XDebug • Let others do it • Sentry, Newrelic, etc. 17
  10. Typical performance tips • Ensure your queries are fast •

    Check again your queries and 3rd party services, then continue with this list • Remove filesystem access • Logs • Session • Cache engines • Do not use sessions if they are not needed • Ensure your assets are optimized • Consider a cache layer... 20
  11. Cache & Invalidation • Invalidation is a hard problem, if

    the benefits are not clear, reconsider the cache layer • Be careful with hidden keys • Users::view cache • Users belongsToMany Groups • Naive invalidation strategy: ANY change done to Users, Groups, GroupsUsers, invalidate all • More complex strategy • Change in users > invalidate by key • Change in groups > invalidate all related users by key 21
  12. OPT: Full Cache • When you just want to cache

    all the things • Middleware based Full Cache example • Consider using varnish or similar alternatives instead • It could make sense when invalidation is time based 26
  13. Example • New Notifications plugin • Send a warning email

    notification to the administrator when a file is tagged as a "virus" 30