Javascript Obfuscator

M

Martin Mücke

Hi,

I am looking for a good javascript obfuscator - I found several on the
web, but I am looking for one that can also handle javascript in jsp,
html and java files - so I need a javascript obfuscator that handles
my entire web project.

Is there anything like that, preferable as a Eclipse plugin?

Thanks,

Martin
 
P

Peter Michaux

Hi,

I am looking for a good javascript obfuscator - I found several on the
web, but I am looking for one that can also handle javascript in jsp,
html and java files - so I need a javascript obfuscator that handles
my entire web project.

Is there anything like that, preferable as a Eclipse plugin?

If you are a Java type then I think the new YUI Compressor is likely
the best option for you as a starting point. I think you'll will have
to write the plugin part that strips and replaces code from the JSP,
HTML and Java files. That or you could just make sure that all your
JavaScript lives in pure JavaScript files that are dynamically added
to other files. I'd vote for the later solution.

Peter
 
P

Peter Michaux

Martin said:
I am looking for a good javascript obfuscator [snip]

In my opinion, there are no "good obfuscators".

And why is that? That is almost like saying there are no "good
compilers." If the obfuscator goes all the way by parsing the code and
building an abstract syntax tree there is certainly a possibility of a
good obfuscator. I believe that the YUI and Dojo tools use the Rhino
engine to parse the JavaScript and then analyze the AST. These strip
IE conditional comments but I don't think that limits them from begin
"good".

Peter
 
P

Peter Michaux

Peter Michaux said the following on 8/21/2007 12:33 PM:
Martin Mücke wrote:
I am looking for a good javascript obfuscator [snip]
In my opinion, there are no "good obfuscators".
And why is that?

Ummm, because there aren't any? :)

What is your criteria for a good obfuscater? Does it necessarily have
to deal with every possible bit of code that could go in script tags?
Or just deal with the subset of code that you write?

Do you minify your code at all?

The problem isn't a good/bad
obfuscator, the problem is that even if you have a "good one" it is a
wasted effort.

Not a total waste, it makes it harder/slower to understand the code
and so will throw off some wimpy thieves. If the value of smaller
downloads and moderate protection exceeds the cost of development/
maintenance of the obfuscator then on balance an obfuscater is a good
idea.

So you think a program that breaks otherwise properly working code can
be called "good"?

Sure a minifier/obfuscater can be good but it may not be perfect
because it may have a bug. An obfuscater is a JavaScript-to-JavaScript
compiler. All compilers have bugs but that doesn't mean we write
everything in assembly. When a compiler bug crops up we fix it.

Peter
 
R

Richard Cornford

Peter said:
Peter Michaux said the following on 8/21/2007 12:33 PM:
On Aug 21, 8:41 am, The Magpie wrote:
Martin Mücke wrote:
I am looking for a good javascript obfuscator [snip]
In my opinion, there are no "good obfuscators".
And why is that?

Ummm, because there aren't any? :)
What is your criteria for a good obfuscater?

In principle an obfuscator is something that renders something else more
obscure (Note that the question asks for an obfuscator and not a
minimiser, so presumably minimisation is not the/a point). The criteria
for what would represent a good would depend on why an increase in
obscurity is desired. There would be some standard of 'sufficiently'
obscure, to satisfy the assumed need, and a good obfuscator would be one
that achieved, or exceeded, that level of obscurity.
Does it necessarily have to deal with every possible bit of
code that could go in script tags?
Or just deal with the subset of code that you write?

That is quite a strange question. The code that any individual may write
may include anything that javascript allows. Anything that works on
javascript source code should be required to handle everything that
javascript can do.
Do you minify your code at all?

It is obfuscation not minimisation that is the subject here.
Not a total waste, it makes it harder/slower to understand
the code and so will throw off some wimpy thieves.

As has been pointed out before, if that code that is being written uses
any moderately 'advanced' techniques the odds are already good that it
is beyond the comprehension of your "wimpy thieves". I cannot remember
the name that is used, but the HTML groups talk of the principle that
the worth of any web source code is inversely proportional to the effort
made to conceal it.
If the value of smaller downloads

