473,671 Members | 2,251 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is a closure's scope accessible by untrusted code?

Is the scope of a closure accessible after it's been created? Is it
safe against XSS to use closures to store "private" auth tokens? In
particular, in...
function closure(token) {
return function () {
// code which uses token to authenticate
}
}

foo = closure(secret) ;
delete secret;

// untrusted code
....can untrusted code access 'secret', or only the code inside foo?

- Andrey
Oct 24 '08 #1
2 1830
On Oct 24, 1:57 pm, Andrey Fedorov wrote:
Is the scope of a closure accessible after it's been created?
The scope is handled internally by the implementation; you probably
mean 'are the objects on the scope chain accessible after it has been
created', or at least those not added to a scope chain with a - with -
statement or the global object (the latter always being accessible).
In pure ECMAScript terms the answer is no. However, in javascript
terms the answer would be 'don't rely on that', as implementations
have provided mechanisms for setting/re-establishing scopes for
function calls. See:-

<URL: http://peter.michaux.ca/article/8069 >
Is it safe against XSS to use closures to store "private"
auth tokens?
Almost certainly not. Not necessarily for any reasons related to
closures but rather questions like how these "auth tokens" got to the
javascript code without being exposed. (If they are in the page source
or the source of an (even dynamically generated) JS file how can you
be certain that the text cannot be retrieved from the DOM, and if XML
HTTP requested how can you be certain that the XSS script did not wrap
the XML HTTP request object, etc.?)
In particular, in...
>function closure(token) {
return function () {
// code which uses token to authenticate
}
}
>foo = closure(secret) ;
delete secret;
>// untrusted code

...can untrusted code access 'secret', or only the code inside foo?
Even if it cannot does it need to? The - foo - value is exposed and
can be modified, and its source code extracted to form the basis for
that modification.

Richard.
Oct 24 '08 #2
Thanks for the thorough response -
how can you be certain that the XSS script did not wrap
the XML HTTP request object
By making sure all user-submitted data are rendered only after the
closures which use auth-token have been created.

Thanks also for the link to Peter's blog, I was looking for that - the
issue appears to have been closed in in FF >= 3.1. I agree that this
isn't a solid solution, but might provide at least somewhat of a
barrier against some attacks.

Cheers,
Andrey
Oct 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1824
by: Dave Benjamin | last post by:
Here are some more ideas for how to implement a statement-friendly code block syntax in Python. Hopefully more "Pythonic" (that is, of or pertaining to those features noticably reminiscent of styles relating to things Python-like; see: Pythonic) this time. Warning to uninitiated: This is not real Python. I am playing make-believe. If you are a Python beginner, kindly ignore this post unless you want to get confused or you like made-up...
27
2103
by: Ted Lilley | last post by:
What I want to do is pre-load functions with arguments by iterating through a list like so: >>>class myclass: .... pass >>>def func(self, arg): .... print arg >>>mylist = >>>for item in mylist: .... setattr(myclass, item, lamdba self: func(self, item))
7
1862
by: Csaba Gabor | last post by:
I feel like it's the twilight zone here as several seemingly trivial questions are bugging me. The first of the following three lines is a syntax error, while the last one is the only one that shows the alert. What is the essential reason? function () { alert('hi mom'); }(); function () { alert('hi dad'); }(8); var x=function () { alert('hi bro'); }();
1
2577
by: Steven T. Hatton | last post by:
All of the following terms are used in some way to describe where and how a name is relevant to a particular location in a program: visible, declarative region, scope, potential scope, valid, introduced, used, potentially evaluated and accessible. They all seem to have subtle difference in meanings. Any positive contribution to the following will be appreciated. Here is my attempt to make sense of these:
11
3021
by: Huayang Xia | last post by:
What will the following piece of code print? (10 or 15) def testClosure(maxIndex) : def closureTest(): return maxIndex maxIndex += 5 return closureTest()
4
1988
by: LAN MIND | last post by:
?
2
1413
by: jman | last post by:
for ( var i = 0; i < div.firstChild.childNodes.length; ++i ) { var marker = new Object(); marker.iii = i; sys.addListener( marker, "click", function() { alert(marker.iii); }); }
4
1304
dmjpro
by: dmjpro | last post by:
Today i looked at JavaScript closures. There i came across a thing closure comes in when an inner function defined inside an outer function. So when outer function exits and returns the inner function reference then a hidden reference returns along with the reference of inner function. Now my question is when that hidden reference created? And the hidden reference have the references of all local variables of outer function. Now my second...
4
1378
by: JavascriptProgrammer | last post by:
In the following code: ----------------------- function get() { return function() { alert(x); } }; function foo(s) { var x = s; this.getX = get();
0
8476
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8821
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8670
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6229
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5696
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4225
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4407
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2812
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2051
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.