473,387 Members | 3,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Is Javascript Secure?

Hi Everyone,

I have been asked to build a PHP application that calculates important
financial information based on some user-inputted numbers and that will

not allow the user to continue forward unless a certain percentage
range has been met. To validate the numbers, I am considering using
Javascript as opposed to having the PHP code validate the numbers
because Javascript is faster (it is almost instantaneous because the
validation code is running on the client side and does not have to wait

for a refresh, as would be required for the server-side PHP code
validation).
My question is: is Javascript secure? My concern here is that because
the Javascript validation would run on the client's computer, they
could potentially hack it to allow unacceptable financial numbers to be

submitted. Am I just being too paranoid here?
Thanks in advance,
-Karl

Jun 7 '06 #1
7 5137
dredge wrote:
<snip>
My question is: is Javascript secure?
The unsecured thing here is the client, not the Javascript as such.
My concern here is that because the Javascript validation would run
on the client's computer, they could potentially hack it to allow
unacceptable financial numbers to be
Yes they could just hack it and send anything they wanted to the
server. There are also numerous other ways of sending anything at all
to the server (not, or not necessarily, involving javascirpt).
submitted. Am I just being too paranoid here?


_Always_ validate anything important (and most else besides) on the
server; the client cannot be trusted (even on an Intranet).

Richard.

Jun 7 '06 #2
"dredge" <kc**@issllc.com> writes:

[validate on client instead of server]
My question is: is Javascript secure? My concern here is that because
the Javascript validation would run on the client's computer, they
could potentially hack it to allow unacceptable financial numbers to be
submitted. Am I just being too paranoid here?


No, that's exactly what they can do. (And it's not whether you are
paranoid, it's whether you are paranoid *enough*! :)

You are in a server/client setting, and the golden rule about security
in that setting is: Never trust the client!

It's not that Javascript is secure or not, it's the entire platform
that's unsafe. I can manually submit invalid data to your server using
a telnet connection, no browser needed and no Javascript runnning at
all.

If your server cannot accept certain input, *it* should test those
inputs. Nobody else can do it as well, and nobody else can be trusted
anyway.

You can still have client-side validation as a *convenience* for
normal, trustworthy users, saving the server roundtrip for each
validation, and also keep server-side validation as a *security*
measure.

Good luck
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jun 7 '06 #3
On Wed, 07 Jun 2006 09:16:03 -0700, dredge wrote:
I have been asked to build a PHP application that calculates important
financial information based on some user-inputted numbers and that will

not allow the user to continue forward unless a certain percentage range
has been met. To validate the numbers, I am considering using
Javascript as opposed to having the PHP code validate the numbers
because Javascript is faster (it is almost instantaneous because the
validation code is running on the client side and does not have to wait

for a refresh, as would be required for the server-side PHP code
validation).

My question is: is Javascript secure? My concern here is that because
the Javascript validation would run on the client's computer, they could
potentially hack it to allow unacceptable financial numbers to be

submitted. Am I just being too paranoid here?


I always validate the data entry with javascript and then validate data
integrity with PHP before it gets dumped into the database.

Get and post can both be spoofed whether javascript is being used or not.

--
The USA Patriot Act is the most unpatriotic act in American history.
Feingold-Obama '08 - Because the Constitution isn't history,
It's the law.

Jun 7 '06 #4
Hi all
It is true, while security is achievable on the server with PHP you
should never trust anything from the client side.

But don't be lured into a false sense of security and assume your data
or application is totally secure just because you're using server-side
logic and data. Server stored pages are also vulnerable to hacks and
you must protect yourself against these. PHP is considered by some to
be vulnerable to bad programming in this sense - make sure you cover
youreself.

This recent opinion piece summarises these concerns quite well.
http://blog.develix.com/frog/user/cl...e/2006-06-06/1

-ad

Ivan Marsh wrote:
On Wed, 07 Jun 2006 09:16:03 -0700, dredge wrote:
I have been asked to build a PHP application that calculates important
financial information based on some user-inputted numbers and that will

not allow the user to continue forward unless a certain percentage range
has been met. To validate the numbers, I am considering using
Javascript as opposed to having the PHP code validate the numbers
because Javascript is faster (it is almost instantaneous because the
validation code is running on the client side and does not have to wait

for a refresh, as would be required for the server-side PHP code
validation).

My question is: is Javascript secure? My concern here is that because
the Javascript validation would run on the client's computer, they could
potentially hack it to allow unacceptable financial numbers to be

submitted. Am I just being too paranoid here?


I always validate the data entry with javascript and then validate data
integrity with PHP before it gets dumped into the database.

Get and post can both be spoofed whether javascript is being used or not.

