Dojo Security Advisory

G

Garrett Smith

Security Advisory to any Dojo users:

| If you have Dojo 0.4 through Dojo 1.4 installed on your site, you are
| strongly encouraged to read all of this message and take immediate
| action.
<URL: http://dojotoolkit.org/blog/post/dylan/2010/03/dojo-security-advisory/
You may need to increase the font size or change the styles so the text
is darker. The site uses text color #555, with 12px fixed font-size on
white background. Depending on the user's vision and monitor's
device-to-pixel ratio, that may be unreadable (it was for me).
 
D

David Mark

Garrett said:
Security Advisory to any Dojo users:

| If you have Dojo 0.4 through Dojo 1.4 installed on your site, you are
| strongly encouraged to read all of this message and take immediate
| action.
<URL:
http://dojotoolkit.org/blog/post/dylan/2010/03/dojo-security-advisory/

And the immediate action should be to delete Dojo. They clearly have
such an over-complicated mess that anything can happen. Told you so! :)
You may need to increase the font size or change the styles so the text
is darker. The site uses text color #555, with 12px fixed font-size on
white background.

Of course. Also is one of those idiotic layouts that is falling off the
left side of the window (no left margin) unless you happen to have your
screen resolution set to something greater than or equal to the
developers' setting. They only go by what they can observe. I've told
them about this before and they quizzed me about my settings and
concluded they were "wrong". :)
Depending on the user's vision and monitor's
device-to-pixel ratio, that may be unreadable (it was for me).

Yes, it is the typical "designer" blundering that is so commonplace on
the Web.
 
D

David Mark

Michael said:
JSONP is a security issue as well, and yet I don't see Dojo or others
abandoning that idea...

They are clearly in way over their heads. I read their recommendations
and guarantee a nightmare for the typical Dojo user. Copy over this,
copy over that, use the files from the build closest to your version
(LOL) and (of course) re-build everything (and pray that there isn't
some obscure incompatibility introduced). Oh, and if you are using
patched files, you are basically screwed.

Die Dojo die (please). :)
 
M

Michael Haufe (\TNO\)

Security Advisory to any Dojo users:

| If you have Dojo 0.4 through Dojo 1.4 installed on your site, you are
| strongly encouraged to read all of this message and take immediate
| action.
<URL:http://dojotoolkit.org/blog/post/dylan/2010/03/dojo-security-advisory/
 >

You may need to increase the font size or change the styles so the text
is darker. The site uses text color #555, with 12px fixed font-size on
white background. Depending on the user's vision and monitor's
device-to-pixel ratio, that may be unreadable (it was for me).

JSONP is a security issue as well, and yet I don't see Dojo or others
abandoning that idea...
 
R

Richard Cornford

JSONP is a security issue as well, and yet I don't see Dojo or
others abandoning that idea...

JSONP is not a security issue in itself. It is a point where a poor
implementation may introduce a security vulnerability, but properly
handled (suitably escaped[1] so that no data can become executable
code, not treating any data that does arrive as defining executable
code, and not making the mistake of thinking that javascript object
literals are JSON, rather than the restricted sub-set of object
literals that are (a very common misconception)) there should be no
risk.

Of course there is the general risk of importing any javascript source
(which then includes JSON and JSONP) from any third party. With an
internal source it is possible to have (at least some) confidence in
the integrity of the source, but from a third party it would be
difficult to guarantee anything of the sort.

So, suppose you employ script library 'x' served through the servers
of provider 'y', it is possible for provider 'y' (or a dishonest/
disgruntled employee of provider 'y') to selectively (say based on the
Referer being of a location where credit card details were entered,
and only in say, 1 in 100 requests to reduce the chances of such an
action being noticed) inset some additional code into the libralry 'x'
source that monitored key presses and broadcast their values and
sequence to some other third party server.

