-
-
Notifications
You must be signed in to change notification settings - Fork 16.2k
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
Should jsonify() throw an exception when provided a list? #1177
Comments
As I stated in above issue I'm all for removing this restriction - the browsers affected by the security bug are now really really old (IE5, firefox 2 etc.) and all have unfixed remote code execution bugs anyway. |
Using flask 0.10.1 I was able to raise the same
To add garbleing behavior of
only In the context of allowing top-level lists to |
If I submit a patch that removes this restriction and allows the developer to be productive by accepting lists, will it be accepted? |
@duaneking sure |
Actually, i need to expand on this and paddle back: as mentioned in #673, any patches for improving the error message are always welcomed and will be merged. I think we agreed in that issue that we should remove the restriction, however, since @mitsuhiko introduced that restriction, i think you should negotiate this with him if this is going to land in 1.0 |
Hah, actually this seems to be a duplicate of #248. |
Closing this in favor of #248, please continue discussion there. |
Consider
jsonify()
cation of a dictionary contained in a list:With the following output:
jsonify()
has -- without complaining -- mangled the data into something really not useful: The original dictionary values are gone, and the"b"
key suddenly is a value.I appreciate that top-level array elements are not allowed to be created in Flask's
jsonify()
implementation (http://flask.pocoo.org/docs/0.10/security/#json-security). Also, there are for sure straight-forward strategies for solving this in application code, for example by wrapping the list in a dictionary:jsonify({"items": collection})
.However, in the Python world we do not find it very often that an entity accepts invalid input and produces garbled output without complaining. Also, it looks like
jsonify()
once raised an exception when provided a list (at least in 2011 it did raise aTypeError
: #170).Should we raise an exception again or is the current behavior carefully designed with a focus on performance? I mean, it is unlikely that this data mangling ends up in a production environment (a developer really should realize that
jsonify()
produces garbage in this case , like I did).The text was updated successfully, but these errors were encountered: