How does the HTTP 'Referer' header help in defending against CSRF attacks?

The HTTP “Referer” header can be used as a defense against CSRF attacks by checking if the request originated from an authorized domain. When a user makes a request, the browser automatically includes the “Referer” header indicating the site that generated the request. The server-side application then verifies this header to ensure it matches the expected value. If there’s a mismatch, the request is rejected, preventing potential CSRF attacks. This method isn’t foolproof due to some browsers or proxies not sending the “Referer” header or users disabling it for privacy reasons. Therefore, it should be combined with other defenses like anti-CSRF tokens and SameSite cookies for robust protection.