Re: [PHP-DEV] Proposed feature for json_encode()

2007-12-05 Thread Keryx Web
Rasmus Lerdorf skrev: It may not be the browser that misses the script tag. It may be the developer. To make things clear. My intention was not to question the value in escaping data or even to give an opinion whatsoever about Sara's patch. I was only replying to Alexey's notion that one

Re: [PHP-DEV] Proposed feature for json_encode()

2007-12-05 Thread Rasmus Lerdorf
Keryx Web wrote: Alexey Zakhlestin skrev: I think I understand what the use-case is… If the browser doesn't know anything about script tag, it is supposed to interpret it's contents as html… In which case, html-tags which appear in javascript code will actually become active ones And in

Re: [PHP-DEV] Proposed feature for json_encode()

2007-12-05 Thread Stanislav Malyshev
The second is the one I'm trying to address, wherein data that belongs in a JS parsing context may (coincidentally) contain HTML parsable data. For *whatever* reason, this data may accidently be echoed outside of a JS context, or a parsing/rendering error may lead to the browser switching

Re: [PHP-DEV] Proposed feature for json_encode()

2007-12-05 Thread Sara Golemon
payload to innerHTML, you are hosed. Using the \u syntax, even if you mess up and that blob of data finds its way to an innerHTML, nothing nasty can happen. Basically this is a more robust context-protected way I'm not sure this is correct - if you just write something like: script var =

Re: [PHP-DEV] Proposed feature for json_encode()

2007-12-05 Thread Markus Fischer
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi, Rasmus Lerdorf wrote: We should probably have done it this way right from the beginning, but since we didn't and since we don't really want to deal with the potential BC issues of changing working code, we have to add it as an option at this

Re: [PHP-DEV] Proposed feature for json_encode()

2007-12-05 Thread Stanislav Malyshev
payload to innerHTML, you are hosed. Using the \u syntax, even if you mess up and that blob of data finds its way to an innerHTML, nothing nasty can happen. Basically this is a more robust context-protected way I'm not sure this is correct - if you just write something like: script var =

Re: [PHP-DEV] Proposed feature for json_encode()

2007-12-04 Thread Alexey Zakhlestin
I think I understand what the use-case is… If the browser doesn't know anything about script tag, it is supposed to interpret it's contents as html… In which case, html-tags which appear in javascript code will actually become active ones The common practice for dealing with this problem is

Re: [PHP-DEV] Proposed feature for json_encode()

2007-12-04 Thread Stanislav Malyshev
I think I understand what the use-case is… If the browser doesn't know anything about script tag, it is supposed to interpret it's contents as html… In which case, html-tags which appear in javascript code will actually become active ones This makes sense. Though wouldn't

Re: [PHP-DEV] Proposed feature for json_encode()

2007-12-03 Thread Rasmus Lerdorf
Alexey Zakhlestin wrote: On 12/2/07, Rasmus Lerdorf [EMAIL PROTECTED] wrote: The \u syntax is specific to JSON, yes. \u syntax is specific to javascripts string literals, regular expressions and identifiers[1] And JSON is not the only way to deliver data into javascript. Manual approaches

Re: [PHP-DEV] Proposed feature for json_encode()

2007-12-03 Thread Stanislav Malyshev
Stuff like this often isn't completely deterministic. The attack vectors will move around and new ones will be discovered but since the syntax Sara is proposing is completely valid JSON it gives people another tool. Documenting specific attack vectors is useful too, of course, but a secondary

Re: [PHP-DEV] Proposed feature for json_encode()

2007-12-03 Thread Rasmus Lerdorf
Stanislav Malyshev wrote: Stuff like this often isn't completely deterministic. The attack vectors will move around and new ones will be discovered but since the syntax Sara is proposing is completely valid JSON it gives people another tool. Documenting specific attack vectors is useful too,

Re: [PHP-DEV] Proposed feature for json_encode()

2007-12-03 Thread Stanislav Malyshev
This is just a different way of encoding Javascript which depending on the context of use will enable Javascript to be embedded securely. Not providing an alternate encoding is a bit like arguing that we shouldn't have base64_encode() because if used incorrectly it could be insecure. I'm not

Re: [PHP-DEV] Proposed feature for json_encode()

2007-12-03 Thread Alan Knowles
One thing to consider is changing json_encode to add a header Content-type: application/json (or x-javascript), unless the additional arguments are used.. That way someone using the function to intermingle with HTML will be faced with the fact they have to encode the output, otherwise it breaks

Re: [PHP-DEV] Proposed feature for json_encode()

2007-12-03 Thread Edward Z. Yang
Alan Knowles wrote: One thing to consider is changing json_encode to add a header Content-type: application/json (or x-javascript), unless the additional arguments are used.. That way someone using the function to intermingle with HTML will be faced with the fact they have to encode the

Re: [PHP-DEV] Proposed feature for json_encode()

2007-12-03 Thread Sara Golemon
One thing to consider is changing json_encode to add a header Content-type: application/json (or x-javascript), unless the additional arguments are used.. That way someone using the function to intermingle with HTML will be faced with the fact they have to encode the output, otherwise it breaks

Re: [PHP-DEV] Proposed feature for json_encode()