Confidence in such a library distribution provider might be better if
they guaranteed the integrity of what they were doing (and had some
sort of reputation to stand by, as guarantees in isolation are as
reliable as a Chinese spammer's shoe retail business). Unfortunately
most 'terms of service' pretty much say everything is at your own risk
and nothing is guaranteed.

Richard.

[1] If the JSONP is to be inserted directly in to HTML mark-up,
between SCRIPT tags, then in addition to the usual javascript
escapeing (line terminators, backslashes, etc.) forward slashes
also need to be 'escaped' so that data that contains
"</script><script>" cannot terminate the current script element
prematurely and commence another that will execute global code.
Thus it is safer for JSON encoding to escape the forward slash
regardless of the context in which its output is being used,
as that may change.
 
D

David Mark

Richard said:
JSONP is a security issue as well, and yet I don't see Dojo or
others abandoning that idea...

JSONP is not a security issue in itself. It is a point where a poor
implementation may introduce a security vulnerability, but properly
handled (suitably escaped[1] so that no data can become executable
code, not treating any data that does arrive as defining executable
code, and not making the mistake of thinking that javascript object
literals are JSON, rather than the restricted sub-set of object
literals that are (a very common misconception)) there should be no
risk.

And given the slap-dash nature of Dojo (and similar) projects, I think
it is a fair bet that most fall into the poor implementation category.
The Dojo code is full of comments that appear to be written by children
(e.g. "IE sux bad"). Doesn't inspire confidence that responsible
professionals are monitoring the effort. They seem to be willing to
dump any submission into the mix with only the feeble scrutiny of the
other participants. It is hard to imagine how companies get talked into
putting trust in something like that.

And I wonder if there will be a similar advisory for Closure, which
(despite the claims of its authors) is basically a moldy slab of old
Dojo with some additional cheese on top.
 
D

David Mark

David said:
Richard said:
On Mar 12, 1:47 am, Garrett Smith wrote:
Security Advisory to any Dojo users:
| If you have Dojo 0.4 through Dojo 1.4 installed on your site, you
| are strongly encouraged to read all of this message and take
|immediate action.
<URL:
http://dojotoolkit.org/blog/post/dylan/2010/03/dojo-security-advisory/
You may need to increase the font size or change the styles so the
text is darker. The site uses text color #555, with 12px fixed
font-size on white background. Depending on the user's vision and
monitor's device-to-pixel ratio, that may be unreadable (it was
for me).
JSONP is a security issue as well, and yet I don't see Dojo or
others abandoning that idea...
JSONP is not a security issue in itself. It is a point where a poor
implementation may introduce a security vulnerability, but properly
handled (suitably escaped[1] so that no data can become executable
code, not treating any data that does arrive as defining executable
code, and not making the mistake of thinking that javascript object
literals are JSON, rather than the restricted sub-set of object
literals that are (a very common misconception)) there should be no
risk.

And given the slap-dash nature of Dojo (and similar) projects, I think
it is a fair bet that most fall into the poor implementation category.
The Dojo code is full of comments that appear to be written by children
(e.g. "IE sux bad"). Doesn't inspire confidence that responsible
professionals are monitoring the effort. They seem to be willing to
dump any submission into the mix with only the feeble scrutiny of the
other participants. It is hard to imagine how companies get talked into
putting trust in something like that.

Here is the bug report:-

http://bugs.dojotoolkit.org/ticket/10773

It seems that it took six years (and outside intervention) to determine
that it is a stupid idea to do something like this:-

window.dojoUrl = "../../dojo/dojo.js";
window.testUrl = "";
window.testModule = "";

// parse out our test URL and our Dojo URL from the query string
var qstr = window.location.search.substr(1);

So this "qstr" variable could hold _any_ string. And why are they using
the non-standard substr method rather than substring?

https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/String/substr

"ECMA Version: None, although ECMA-262 ed. 3 has a non-normative section
suggesting uniform semantics for substr"