--
The USA Patriot Act is the most unpatriotic act in American history.
Feingold-Obama '08 - Because the Constitution isn't history,
It's the law.


Jun 8 '06 #5
JRS: In article <11*********************@u72g2000cwu.googlegroups. com>,
dated Wed, 7 Jun 2006 09:36:51 remote, seen in
news:comp.lang.javascript, Richard Cornford
<Ri*****@litotes.demon.co.uk> posted :

_Always_ validate anything important (and most else besides) on the
server; the client cannot be trusted (even on an Intranet).


Not always.

One cannot do that if the server merely dispenses pages and does not
receive any return data.

One need not do that if correct operation is in the user's interest;
indeed, in that case the user might wish to validate the page code
itself somehow.

Remember : there is life outside of commercial trading.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jun 8 '06 #6
Dr John Stockton <jr*@merlyn.demon.co.uk> writes:
JRS: In article <11*********************@u72g2000cwu.googlegroups. com>,
dated Wed, 7 Jun 2006 09:36:51 remote, seen in
news:comp.lang.javascript, Richard Cornford
<Ri*****@litotes.demon.co.uk> posted :

_Always_ validate anything important (and most else besides) on the
server; the client cannot be trusted (even on an Intranet).
Not always.

One cannot do that if the server merely dispenses pages and does not
receive any return data.


Well, then "anything important" is trivially validated :)
One need not do that if correct operation is in the user's interest;
indeed, in that case the user might wish to validate the page code
itself somehow.

Remember : there is life outside of commercial trading.


Absolutely. Only when false data sent to the server can in some way
hurt the server owner, or other users, is it necessary to protect it
against a malicious user. If all the malicious user can do is to hurt
himself, then by all means give him rope enough to hang himself.

On the other hand, input validation can also, potentially, catch the
odd input that is really an attempt at a buffer overflow or SQL
injection attack, one that you didn't know about. If you treat input
programmatically in any way, or pass it to third party components of
any sort, better be safe than sorry. You might not know whether you
can be hurt. Crashing a server doesn't only hurt the person doing it,
but also all other users wanting to use it (denial of service).

If you touch user input with a ten foot pole, validate it first. It
might just be designed to break the pole :)
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jun 8 '06 #7
In article <tL**************@merlyn.demon.co.uk>, Dr John Stockton
<jr*@merlyn.demon.co.uk> writes
JRS: In article <11*********************@u72g2000cwu.googlegroups. com>,
dated Wed, 7 Jun 2006 09:36:51 remote, seen in
news:comp.lang.javascript, Richard Cornford
<Ri*****@litotes.demon.co.uk> posted :

_Always_ validate anything important (and most else besides) on the
server; the client cannot be trusted (even on an Intranet).
Not always.

One cannot do that if the server merely dispenses pages and does not
receive any return data.


You snipped the word 'submitted'; your comment doesn't apply here.
One need not do that if correct operation is in the user's interest;
indeed, in that case the user might wish to validate the page code
itself somehow.
Not always.

The user could be following a (possibly malformed) link in a news
article, not knowing any better.
Remember : there is life outside of commercial trading.


Returning misleading advice is still unethical even if given outside
commercial trading.

John
--
John Harris
Jun 9 '06 #8

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

Similar topics

41
by: Mr. x | last post by:
Hello, Can I make my java script code be invisible to other people who enter into my site by IE browser ? - How ? Thanks :)
5
by: Connie Walsh | last post by:
Hi: I gleaned a javascript off of the web: http://www.hypergurl.com/popup.html that sets a cookie everytime someone visits your site. If it is the first visit in x number of days then a...
4
by: John | last post by:
I am writing some JavaScript code and need to write one set of code if on a standard page and a different set if on a secure page. Does anyone know if there is a JavaScript function that tests...
7
by: Steph | last post by:
Bonjour, Je souhaite lancer une redirection vers un fichier php via SRC= dans une condition if (voir ci-dessous en bas du script) mais la redirection ne fonctionne pas. Par contre la condition...
1
by: CR1 | last post by:
I found a great cookie script below, but don't know how to make it also pass the values sent to the cookie, to a querystring as well for tracking purposes. Can anyone help? If there was a way to...
8
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How can I protect a webpage in javascript?...
3
by: krg | last post by:
Hi, I started writing this blog some time back and it would be great if I could get an audience here and even better if we could have a conversation about developments possible on the techniques I...
4
by: webmaniac | last post by:
Hi, Does anyone knows How "JAVAScript Public Key Encryption" works? I am trying to secure my web page. The users are going to be log in to my website. I want to give them a 4 digit pin, that...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.