-
Notifications
You must be signed in to change notification settings - Fork 290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Klein's poor escaping helper can lead to vulnerabilities #148
Comments
One of Klein's main objectives thus far has been to have no dependencies, making it very portable (and less apt to clash with dep. versions). Including a dependency would be a major drawback in its current design. The escape method here is a simple "macro" if you will and is not a major part of the library. If your project/library needs a more advanced attribute escaper, I suggest adding the dependency to your own project. |
What if we we reimplement those 5 methods inside ServiceProvider ? Sticking to UTF-8 would really simplifies the code, that would weight less than 100 lines (mainly phpdoc). What do you think ? At the very least, the documention should state that $serviceProvider->escape() is limited and should only be used under strict conditions. |
I think it makes more sense to put some documentation mentioning its limited use case than to extend its abilities. In fact, I honestly was going to remove it from Klein 2, as its more of a utility method, but thought it didn't hurt to leave in. |
This is a proper replacement for the escape method()
I'm never with you about removing Klein built-in features (see #97). But it feels awkward to have escape() and not escapeAttribute(), nor escapeUrl(), those methods would really be handful for a framework providing Views and Partials. |
This should be considered fixed as of 3f13653 |
Currently Klein has a simple escape view helper:
It should be noted that this method should only be used to output html codes when the output is not inside a html attribute. It should never be used to output css or javascript code.
Zend Framework 2 has an Escaper module, that is still simple, and provides:
Zend_Escaper source code: https://github.com/zendframework/zf2/blob/master/library/Zend/Escaper/Escaper.php
The (really good) documentation has some simple examples that show the weakness of using a simple htmlentities() and other code-injection:
http://framework.zend.com/manual/2.2/en/modules/zend.escaper.theory-of-operation.html
Simple example adapted from the documentation:
I propose to include
Zend_Escaper
(New BSD License), it is small and have no dependency or to re-implement the methods in theServiceProvider
class.The escapeHtmlAttrs() is an absolute must I think.
The text was updated successfully, but these errors were encountered: