I am not against removing this (I personally don’t have use for this anymore), but the reason behind the removal this seems unclear to me.
If it’s just “let’s remove this because no one uses this anymore” (and if that’s true), or “Rails want to discourage this type of architecture in favour of moving these type of processing to the client”, then fine. But I am not sure if I fully understand the security angle here.
Specifically, in Egor’s blog post:
- “Broken concept & architecture. This feels as weird as the client-side sending code that is going to be evaled on the server-side… wait… Rails programmers had similar thing for a while :/”
But in the context of a web application, by definition you are always sending JavaScript code from your server to be eval()-ed in the client (browser)
Whether the code is in /assets/javascript or in your controller, there’s really no difference here.
So I’ll have to assume you are talking about eval()-ing code that contains user-supplied data that’s bad. Which is fair enough, considering there’s usually a safer way to do this (encoding the user-supplied data as JSON first).
But as Andrew pointed out on the Github issue, there might be legitimate use cases for using this to return code that does NOT contain user-supplied data. I think those use cases needs to be understood properly (and we need to investigate/suggest alternatives for those cases) to ensure we are not removing a useful feature just because it’s subject to abuse.
- **"**Escaping user content and putting it into Javascript can be more painful and having more pitfalls then normal HTML escaping. … There can be more special characters and XSS you should care about."
Is this not already adequately addressed by the escaping helpers Rails provide? If so, regardless of whether we remove the js responder, those issues should be reported and fixed in Rails itself. I just opened https://github.com/rails/rails/pull/13073 yesterday to patch json_escape to make it useful again (please provide feedback), and I plan to submit another PR to improve the docs on escape_javascript to make the intended use cases more clear.
If it is already possible to correctly escape input for use in the JS responder, just that it’s difficult to do it correctly, the problem might not lie in the JS responder pre-se and we should take this opportunity to address them.
- “JSONP-like data leaking. If app accepts GET request and responds with Javascript containing private data in it attacker can use fake JS functions to leak data from the response.”
I assume you are talking about CSRF attacks where a page on a third-party domain can make requests to your site on your user’s behalf. But like you said, this problem also exists in JSONP. In fact, it’s probably much easier to exploit this in JSONP (because you can control the name of the callback) than a JS response that updates a certain part of the page. So I’m not sure if this is really JS responder’s fault. And like Andrew said, in his use case there’s nothing to leak.
Maybe I am not understanding this point correctly. If you can provide some examples based on the apps you see in the field it will be very helpful.
- “UPD as pointed out on HN evaling response will mess with your global namespace and there is no way to jump into closure you created request in…”
(I suppose this is not related to security.)
If you are doing a lot you should definitely architect your client-side JavaScript properly, that I agree 100% (I mainly write full-blown single page apps these day for my day job, so believe me when I say we are in agreement :). But in cases where you are delivering a small, simple payload to update a small part of the page, I don’t know if that’s super evil and should be strongly discouraged.
I don’t do this, so I’m not really in a good position to defend it. Again, maybe it’s just a case of “no one uses this anymore so it’s not worth supporting”, and that’s fine by me. But you brought up security, so I want to make sure we address your concerns properly.
Godfrey