Anwar Chandra
Anwar Chandra

Reputation: 8638

How to make sure a POST is requested from specific domain?

Is there any property in HttpRequest that can make sure if the request is a POST request and it is coming from specific domain?

private bool IsRequestedFromDomain(string domain)
{
  // Request.Form is from domain ?
  return false;
}

Upvotes: 1

Views: 187

Answers (3)

nothrow
nothrow

Reputation: 16168

HTTP Referer, but it can be modified.

Only way how to be sure is to send some , randomly generated value to form, store it to session, and in IsRequestedFromDomain compare it.

Upvotes: 1

Wim
Wim

Reputation: 12082

Use:

Request.UrlReferrer, though it isn't reliable as it can be easily faked and may be changed by proxies.

Upvotes: 0

Rubens Farias
Rubens Farias

Reputation: 57946

Try to use

Request.ServerVariables["HTTP_REFERER"]

Note this header can be faked.

For a list of server variables, please take a look: ASP ServerVariables Collection

Upvotes: 1

Related Questions