You are back to minimisation again. Because HTTP 1.1 introduced
standards for transition of content zipped/compressed, and user agents
support it, the size reduction effects of minimisation are not nearly as
significant as superficial observations may suggest. It has even been
demonstrated that some source code size reduction strategies have a
negative impact on subsequent zip compression, making the actual
downloads larger (if only fractionally).
and moderate protection

Moderate relative to what exactly?
exceeds the cost of development/maintenance of the
obfuscator then on balance an obfuscater is a good idea.

So you are not including the cost of QA on the post-obfuscated code?

Isn't being able to handle the code as real javascript more of a
criterion for not declaring the obfuscator as unacceptably bad, rather
than a reason for declaring it good?

I have never liked IE conditional comments and I do not use them, but
realistically they are used so any obfuscator offered for general public
use should be designed to cope with them before it can even be
considered suitable for consideration.
So you think a program that breaks otherwise properly
working code can be called "good"?
Sure a minifier/obfuscater can be good but it may not be
perfect because it may have a bug. An obfuscater is a
JavaScript-to-JavaScript compiler.

Some may be, but certainly not all on offer are.
All compilers have bugs
but that doesn't mean we write everything in assembly. When
a compiler bug crops up we fix it.

If you are writing a compiled langue then you have no choice but use a
complier. Obfuscating javascript source code is absolutely optional, and
it has drawbacks including questionable effectiveness at addressing its
objectives, making post-obfuscation maintenance and debugging of the
code harder that it may have been otherwise and requiring that the
post-obfuscated code is fully QAed so that any problems that may have
been introduced by the obfuscation process can be identified.

Richard.
 
P

Peter Michaux

Peter Michaux wrote:
Peter Michaux said the following on 8/21/2007 12:33 PM:
On Aug 21, 8:41 am, The Magpie wrote:
Martin Mücke wrote:
I am looking for a good javascript obfuscator [snip]
In my opinion, there are no "good obfuscators".
And why is that?
Ummm, because there aren't any? :)
What is your criteria for a good obfuscater?

In principle an obfuscator is something that renders something else more
obscure (Note that the question asks for an obfuscator and not a
minimiser, so presumably minimisation is not the/a point). The criteria
for what would represent a good would depend on why an increase in
obscurity is desired. There would be some standard of 'sufficiently'
obscure, to satisfy the assumed need, and a good obfuscator would be one
that achieved, or exceeded, that level of obscurity.
Does it necessarily have to deal with every possible bit of
code that could go in script tags?
Or just deal with the subset of code that you write?

That is quite a strange question. The code that any individual may write
may include anything that javascript allows.

I was suggesting the individual is self-restricting to a subset of
what can go between script tags. This is a justifiable decision and
writing a processor for a subset may be substantially easier.

Anything that works on
javascript source code should be required to handle everything that
javascript can do.

I think your answer makes my point. Not everything that goes between
script tags is JavaScript. IE conditional comments are not JavaScript.
If you are willing to limit to JavaScript 1.6- then the current Rhino-
based solutions could likely be very robust and if they have bugs then
they are surely fixable.

If by JavaScript you mean anything that can go in between script tags
then that would be a very hard target for obfuscation.

It is obfuscation not minimisation that is the subject here.

Discussions can drift :) Really it is a related question since
resistance to one may be connected to another and often the same piece
of software does both. Every obfuscater I've looked at tries to use
small replacement identifiers in order to reduce size as well as
obscure. So the goals of obfuscation and minification can be
implementationally intertwined.

As has been pointed out before, if that code that is being written uses
any moderately 'advanced' techniques the odds are already good that it
is beyond the comprehension of your "wimpy thieves". I cannot remember
the name that is used, but the HTML groups talk of the principle that
the worth of any web source code is inversely proportional to the effort
made to conceal it.

If you think of it I'd like to know. Interesting.

You are back to minimisation again. Because HTTP 1.1 introduced
standards for transition of content zipped/compressed, and user agents
support it, the size reduction effects of minimisation are not nearly as
significant as superficial observations may suggest.

