CSRF (Cross-Site Request Forgery) là tấn công khiến trình duyệt nạn nhân gửi request đến server thay mặt họ.
Rails bảo vệ bằng cách nhúng authenticity token (random string unique per session) vào mọi form. Controller kiểm tra token trước mọi non-GET request:
ruby
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception # default
endRequest từ site khác không có token → ActionController::InvalidAuthenticityToken (403).
API mode: ActionController::API không include CSRF protection (stateless API dùng JWT/token thay thế, không dùng session cookie).