Cookie dan sesi untuk htmx

high5 titik pemeriksaan

Cookie sesi adalah kunci akun. Atribut yang hilang mengubah satu celah XSS menjadi pengambilalihan akun penuh.

Yang harus ada di htmx

  • Atribut Secure pada setiap cookie
  • HttpOnly pada cookie sesi
  • SameSite=Lax atau Strict pada cookie sesi
  • Tidak ada ID sesi di URL atau localStorage
  • Rotasi sesi setelah login dan invalidasi saat logout

Cara memperbaiki

  1. 1Set atribut cookie di level framework agar semua cookie mewarisinya
  2. 2Pindahkan token dari localStorage ke cookie HttpOnly

Konteks htmx

HTML-over-the-wire library that swaps fragments returned by the server.

Server responses become DOM: sanitise HTML fragments and require CSRF tokens on every hx-post.