2007-12-02 Thread Alexey Zakhlestin
On 12/2/07, Rasmus Lerdorf [EMAIL PROTECTED] wrote: The \u syntax is specific to JSON, yes. \u syntax is specific to javascripts string literals, regular expressions and identifiers[1] And JSON is not the only way to deliver data into javascript. Manual approaches are still useful [1] -

Re: [PHP-DEV] Proposed feature for json_encode()

2007-12-01 Thread Alexey Zakhlestin
Is such filtering specific to JSON? Does it have some use out of JSON-context? Maybe it would be better to provide a set of functions for encoding characters into '\u'-entities? (similiar to htmlentities, htmlspecialchars) because if we speak of 'theoretical' problem, we might end reimplementing

Re: [PHP-DEV] Proposed feature for json_encode()

2007-12-01 Thread Rasmus Lerdorf
Alexey Zakhlestin wrote: Is such filtering specific to JSON? Does it have some use out of JSON-context? Maybe it would be better to provide a set of functions for encoding characters into '\u'-entities? (similiar to htmlentities, htmlspecialchars) because if we speak of 'theoretical'

Re: [PHP-DEV] Proposed feature for json_encode()

2007-11-30 Thread Stanislav Malyshev
I can't because I don't know of any successful vectors *currently*. I also would have sworn that echoing htmlentified data was safeuntil I came across a browser where it wasn't. So that's what I wanted to understand, because if we add this feature, we should give some explanation on when

Re: [PHP-DEV] Proposed feature for json_encode()

2007-11-30 Thread Sara Golemon
Stanislav Malyshev wrote: You're absolutely correct that this won't save us from brain-dead engineers, what it will save us from is broken browsers which misinterpret otherwise legitimate data and get broken out of their proper context. (Yes, I've seen browsers do exactly this, and you can

Re: [PHP-DEV] Proposed feature for json_encode()

2007-11-30 Thread Rasmus Lerdorf
Stanislav Malyshev wrote: I can't because I don't know of any successful vectors *currently*. I also would have sworn that echoing htmlentified data was safeuntil I came across a browser where it wasn't. So that's what I wanted to understand, because if we add this feature, we should

[PHP-DEV] Proposed feature for json_encode()

2007-11-29 Thread Sara Golemon
While it's technically safe to include user supplied data in json_encode() serialized values. The fact that characters such as ' remain as is means there room for some as-yet unidentified problem either in the browser's rendering or (more likely) elsewhere in one's codebase for this data to

[PHP-DEV] Proposed feature for json_encode()

2007-11-29 Thread Sara Golemon
While it's technically safe to include user supplied data in json_encode() serialized values. The fact that characters such as ' remain as is means there room for some as-yet unidentified problem either in the browser's rendering or (more likely) elsewhere in one's codebase for this data to

[PHP-DEV] Proposed feature for json_encode()

2007-11-29 Thread Sara Golemon
While it's technically safe to include user supplied data in json_encode() serialized values. The fact that characters such as ' remain as is means there room for some as-yet unidentified problem either in the browser's rendering or (more likely) elsewhere in one's codebase for this data to

Re: [PHP-DEV] Proposed feature for json_encode()

2007-11-29 Thread Rasmus Lerdorf
Sara Golemon wrote: While it's technically safe to include user supplied data in json_encode() serialized values. The fact that characters such as ' remain as is means there room for some as-yet unidentified problem either in the browser's rendering or (more likely) elsewhere in one's

Re: [PHP-DEV] Proposed feature for json_encode()

2007-11-29 Thread Alexey Zakhlestin
is it really needed? str_replace can easily do that… it just looks like this unidentified problem is not specific to json On 11/29/07, Sara Golemon [EMAIL PROTECTED] wrote: While it's technically safe to include user supplied data in json_encode() serialized values. The fact that characters

Re: [PHP-DEV] Proposed feature for json_encode()

2007-11-29 Thread Sara Golemon
str_replace() *can* fix the problem, but when you have a series of nested arrays and objects, solving that problem with a separate loop becomes onerous. -Sara P.S. - Sorry about the tripple post before... Alexey Zakhlestin wrote: is it really needed? str_replace can easily do that… it just

Re: [PHP-DEV] Proposed feature for json_encode()

2007-11-29 Thread Stanislav Malyshev
To that end, the attached patch allows the caller to be paranoid about their data and stipulate that ' should be encoded to hex references instead. This doesn't stop a web developer from dropping that content into an innerHTML of course, but it's one more rope holding the ship together. Can

Re: [PHP-DEV] Proposed feature for json_encode()

2007-11-29 Thread Stanislav Malyshev
You're absolutely correct that this won't save us from brain-dead engineers, what it will save us from is broken browsers which misinterpret otherwise legitimate data and get broken out of their proper context. (Yes, I've seen browsers do exactly this, and you can probably guess which

Re: [PHP-DEV] Proposed feature for json_encode()

2007-11-29 Thread Xuefer
if we want to a onclick=process(?php echo json_encode($stringValue); ?) we should do echo htmlspecialchars(json_encode($stringValue)) instead actually, and yes JSON_HEX_TAG will help avoiding htmlspecialchars() just like urlencode()ed data which never contains or so. i'm not sure if there is