if(qstr.length){
var qparts = qstr.split("&");
for(var x=0; x<qparts.length; x++){
var tp = qparts[x].split("=");
if(tp[0] == "dojoUrl"){
window.dojoUrl = tp[1];
}

Do not augment host objects.

[...]

Here is one of the vulnerabilities. Clearly the "dojoUrl" is built from
the potentially malicious string (qstr).

document.write("<scr"+"ipt type='text/javascript' djConfig='isDebug:
true' src='"+dojoUrl+"'></scr"+"ipt>");

Never mind the clueless use of unnecessary concatenation or the
non-standard attribute, but they've dumped a URI without encoding it.
Having been through much of the Dojo code, I can confirm that multiple
rookie gaffes per line is the norm. As there are hundreds of files with
hundreds of lines each, it stands to reason that this thing should be
avoided like the plague. After all, it's not like they are splitting
atoms here.

And at the top of this file is an example of their comments, which often
indicate confusion as well as outright admissions of failure (e.g.
"don't work in Opera"):-

<!--
NOTE: we are INTENTIONALLY in quirks mode. It makes it much easier to
get a "full screen" UI w/ straightforward CSS.
-->

In what universe?

It is useful to note that this is not "IBM's toolkit" (a common
misconception). At least as much as the much-ballyhooed (and
ever-changing) widgets go, it's largely the work of "bill" and a few
similarly clueless cronies (and virtually nobody does any significant
work on the core, which they see as "solid"). I remember bumping into
this guy in the trac when he noticed how much I had changed in my branch
and warned me that he wouldn't accept any of the changes unless I could
demonstrate that they worked in "all browsers" on "all platforms". This
is ironic coming from a guy who uses more UA sniffs per function than
I've ever seen (and that's saying something). I remember others voiced
the same concern, but couldn't grasp that their code would never run in
"all browsers". It's all about what they can see and feel (in the
latest versions of a handful of browsers) and don't talk to them about
abstractions as it seems to induce headaches (judging from the typically
bitchy responses I got when pointing out outrageous gaps in their logic).

It's such a bizarre contradiction as this same guy chastised a bug
reporter for complaining that their app fell apart in IE8, pointing out
that the version of Dojo used did not claim to "support" IE8 (of course
not, IE8 wasn't available for marathon observation sessions when the
older version of Dojo was cobbled together). It's the same thing with
all of the five or so browsers they profess to "care" about (meaning the
ones they've peered at endlessly to determine how their code can appear
to "work" with them). If you used Dojo 1.3, your app has some shot of
"working" in IE7, Safari 3 and Opera 9, but if you use Dojo 1.4, it is
unlikely to stand up to the latter two (so tell all of your visitors to
hurry up and download Safari 4 or Opera 10). And if your visitors may
be using IE8, then _you_ better hurry up and upgrade to Dojo 1.4. Round
and round it goes and yet the Dojo developers are still oblivious to
their own insanity (what they call "pragmatism").

Regarding this ridiculous (and painfully obvious) security problem,
which apparently dates back six years, "bill" had this (very typical)
response:-

"Thanks for the reminder about encodeURIComponent(). I think for DOH
runner we'd need to use encodeURI() rather than encodeURIComponent(), to
let the "/" characters through."

Why did he need a reminder about encodeURIComponent in 2010? He goes on
to argue:-

"Like I said above, I don't think any of these values would legitimately
contain special characters, because these values are used to construct
file paths, and also because a theme name with (for example) a ">"
character would terribly break CSS selectors."

Legitimately? And as for passing "theme" names, to the present they
have exactly two of those, which makes me wonder why they bothered with
them at all. Both are full of CSS parse hacks and redundancies (theme
name repeated endlessly in each file) as well as classes named after
browsers (which are added by more browser sniffing). And while they are
busy adding more (so as to "compete" with other bloated and ill-advised
frameworks like YUI and ExtJS), nobody has been paying attention to the
swiss cheese-like code that implements them.

JFTR, you don't need theming for Web widgets. They very idea is silly
as it implies you would use the same source for every widget (in this
case the source is "bill"). If an enterprise is naive enough to use
some of his inaccessible form control replacements, does that mean they
should also use his crappy editor, popup menus, etc.?

They seem to have a hard time justifying these "themes" (or are they
skins?) in their own Wikipedia entry:-

http://en.wikipedia.org/wiki/Dojo_toolkit

"Skins can be used such as tundra, soria, and others in order to change
the look and feel of dijit.Editor along with all other Dojo elements
that are used within the same page."

Yep, "tundra" and "soria" are the two. I've never seen any others.

"Other online rich-text editor programs such as TinyMCE use independent
skinning which can be a disadvantage in comparison to a unified approach."

So the "reasoning" seems to be that you will have to actually create CSS
to make one widget look like another and it would be a be sounder
strategy to leave CSS to people who demonstrate no proficiency at all in
its creation and, as a side effect, be stuck with widgets implemented by
people who seemingly can't write a single line of Javascript without
committing numerous and obvious blunders.

But I digress. Here is one final related (and typically argumentative)
note from someone who is clearly unqualified to argue about browser
scripting:-

"So, one could argue that it's odd to call encodeUri...() on a value
that should never need encoding. But it could be argued either way, it's
a philosophical thing."

JFTR, I think this bunch (they all sound the same) would have made a
pretty lousy philosophers as well. :)
 
