Validate Origin Before Trusting Browser Requests
A web endpoint can receive a valid session cookie and still receive a request that the user did not intend to send. Browsers attach cookies according to cookie rules, not according to the intent of the page that caused a request. For sensitive state changes, that distinction matters. One useful defense is to check the request’s browser origin before accepting the action. An origin identifies the scheme, host, and port of the context that initiated a request. Comparing it with a small set of expected origins can reject requests arriving from browser contexts your application does not trust.