Last active
September 23, 2016 13:49
-
-
Save shimarin/f8b2f1d429eacbad58b6cee2079fbd05 to your computer and use it in GitHub Desktop.
stateless csrf(via xhr) prevention
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (isset($_SERVER["HTTP_ORIGIN"])) { | |
| if (parse_url(explode(",",$_SERVER["HTTP_ORIGIN"])[0], PHP_URL_HOST) != $_SERVER["SERVER_NAME"]) { | |
| header("HTTP/1.1 403 Forbidden"); | |
| exit; | |
| } | |
| } | |
| // XHRで必ず呼ばれるはずのリクエストについてはコレも付ける | |
| if (!isset($_SERVER["HTTP_X_REQUESTED_WITH"]) || $_SERVER["HTTP_X_REQUESTED_WITH"] != "XMLHttpRequest") { | |
| header("HTTP/1.1 403 Forbidden"); | |
| exit; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| myModule.config(function($httpProvider) { | |
| $httpProvider.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment