0

I developed an application in ASP.NET MVC. This app has an action that returns a JsonResult and I get it with jquery in client side. Everything works fine but I'd like to know, if is there any way to make a security in this action to return only requests that came from my website.

Is there any way to avoid others websites to request this action? Or avoid javascript in address bar (script injection) ?

Thanks

1
  • Could you more describe your environment. You wrote about 1) ASP.NET MVC application 2) your website 3) other websites and clients. Is the ASP.NET MVC application a part of your website or at least run on the same webserver or the same server? Is all work in the intranet with active directory or on the internet? Do you have and use any certificates of the client or server side? Commented Oct 26, 2010 at 12:12

4 Answers 4

1

Short answer: No

Long answer: The only way to know that a request is legitimate is to interpret what's coming with the request. There's no magic in the http protocol. Probably, the most reliable way is to check the referrer and ensure that it's your site. But it's not hard to fool that check..

Sign up to request clarification or add additional context in comments.

Comments

0

I have not tried this yet but have been thinking about how I might achieve this as well. My current thoughts are to add a custom attribute to the action that checks a token appended to the cal by the requesting application.

The token would be generated by the calling application based on a seed key that was provided to the requester upon applying to use the API. The custom attribute would authenticate the key before the action ran either allowing or denying the call.

As I said not fully formed yet but was thinking along these lines ... good luck and if you come up with something make sure you post back.

Comments

0

For other sites:

  • You can check the referrer, but that can be spoofed.
  • You can check to see if you have an active session with the user.

For the address bar:

  • There is nothing you can really do about that.

1 Comment

Hello Epascarello, to est the active session, How could I do it in MVC? Need I start an session to get a SessionID and pass it as a parameter? Thanks
0

Others Websites can't make requests to your action using ajax because HTTP doesn't allow it, but it can still get called from the address bar, other program or anything.

If you whant to allow calls to your action only from specific parts of your website you can use the the html helper AntiForgeryToken and the attribute [ValidateAntiForgeryToken], you can check a tutorial about this over here: http://haacked.com/archive/2009/04/02/anatomy-of-csrf-attack.aspx. It's pretty much the idea abarr posted.

1 Comment

Yes man, but this action only aceppts GET. I can't to get it with post because I need performace.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.