Minification allows for documentation to be inserted inline in source
code. I think this is very good reason to use minification. It is much
more likely that documentation is kept up-to-date when the
documentation is staring the developer in the face. The documentation
doesn't get lost this way. Useful developer notes like like TRICKY or
TODO should note be served as they may indicate an unprofessional view
or tip a competitor off to a feature that has not yet been
implemented. Sometimes inline documentation is judged valuable and
there is no reason to gzip documentation. Minification followed by
gzip works well in this case and isn't naive double compression.
Obfuscation and then gzip may be less valuable since both use
replacement compression.

It has even been
demonstrated that some source code size reduction strategies have a
negative impact on subsequent zip compression, making the actual
downloads larger (if only fractionally).


Moderate relative to what exactly?

triple-handshake, SHA-984*7 encrypted binary with a cherry on top and
a land mine chaser.

So you are not including the cost of QA on the post-obfuscated code?

I'm including it. However not specifically as an effort to test the
obfuscater. The obfuscater should have it's own tests. If one of my
application specific tests show leads me to a test that shows a
problem with the obfuscater then test belongs in the obfuscater's test
suite. I don't test gcc's work when I test my C program.

Isn't being able to handle the code as real javascript more of a
criterion for not declaring the obfuscator as unacceptably bad, rather
than a reason for declaring it good?

I think that a traditional lexing and parsing of the code just as the
final interpreter will makes it more likely the obfuscater has a
chance at success.

I have never liked IE conditional comments and I do not use them, but
realistically they are used so any obfuscator offered for general public
use should be designed to cope with them before it can even be
considered suitable for consideration.

If the software explains it's limitations then the developer can
easily decide if it is appropriate. Software with reasonable and
declared limitations can still be useful for the general public. It is
reasonable that you can't send JScript 5.7 to a JavaScript 1.6
obfuscater.

This brings up something I don't like about most JavaScript libraries.
They build hype by saying they are good for everything but of course
they have many limitations. This actually made me very bitter when I
first started learning Rails and Prototype had the official stamp of
approval. I was very disappointed when I learned how poor this
approved code actually was.

Some may be, but certainly not all on offer are.

If a compiler is something that takes source program in and produces
source program out (perhaps in a different language) then they are all
compilers.

If you are writing a compiled langue then you have no choice but use a
complier. Obfuscating javascript source code is absolutely optional, and
it has drawbacks including questionable effectiveness at addressing its
objectives, making post-obfuscation maintenance and debugging of the
code harder that it may have been otherwise and requiring that the
post-obfuscated code is fully QAed so that any problems that may have
been introduced by the obfuscation process can be identified.

Like many choices, it is a balance of value judgments. I don't think
the QA argument stands up that well in general because if the
obfuscater is good then related problems are so rare they are
outweighed by the perceived benefits. The fact that most obfuscaters
have been awful amounts to problems in particular rather then a
general fault with the idea.

Have you tried to fool the new JavaScript YUI Compressor?

http://www.julienlecomte.net/blog/2007/08/13/introducing-the-yui-compressor/

Peter
 
P

Peter Michaux

Peter Michaux said the following on 8/21/2007 5:26 PM:
Peter Michaux said the following on 8/21/2007 12:33 PM:
Martin Mücke wrote:
I am looking for a good javascript obfuscator [snip]
In my opinion, there are no "good obfuscators".
And why is that?
Ummm, because there aren't any? :)
What is your criteria for a good obfuscater?

I hate them so I don't have a criteria for what I would call a "good"
one versus a "bad" one. The biggest problem with them is that people
think that once they obfuscate code that they have "protected" it and
that simply isn't true. It doesn't mean there won't ever be one that
protects client side code, it just doesn't exist yet.

The other problem is that obfuscation and minimization and come to be
synonymous in the web world when they are entirely different animals.

I see them as inextricable. Given that minification programs remove
whitespace that makes programs easier to read, minification programs
do obfuscate in a trivially reversible way. Obfuscater programs that
work by replacing identifiers choose short identifiers when possible
and so are minification programs.

Ideally, it should be able to handle anything I write, or leave it alone
if it can't handle it.


