-
-
Save dwaltrip/fd5e7ef420c401851fd4 to your computer and use it in GitHub Desktop.
Using filters to automatically add a string to JSON responses in order to prevent certain type of XSS attack
This file contains 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
class ApplicationController < ActionController::Base | |
after_filter :protect_json | |
private | |
def protect_json | |
if response.content_type == "application/json" | |
response.body = ")]}',\n" + response.body | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment