-
-
Save ivanionut/10fbb836fccdc47ecfff to your computer and use it in GitHub Desktop.
This ColdFusion UDF will query the server's request headers to determine if the request is an Ajax form post from jQuery. (jQuery adds a special header to all ajax requests.)
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
<cfscript> | |
function isAjaxRequestPost(){ | |
var headers = getHttpRequestData().headers; | |
return CGI.Request_Method is "POST" and StructKeyExists(headers, "X-Requested-With") AND (headers["X-Requested-With"] EQ "XMLHttpRequest"); | |
} | |
</cfscript> | |
<cfif not isAjaxRequestPost()> | |
<!--- log attempt, alert admin, etc ---> | |
<cfheader statuscode="403" statustext="Forbidden"> | |
<cfcontent type="text/html; charset=UTF-8"><cfoutput>Forbidden</cfoutput><cfabort> | |
</cfif> | |
<!--- perform database update, modify cookies, upload files, etc ---> | |
<cfcontent type="application/json; charset=UTF-8"><cfoutput>{"status":1}</cfoutput><cfabort> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment