How can I validate/secure/authenticate a JavaScript-based POST request?

前端 未结 10 2077
孤独总比滥情好
孤独总比滥情好 2020-12-14 20:27

A product I\'m helping to develop will basically work like this:

  • A Web publisher creates a new page on their site that includes a
10条回答
  •  半阙折子戏
    2020-12-14 21:07

    First of all, I would validate the domain (and maybe the "server profile") as suggested by others here, and obviously very strictly validate the content of the POST (as I hope you're already doing anyway).

    If you make the URL for your script file point to something that's dynamically generated by your server, you can also include a time-sensitive session key to be sent along with the POST. This won't completely foil anyone, but if you're able to make the session expire quickly enough it will be a lot more difficult to exploit (and if I understand your application correctly, sessions should only need to last long enough for the user to enter something after loading a page).

    After typing this, I realize it's basically what avlesh already suggested with the addition of an expiry.

提交回复
热议问题