T

Thomas 'PointedEars' Lahn

David said:
[...]
// parse out our test URL and our Dojo URL from the query string
var qstr = window.location.search.substr(1);
[...]
if(qstr.length){
var qparts = qstr.split("&");
for(var x=0; x<qparts.length; x++){
var tp = qparts[x].split("=");
if(tp[0] == "dojoUrl"){
window.dojoUrl = tp[1];
}

Do not augment host objects.

[...]

Here is one of the vulnerabilities. Clearly the "dojoUrl" is built from
the potentially malicious string (qstr).

document.write("<scr"+"ipt type='text/javascript' djConfig='isDebug:
true' src='"+dojoUrl+"'></scr"+"ipt>");

Never mind the clueless use of unnecessary concatenation or the
non-standard attribute, but they've dumped a URI without encoding it.

Yes, it needs to be

encodeURI(decodeURIComponent(dojoUrl)).replace(/&/g, "&amp;")

here.


PointedEars
 
G

Garrett Smith

Richard said:
JSONP is a security issue as well, and yet I don't see Dojo or
others abandoning that idea...

JSONP is not a security issue in itself. It is a point where a poor
implementation may introduce a security vulnerability, but properly
handled (suitably escaped[1] so that no data can become executable
code, not treating any data that does arrive as defining executable
code, and not making the mistake of thinking that javascript object
literals are JSON, rather than the restricted sub-set of object
literals that are (a very common misconception)) there should be no
risk.

If an external script element is appended to the DOM then how would that
happen?
 
R

Richard Cornford

JSONP is not a security issue in itself. It is a point where a
poor implementation may introduce a security vulnerability, but
properly handled (suitably escaped[1] so that no data can become
executable code, not treating any data that does arrive as
defining executable code, and not making the mistake of thinking
that javascript object literals are JSON, rather than the
restricted sub-set of object literals that are (a very common
misconception)) there should be no risk.

If an external script element is appended to the DOM then how
would that happen?

How would what happen?

Richard.
 
G

Garrett Smith

Garrett said:
Richard said:
On Mar 12, 1:47 am, Garrett Smith wrote:
Security Advisory to any Dojo users:
| If you have Dojo 0.4 through Dojo 1.4 installed on your site, you
| are strongly encouraged to read all of this message and take
|immediate action.
<URL:
http://dojotoolkit.org/blog/post/dylan/2010/03/dojo-security-advisory/
You may need to increase the font size or change the styles so the
text is darker. The site uses text color #555, with 12px fixed
font-size on white background. Depending on the user's vision and
monitor's device-to-pixel ratio, that may be unreadable (it was
for me).
JSONP is a security issue as well, and yet I don't see Dojo or
others abandoning that idea...

JSONP is not a security issue in itself. It is a point where a poor
implementation may introduce a security vulnerability, but properly
handled (suitably escaped[1] so that no data can become executable
code, not treating any data that does arrive as defining executable
code, and not making the mistake of thinking that javascript object
literals are JSON, rather than the restricted sub-set of object
literals that are (a very common misconception)) there should be no
risk.

If an external script element is appended to the DOM then how would that
happen?
I should not have snipped the footnote, where you posed the problem:

| If the JSONP is to be inserted directly in to HTML mark-up,
| between SCRIPT tags, then in addition to the usual javascript
| escapeing (line terminators, backslashes, etc.) forward slashes
| also need to be 'escaped' so that data that contains
| "</script><script>" cannot terminate the current script element

My reaction to that, and the basis for my question, is that JSON-P
callbacks are performed by appending external script. That external
script contains a function call with one parameter. The function that it
calls is defined in the global object of the document that the script is
appended to. This is my understanding of what JSONP is.

1) Page defines callback function "finger", with 1 param.
2) Page requests userData.jsp?callback=finger
3) userData.js contains "finger({ length : 10 })"
4) Function finger, as defined on page is called with arg: {length : 10}