Are we talking about minimizing or obfuscating?
worth the effort unless it is done "on the fly" by the server.

When minifying on-the-fly there needs to be caching of the minified
version.

During the build/release of the site I work on, I generate minified
and minified-gzipped versions of the JavaScript and CSS. For each
request, apache looks at the request header and if the browser accepts
gzip, apache rewrites the request to the gzipped version. This process
also allows me to timestamp the file names and send the files with a
far-future cache expiration date.

There is no question that the minification, and build in general, must
be automated. I'm not doing that stuff manually.

If "wimpy thieves" are all you are trying to protect from, then the code
wasn't worth stealing to start with. If the code is so unique/complex
that it is worth stealing then the person stealing would have to be able
to understand it and if they can understand it then they can write it
and if they can write it they don't need to steal it. It is the
Obfuscation Paradox from hell.

If the code is not obfuscated then it is very fast to steal it an
integrate it in another page. If the code is complex and obfuscated
then it is faster to rewrite it. To rewrite it could take a long time.
So this is a good edge in a competitive area of web development where
one competitor is barely ahead of another but enough that there is a
marketing advantage. I spoke with a web developer that now obfuscates
and wishes he had before because someone did steal his code quickly
and made a clone running in another country. If it was obfuscated at
least there would have been a longer delay.

Smaller downloads are a result of minimizing, not obfuscating code. When
I talk/write about obfuscation I am referring to code that typically
starts with eval(.....

We are using different terminology. I'm thinking of obfuscation as
identifier replacement mainly.

That same "moderate protection" can usually be gained by
src="hideMyCodeFromWimpyThieves.js"

:)

A exaggeration but a funny one.

You seem to be grouping them together as if they are the same thing when
they aren't. One of the side effects of minimizing can be some simple
obfuscating (renaming of variables, etc).
From what I've seen, the term "minification program" is restricted to
whitespace removal programs. But that's just what I've seen.

Most of the ones I have looked at don't do that. They simply minimize to
an extent, rename variables, convert it to a text string and then spit
out some eval('someTextHereInASCII') code.

Why do they bother putting the code in an eval()? Just so they have to
escape some characters in the string?

But, if a minimizer or an obfuscator totally breaks my code because it
removed my IE conditional comments then I would definitely call it
anything but "good".

If your code uses IE conditional comments then that would definitely
be an inappropriate processing program.

Peter
 
G

Gregor Kofler

Peter Michaux meinte:
Not a total waste, it makes it harder/slower to understand the code
and so will throw off some wimpy thieves. If the value of smaller
downloads and moderate protection exceeds the cost of development/
maintenance of the obfuscator then on balance an obfuscater is a good
idea.

Come on. A complete and total waste. Show me one piece of JS worth
"protecting". Just one.

There are billions of libraries, frameworks, snippets out there - freely
available, sometimes well documented. I still prefer my own JS
solutions. However, I never thought about obfuscating it. If somebody
really wants to steal it - so what? If he/she good enough to adapt and
understand it, he/she can easily write those scripts by him- or herself.

If the code is so crucial, important, expensive, whatever, then people
would put some effort in penetrating the obfuscation and succeed,
anyway. And all the other stuff is not worth "protecting". And I don't
give a shit whether "wimpy thieves" steal my code.

Gregor
 
T

The Magpie

Peter said:
Martin said:
I am looking for a good javascript obfuscator [snip]
In my opinion, there are no "good obfuscators".

And why is that?
Well, its because obfuscators are supposed to make code "coded" (as in
normally unreadable). And they don't.
If the obfuscator goes all the way by parsing the code and building
an abstract syntax tree there is certainly a possibility of a good
obfuscator.
No... that would be a code compressor.
These strip IE conditional comments but I don't think that limits
them from begin "good".
It also doesn't make them obfuscators. Just compressors.

And as a final blow - why would you even *want* to obfuscate the code
in the first place? I've yet to see any (including my own) that is
remotely worth the effort.
 
P

Peter Michaux

