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

Home Posts Topics Members FAQ

Verify JavaScript before using eval()

Frinavale
9,735 Recognized Expert Moderator Expert
Apparently I have a lot of questions today regarding JavaScript security.

I've implemented a JavaScript Object that intercepts page submits (postbacks) and then displays a UI prompting the user to confirm(yes)/deny(no)/cancel(close UI/cancel submit) their action.

There may be additional JavaScript methods to execute before displaying the UI and may be additional JavaScript methods to execute upon closing the UI.

I'm thinking about passing these additional JavaScript methods from the server to the JavaScript Object using "properties ".

There's a little magic here because I'm not entirely sure how the data (the properties) is passed from my .NET Server code to my JavaScript Object. I'm assuming that there is a JSON Object being used behind the scenes....I'm going to look into this on my own....

I am wondering about the risks of using the eval() method with regards to JSON Objects. I'm quite new to JavaScript and so I'm not entirely sure how to secure my Objects.

The way I see it (assumption about using JSON made):
  • Server sends JSON Object to client:
    • client populates my JS Object's properties w/data supplied
    • JS Object uses eval() method to executed additional JS methods

If the JSON Object were captured and modified during transport, then my JavaScript Object may end up executing code that isn't my own.

Is there some way (a toolkit or other JavaScript library which you would recommend that can check hashes or something) to verify that the JavaScript has been provided by my code?

Is this type of attack easy to do (is it high risk)?

Is there something other than the eval() method that I can use that is safer?

Are there any other risks that I should be aware of?

I know that this is a lot to ask but I'm pretty much looking for any keywords/concepts that I can research before I start implementing this solution. Your thoughts on the topic would be greatly appreciated.

Thanks a lot,

-Frinny
Jun 22 '09 #1
6 3545
Dormilich
8,658 Recognized Expert Moderator Expert
I've not done much with JSON (I'm using WDDX), but if you serialize an object you do not transmit the methods (and thus do not use eval()), i.e. you need to have the class definition where the methods are stored already in the script and the objects are deserialized using the transmitted properties only.

from what I know there are different JSON deserializers available (at least 3)
Jun 22 '09 #2
Frinavale
9,735 Recognized Expert Moderator Expert
@Dormilich
What??
You've completely lost me.
Jun 22 '09 #3
Dormilich
8,658 Recognized Expert Moderator Expert
objects are usually sent serialized (you only submit the data (properties) and therefore need the "class definition" on the receiver).

acoder mentioned to look at the JSON parsers instead of using eval().
Jun 22 '09 #4
Frinavale
9,735 Recognized Expert Moderator Expert
I'm still reading through the links (of the links) that acoder had posted.

Now, I'm not sure I'm ready to jump into using JSON before I completely understand how it works. (I starting having a lot of fun with it a couple of weeks ago...I was very impressed with what I could do using JSON and AJAX)

The parseJSON() method looks like it's going to fix a bunch of security risks inherent to JSON's dependency on JavaScript's eval() ...but there are a lot of security topics (that I was not aware of before now) that I'm going to have to keep in mind while using JSON.

I wonder if the AJAX.NET library uses the parseJSON() method? I am having a very hard time finding out what exactly is going on behind the scenes with regards to how the data is transferred from the Server to the Client.


I have a feeling that the "Same Origin Policy" is going to cover a lot of the concerns that I was having with my particular object....but I'm still not sure how to detect a man-in-the-middle attack.
Jun 22 '09 #5
acoder
16,027 Recognized Expert Moderator MVP
In case anyone else following this thread is wondering what those links were[*], here they are:
JSON in JavaScript
JSON - Wikipedia
Basically, use a JSON parser instead of eval().
[*] deleted the post as I saw Dormilich had responded.
Jun 22 '09 #6
rnd me
427 Recognized Expert Contributor
man in the middle?
the only way to stop that is https.

if you are serving your own content, there's no reason eval cannot be used.
you are serving the whole page in the first place, right?

if you are talking about large amounts of data, remember that eval is WAY faster than a JS-based parser would be.

jsonp demands a little more care than json, only because 3rd party websites will be able to use free-range javascript to grab your data. anyone could still use curl to get your non-jsonp json, they just can't easily and cheap pass along the ability to do so, thanks to the SOP...

remember, jsonp uses eval, only json via ajax can be parsed as described...
Jul 6 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
3831
by: JesusFreak | last post by:
From: us_traveller@yahoo.com (JesusFreak) Newsgroups: microsoft.public.scripting.jscript Subject: toolbar script problem NNTP-Posting-Host: 192.92.126.136 Recently, I downloaded the following beautiful script "http://javascript.internet.com/navigation/toolbar-menu.html". It works like a charm. I made my webpage in frames, where the nav-frame shows the menubar, so whenever I click a link in the menubar, it opens in the frame below. But...
0
8339
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8751
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...
1
8535
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8629
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...
0
7360
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
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
4176
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...
1
2757
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
1982
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.