How does doing that create the problem you describe?
 
G

Garrett Smith

Michael said:
userData.js _hopefully_ contains 'finger({ "length" : 10 })'
That is a very good point. One of the problems with dynamic script
loading is that it expects nonstandard behavior.

The script may fail to load due to connection problem or server error.
In that case, there is no way for the code that appended it to cancel
the request.

In Opera, removing the script element, via removeChild, will cancel the
loading of if, if it has not yet loaded. This is also nonstandard and
other browsers don't do this either.
 
R

Richard Cornford

Garrett said:
Richard Cornford wrote:
JSONP is not a security issue in itself. It is a point where
a poor implementation may introduce a security vulnerability,
but properly handled (suitably escaped[1] so that no data can
become executable code, not treating any data that does
arrive as defining executable code, and not making the mistake
of thinking that javascript object literals are JSON, rather
than the restricted sub-set of object literals that are (a
very common misconception)) there should be no risk.
If an external script element is appended to the DOM then how
would that happen?

I should not have snipped the footnote, where you posed the
problem:

| If the JSONP is to be inserted directly in to HTML mark-up,

So the first condition is that an "external script element" is not
"appended to the DOM".
| between SCRIPT tags, then in addition to the usual javascript
| escapeing (line terminators, backslashes, etc.) forward slashes
| also need to be 'escaped' so that data that contains
| "</script><script>" cannot terminate the current script element

My reaction to that, and the basis for my question, is that
JSON-P callbacks are performed by appending external script.

That is certainly a common scenario for their usage.
That external script contains a function call with one
parameter. The function that it calls is defined in the
global object of the document that the script is
appended to. This is my understanding of what JSONP is.

How something may be used does not often constitute a definition of
what it is.
1) Page defines callback function "finger", with 1 param.
2) Page requests userData.jsp?callback=finger
3) userData.js contains "finger({ length : 10 })"
4) Function finger, as defined on page is called with arg: {length : 10}

How does doing that create the problem you describe?

It doesn't. The problem I described precludes that scenario at the
start of its opening sentence.

But consider the scenario you describe here; suppose the JSONP
resource existed so that could do some sort of database retrieval and
make the recovered data available externally to a web site (not an
uncommon use for JSONP). Now suppose that same web site wanted to use
the same data retrieval process internally in a dynamically generated
web page. Rather than re-write the process it may seem reasonable to
have the server-side code invoke the existing JSONP generating
resource and include its output directly in a SCRIPT element in the
dynamically generated HTML page. A that point you have introduced the
possibility of the character sequence "</script><script>" prematurely
terminating the first script element (with a probably non-fatal syntax
error), commencing a new one and having the browser execute a
following character sequined from what had been data as if it was
javascript source code.

Richard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,163
Latest member
Sasha15427
Top