Peter Michaux said the following on 8/21/2007 10:19 PM:
Peter Michaux said the following on 8/21/2007 5:26 PM:
Peter Michaux said the following on 8/21/2007 12:33 PM:
Martin Mücke wrote:
I am looking for a good javascript obfuscator [snip]
In my opinion, there are no "good obfuscators".
And why is that?
Ummm, because there aren't any? :)
What is your criteria for a good obfuscater?
I hate them so I don't have a criteria for what I would call a "good"
one versus a "bad" one. The biggest problem with them is that people
think that once they obfuscate code that they have "protected" it and
that simply isn't true. It doesn't mean there won't ever be one that
protects client side code, it just doesn't exist yet.
The other problem is that obfuscation and minimization and come to be
synonymous in the web world when they are entirely different animals.
I see them as inextricable. Given that minification programs remove
whitespace that makes programs easier to read, minification programs
do obfuscate in a trivially reversible way. Obfuscater programs that
work by replacing identifiers choose short identifiers when possible
and so are minification programs.

What you are describing in this thread is more minimization than
obfuscation.
[snip]

This is the same script "obfuscated" (from a web search for obfuscators):
eval(unescape('%68%35%3D%30%3B%68%30%3D%27%%36%44%%36%35%%36%45%%37%34%%32%45%%35%35%%35%32%%34%43%%33%42%27%3B%66%75%6E%63%74%69%6F%6E%20%68%31%35%28%68%31%31%29%7B%68%38%3D%4D%61%74%68%2E%72%6F%75%6E%64%28%68%31%31%2F%34%30%39%36%2D%2E%35%29%3B%68%31%33%3D%68%31%31%2D%68%38%2A%34%30%39%36%3B%68%39%3D%4D%61%74%68%2E%72%6F%75%6E%64%28%68%31%33%2F%32%35%36%2D%2E%35%29%3B%68%31%34%3D%68%31%33%2D%68%39%2A%32%35%36%3B%68%31%30%3D%4D%61%74%68%2E%72%6F%75%6E%64%28%68%31%34%2F%31%36%2D%2E%35%29%3B%68%31%36%3D%68%31%34%2D%68%31%30%2A%31%36%3B%72%65%74%75%72%6E%28%27%27%2B%68%31%39%28%68%31%30%29%2B%68%31%39%28%68%31%36%29%29%3B%7D%68%32%3D%27%%34%41%%34%31%%35%36%%34%31%%35%33%%34%33%%35%32%%34%39%%35%30%%35%34%%31%41%%30%30%%32%44%%32%41%%34%31%%31%44%%34%43%%34%46%%34%33%%34%31%%35%34%%34%39%%34%46%%34%45%%30%45%%34%38%%35%32%%34%35%%34%36%%31%42%%30%30%%32%44%%32%41%%34%32%%31%44%%34%34%%34%46%%34%33%%35%35%%34%44%%34%35%%34%45%%35%34%%30%45%%34%34%%34%46%%34%44%%34%31%%34%39%%34

Ahh ok. Now I know what you mean. That mess of percents is really
crazy and trivially easy to undo. I suppose whitespace removal and
identifier replacement are both minification and obfuscation to some
degree. Actually identifier replacement is a better obfuscation then
those percents because it takes a person's slow analysis to undo what
identifier means what.

Thanks,
Peter
 
R

Richard Cornford

Peter said:
Peter said:
On Aug 21, 1:51 pm, Randy Webb wrote:
Peter Michaux said the following on 8/21/2007 12:33 PM:
On Aug 21, 8:41 am, The Magpie wrote:
Martin Mücke wrote:
I am looking for a good javascript obfuscator [snip]
In my opinion, there are no "good obfuscators".
And why is that?
Ummm, because there aren't any? :)
What is your criteria for a good obfuscater?

In principle an obfuscator is something that renders something
else more obscure (Note that the question asks for an obfuscator
and not a minimiser, so presumably minimisation is not the/a
point). The criteria for what would represent a good would
depend on why an increase in obscurity is desired. There would
be some standard of 'sufficiently' obscure, to satisfy the
assumed need, and a good obfuscator would be one
that achieved, or exceeded, that level of obscurity.
Does it necessarily have to deal with every possible bit of
code that could go in script tags?
Or just deal with the subset of code that you write?

That is quite a strange question. The code that any individual
may write may include anything that javascript allows.

I was suggesting the individual is self-restricting to a subset of
what can go between script tags. This is a justifiable decision and
writing a processor for a subset may be substantially easier.

I always worry about the notion of (self or externally) imposed blanket
restrictions on what may be done in javascript. For a start we see too
many questions on this group that take the form "I have tied my own
hands and now I need to know how to do the things that became imposable
when I tied my own hands", which don't tend to get what the OP might
consider 'good' answers.

There certainly are some things that everyone should be avoiding, and
the recent illustration of the non-obvious/counterintuitive consequences
of the use of the - with - statement in javascript goes a long way
towards justifying a general assertion that the - with - statement
"should not be used in javascript". But then there is a justifiable use
of the - with - statement, to deliberately augment the scope chain of a
dynamically created function object. The need to do that is rare
(pushing exceptional) but it does exist. Would you want to sacrifice
that possibility just because the rest of the time the - with -
statement "should not be used in javascript"?

The - with - statement, along with - eval - (which is itself subject to
similar injunctions on its use) are the two constructs that can really
mess-up poor obfuscation/minimisation methods.

An illustration of - eval -'s role came to my attention earlier in the
week. For some reason (curiosity as to how they had achieved their
latest spectacular f**k-up) I took a look at one of the javascript files
imported by Google groups pages. The file is -
g2_common-1cb0e454e081b7db50b59661d9bad546.js - (though I suspect that
all the characters after the dash change regularly (they look like a
session ID)), and that file has been 'minimised' using a technique that
has attempted to transform local Identifier names to shorter (one
character) names (a good idea for a minimiser, though a sub-optimal
implementation here). In that code I found (and it is quite easy to find
as it appears twice) a - Function.prototype.appply - emulation (a
subject I have written about many times in the past) which is presumably
to all support on pre-JScritp 5.6 IE browsers (which means mostly IE 5
to 5.5 as that is ActiveX became scriptable). The code reads
(re-wrapped):-

| if(!Function.prototype.apply){
| Function.prototype.apply = function(a,b){
| var c=[],e,g;
| if(!a)a=ra;
| var f=b||[];
| for(var h=0;h<f.length;h++){
| c[h]= "args["+h+"]"
| }
| g="oScope.__applyTemp__.peek()("+c.join(",")+");";
| if(!a.__applyTemp__){
| a.__applyTemp__=[]
| }
| a.__applyTemp__.push(this);
| e=eval(g);
| a.__applyTemp__.pop();
| return e
| }
| }

It is reasonably obvious what that code is trying to do (so much for
obscurity) and it is pretty obvious that the process of minimisation had
broken it, by transforming the Identifiers - oScope - and - args - into
one character equivalents but not doing so inside the strings that will
be - eval -ed. And of course a minimiser should not be messing with the
contents of string literals, but what it should be doing is recognising
the - eval - use and not trying to transform any Identifiers in the
(lexically) containing scopes.

Though a better solution would be observing that you only need to use -
eval - in a truly general - apply - emulation, while no real script
contexts are truly general so there was never a need to use - eval -
here in the first place. Still, if Googl's script authors are not with
it enough to notice that they have included the - appply - emulation
twice in the same script I suppose it is a bit unrealistic to expect
them underside what they are doing or why they are doing it.
I think your answer makes my point. Not everything that goes between
script tags is JavaScript. IE conditional comments are not
JavaScript. If you are willing to limit to JavaScript 1.6 then the
current Rhino based solutions could likely be very robust and if
they have bugs then they are surely fixable.

If conditional comments were a rare, unknown or unexpected feature of
web authoring then you would be right. But we know, if only form
observation, that that is not the case. It may be a pain to take
something like Rhino, for which a comment is just a comment, and make it
see when a comment is a conditional comment (especially when Microsoft
is not going to make the conditional comment algorithms public), but
that is a job that has to be done before the end result is going to be
of general use.
If by JavaScript you mean anything that can go in between
script tags then that would be a very hard target for
obfuscation.

You switch between obfuscation and minimisation at the drop of a hat.
Discussions can drift :)

Yes, but where has this one drifted to? are we talking about code
minimisation or code obfuscation at this point?
Really it is a related question since resistance to one
may be connected to another and often the same
piece of software does both.

A degree of obfuscation may be a likely side-effect of minimisation, but
it is not the goal of minimisation. While minimisation is only a
possible side effect of obfuscation. There is, for example, a heavily
marketed commercial script obfuscator that attempts to increase
obscurity by transforming Identifiers into sequences of characters that
look numeric (upper case - o - and lower case - L - followed by decimal
digits), the result increases obscurity (at least in the absence of
syntax highlighting) by often does nothing to reduce code size (on its
own).
Every obfuscater I've looked at
tries to use small replacement identifiers in order to reduce
size as well as obscure.

That is not true of many obfuscators I have looked at, and attributing
the motivation of code size reduction to the transformations performed
by an obfuscator would be questionable. If software is designed to
obscure the likely primary motivation for any actions it takes are
likely to be increased obscurity not minimisation.
So the goals of obfuscation and
minification can be implementationally intertwined.

A level of the one can be the side effect of the other, in both
directions.

Minification allows for documentation to be inserted inline in
source code. I think this is very good reason to use minification.

So is "minification" (which implies an attempt to achieve an extreme of
small-ness) the only thing that will prevent commented source code from
being distributed with its comments? Obviously not.
It is much more likely that documentation is kept
up-to-date when the documentation is staring the
developer in the face.

Well, you would think so, but reality is disappointing in that area.

I'm including it. However not specifically as an effort to test the
obfuscater.
<snip>

Where would you attribute the fault in the Google code I posted above?
It is being distributed to client browsers, and it is broken. It may
have been broken by the attempt at minimisation, but it was a failure to
run proper QA tests on the post-minimisation version that has resulted
in its being distributed in its broken state.
I think that a traditional lexing and parsing of the code just as
the final interpreter will makes it more likely the obfuscater has
a chance at success.

Yes, that is fairly necessary if minimisation is to go beyond removing
non-significant white space and comments. On the other hand, removing
non-significant white space and comments will invariably have a big
impact on code size (and a side-effect on relative obscurity). While
interpreting faces the problem that some javascript is (or may be)
interpreted at runtime.

If the software explains it's limitations then the developer
can easily decide if it is appropriate.

Yes, at least when they know enough to make the judgment.
Software with reasonable and declared limitations can
still be useful for the general public.

The "general public"? What do the general public have to do with browser
scripting?
It is reasonable that you can't send JScript 5.7 to a
JavaScript 1.6 obfuscater.

But it would not be reasonable if you could not send ECMAScript to a
browser supporting either (that is, after all, the point of having a
standardised language).
This brings up something I don't like about most
JavaScript libraries.

Only most?
They build hype by saying they are good for everything
but of course they have many limitations.

Any library claiming to be "good for everything" would be a bad library
for that reason alone, as there a no real world contexts where
everything is needed. (Considering that the project I am working on at
the moment now has a client-side code base of over 100,000 lines and it
certainly does not need to do 'everything', for example, there is
currently no code at all that attempts to manipulate user selections)
This actually made me very bitter when I first started
learning Rails and Prototype had the official stamp of
approval.

Does it still, or are the mistakes of the past being corrected?
I was very disappointed when I
learned how poor this approved code actually was.

Seeing what was being done with it I was not at all surprised that the
people making Rails design decisions were also 'approving' poor script
code.
If a compiler is something that takes source program in and
produces source program out (perhaps in a different language)
then they are all compilers.

No, some minimisers work only at the source text level, they may take in
what is effetely a program, and then output what is still effetely a
program, but they are not compilers.
Like many choices, it is a balance of value judgments.

Preferably informed judgments.
I don't think the QA argument stands up that well in general
because if the obfuscater is good then related problems are
so rare they are outweighed by the perceived benefits.

And Google groups think they are supporting JScript < 5.6 but in reality
they are not. and they don't know they are not because they did not do
the QA.
The fact that most obfuscaters have been awful amounts to
problems in particular rather then a general fault with
the idea.
<snip>

The problem with obfuscators is exactly the same problem it has always
been; they do not achieve a sufficient level of
(non-trivially-reversible) obscurity to provide anything resembling
'protection' ("moderate protection" or otherwise). The formatting and
non-significant white space can be resorted with the simplest of tools,
the DOM and browser object model interactions cannot be subject to
Identifier modification because that will break them, the names of
javascript object properties cannot be modified unless you have
simultaneous access to all the code in the entire system when
obfuscating because you could not guarantee that other code will not
want to refer to those property names, the global identifiers cannot be
modified for the same reasons (under the same circumstances), and that
just leaves the local parameters, inner function declaration and
variable names amenable to modification (and only if they are in scopes
where - with - and - eval - are never used).

And what happens when you change those local Identifiers? There
meaningful names are gone, but their names where maybe not meaningful to
someone who did not understand the author's native language to start
with, and as each Identifier was only meaningful within a confined
lexical scope anyway it does not take much looking to work out their
roles in thier context without ever knowing what (possibly) meaningful
names they may have had. Indeed, if a local variable needed a name that
was any more than unique in its scope then no non-English
speaking/reading programmer could never learn anything from most of the
code examples that exist. We would live in a world where software
authoring was virtually restricted to the English speaking nations, and
that is just not the case.

Minimisation and obfuscation are not the same thing, where the goal is
obfuscation the outcome will not justify the effort. Minimisation may
have a different cost-benefit, but Google are doing a good job of
illustration that the cost side of the equation may not always be being
properly perceived.

Richard.
 
P

Peter Michaux

On Aug 26, 9:10 am, "Richard Cornford" <[email protected]>
wrote:

[snip regarding obfuscation/minification]

Thoughts and comments appreciated and points taken.
Any library claiming to be "good for everything" would be a bad library
for that reason alone, as there a no real world contexts where
everything is needed. (Considering that the project I am working on at
the moment now has a client-side code base of over 100,000 lines and it
certainly does not need to do 'everything', for example, there is
currently no code at all that attempts to manipulate user selections)


Does it still, or are the mistakes of the past being corrected?

Prototype is still packaged and integrated with Rails. Prototype is
getting better but some foundational design decisions (eg augmenting
built-ins) will always make it fatally flawed. They are swatting flies
instead of removing the rotting carcass from the room. They have had a
share of good ideas.

Peter
 
J

Julian Turner

On 22 Aug, 00:16, "Richard Cornford" <[email protected]>
wrote:

[snip]
Obfuscating javascript source code is absolutely optional, and
it has drawbacks including questionable effectiveness at addressing its
objectives, making post-obfuscation maintenance and debugging of the
code harder that it may have been otherwise and requiring that the
post-obfuscated code is fully QAed so that any problems that may have
been introduced by the obfuscation process can be identified.
[/snip]

Speaking as a reformed character, who has experimented with
obfuscation in the past, I would strongly support this statement, from
experience.

If one seeks to obfuscate large complex script files, the obfuscation
process can introduce a number of subtle problems which can also vary
from browser to browser.

These feel like a very small needle in a very large haystack, and it
would seem to me that to solve these problems requires the close
involvement of the program authors, to try to deduce how the
obfuscator could be effecting the program.

If you are lucky these problems show up as a syntax error - although,
if your code is all in one line, then an error which points to "char
237636 on line 1" is daunting, and the cause is rarely the character
pointed to.

If you are unlucky, then the problem will not produce a syntax error,
but will appear either as a mysterious runtime error at some point, or
worse, a program logic error, which you may never spot until it is too
late.

The only way I was able to even able to get my obfuscated code to run
was to adopt a layered approach, to trap errors:-

remove comments
test on target browsers
change "var" names
test on target browsers
change function argument names
test on target browsers
change other names
test on target browsers
remove line breaks
test on target browsers

But this was madness, a complete waste of resouce when I could be
spending my time writing, testing, debugging and maintaining my
original code. It is hard enough debugging the original code without
introducing a whole new layer of errors.

Julian
 

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,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top