You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Utf8JsonWriter.WriteString do not honor escape=false #28567
When writing an unescaped value like "jwt+secevent", the Utf8JsonWriter is honoring the contract by not escaping the value, as illustrated in the following test:
WriteString(string propertyName, string value, bool escape) <= the escape bool only applies to the property name, not to the value.
The value is always escaped
Right. This is by design. Usually, property names are known/constant values, so the bool escape applies to the property name only, not to the value. We decided not to provide an additional bool escapeValue argument as it didn't seem useful for common uses and complicated the api surface.
It is inconsistent to always escape a value from a property, but not from an array.
That's a good point. I don't know if there is a strong use case for writing unescaped string arrays, so for consistency, we should consider removing the escape argument on WriteStringValue.
In addition, I do not understand the reason that the '+' is escaped. Same remark for '&', '<', '>' and '`'.
This characters are legit (I assume...)
These are common Html characters that need to be escaped since JSON can end up embedded within html web pages.
Right. This is by design. Usually, property names are known/constant values, so the bool escape applies to the property name only, not to the value. We decided not to provide an additional bool escapeValue argument as it didn't seem useful for common uses and complicated the api surface.
Can't we imagine a new property on the JsonWriterOptions like IgnoreValueEscaping ?
It won't change the surface API, and may provide more performance if the values are safe.
Nevertheless I'd rather prefer to have the control over each property. This would just add a bool to 9 methods:
These are common Html characters that need to be escaped since JSON can end up embedded within html web pages.
The security consideration is no clear to me. Utf8JsonWriter a low-level component. You cannot assume how is consumed the produced JSON. And escaping the JSON is not a very efficient way to protect against XSS.
And if I would like to escape, may be that HTML escaping is not enough. URL escaping, CSS escaping, JavaScript escaping, Attributes escaping....
IMHO, this JSON writer should only do JSON escaping as defined by the RFC.
Activity
ycrumeyrolle commentedon Jan 30, 2019
I haven't seen the comment:
/// The value is always escapedIt is inconsistent to always escape a value from a property, but not from an array.
ycrumeyrolle commentedon Jan 30, 2019
In addition, I do not understand the reason that the '+' is escaped. Same remark for '&', '<', '>' and '`'.
This characters are legit (I assume...)
ahsonkhan commentedon Feb 3, 2019
WriteString(string propertyName, string value, bool escape)<= the escape bool only applies to the property name, not to the value.Right. This is by design. Usually, property names are known/constant values, so the
bool escapeapplies to the property name only, not to the value. We decided not to provide an additionalbool escapeValueargument as it didn't seem useful for common uses and complicated the api surface.That's a good point. I don't know if there is a strong use case for writing unescaped string arrays, so for consistency, we should consider removing the escape argument on
WriteStringValue.These are common Html characters that need to be escaped since JSON can end up embedded within html web pages.
cc @GrabYourPitchforks
stephentoub commentedon Feb 4, 2019
Seems like the parameter should be renamed then to avoid any ambiguity? e.g. escape => escapeName
ycrumeyrolle commentedon Feb 5, 2019
Can't we imagine a new property on the
JsonWriterOptionslikeIgnoreValueEscaping?It won't change the surface API, and may provide more performance if the values are safe.
Nevertheless I'd rather prefer to have the control over each property. This would just add a bool to 9 methods:
The security consideration is no clear to me.
Utf8JsonWritera low-level component. You cannot assume how is consumed the produced JSON. And escaping the JSON is not a very efficient way to protect against XSS.And if I would like to escape, may be that HTML escaping is not enough. URL escaping, CSS escaping, JavaScript escaping, Attributes escaping....
IMHO, this JSON writer should only do JSON escaping as defined by the RFC.
ccnxpt commentedon Feb 10, 2019
I just tried Utf8JsonWriter.WriteString(name, value, false), then
Original value = "春夏秋冬" (12bytes)
Escaped value = "\u6625\u590f\u79cb\u51ac" (24bytes)
Is this by design? Too long and unreadable.
steveharter commentedon Jul 10, 2019
Closing this as https://github.com/dotnet/corefx/issues/37192 addresses this by passing a custom escaper to the writer.
taadis commentedon Sep 27, 2019
it work!!!