Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8317435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:36:09+00:00 2026-06-08T21:36:09+00:00

I know security is either non-existant or very difficult in client side JavaScript. I

  • 0

I know security is either non-existant or very difficult in client side JavaScript. I know my server-side code should ultimately decide who it gives data to or accepts data from.

That said, is the following okay to do. By “okay” I mean if this were the method used on some new popular trendy cool web app. Could I sleep at night knowing that I won’t see “Super Cool Web App Hacked, change your passwords!” all over HN and Reddit (or any other sources of info people care about) as a result of this implementation.

If it is not secure. Why? How can that info (username and password) be obtained?

If it is secure? How sure are you? Why is it secure? What is stopping me from getting that info outside of my obvious inability to right now.

Partial answers are welcome. Just looking for a better understanding.


EDIT

I’m thinking about the case of some trying to steal a users credentials. My understanding is that cookies are insecure because 1.) other javascripts (via XSS or whatever) can access them and because 2.) they are passed in the clear. I figure SSL would take care of the second issue and lets just assume I’m able to prevent XSS. It would now seem that cookies are now secure, right?

I’m aware of some supposed browser vulnerabilities that assist in making cookies insecure. That’s what made me ask this question. Given all the things that make cookies insecure, is this (code below) any better?


http://jsfiddle.net/KTastrophy/vXEjm/1/ OR see code below
(Only tested in Chrome)

<!DOCTYPE html>
<html>
    <head>
    </head>
    <body>
        <form id="login">
            <div>
                <label for="username">Username</label>
                <input id="username" name="username" type="text" />
            </div>
            <div>
                <label for="password">Password</label>
                <input id="password" name="password" type="password" />
            </div>
            <div>
                <input id="submit" name="submit" type="submit" value="Login" />
            </div>
        </form>
    </body>
    <script type="text/javascript">
        ;(function () {
            "use strict";
            var login, user = {};
            login = document.getElementById("login");
            login.onsubmit = function (event) {
                event.preventDefault();
                user.username = document.getElementById("username").value;
                user.password = document.getElementById("password").value;

                /*
                    use the username and password here to do
                    an API request over SSL using HTTP Auth
                 */
            }
        }());
    </script>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T21:36:11+00:00Added an answer on June 8, 2026 at 9:36 pm

    When you’re dealing with sensitive values stored in JavaScript, you have two primary security concerns:

    1. The sensitive value is viewable as plain text in the source.
    2. Another JS function on the page can reach into the object and pull those values (i.e., an XSS attack).

    The second item above becomes much more relevant when you have apps running from multiple sources on a single page (e.g., Facebook apps). In these instances, you would have to take pre-cautions not to expose sensitive variables by using closures to namespace. You are actually already doing this: your user object is declared inside a closure. This prevents any other JS function on the page from being able to access the user object.

    In your case, I’m assuming that there isn’t any other code on the page except for your own and the possibility for injection is minimal–your code is safe 🙂

    Edit: What makes storing the username and password in a cookie insecure is that it sits on your computer after you’ve closed the browser. If a hacker can access that cookie (through any number of ways) then you could be in trouble. What you’ve done above is safe because nothing is stored on the client side after the browser closes (and while the browser is open, other JS cannot access the values you’ve stored). If you want to put something in a cookie, it’d be better to store some sort of public/private authentication key. There’s a lot of discussion on this, here is a thorough ‘best practices’ article on the topic: http://jaspan.com/improved_persistent_login_cookie_best_practice

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to know how to go about implementing general security for a C#
Does anyone know of any article/publication on the security architecture of Metro app? For
I've been working on a spring security recently and I need to know how
I'm studying security, and I would like to know: in Windows or Unix based
I'm using Spring, Spring Security, BlazeDS, Flex and spring-flex. I know that I can
Know if it's possible to access the iPhone compass in Safari using JavaScript? I
I'm curious to know how the new security model in OS X Lion will
It's pretty well known that overridden objects in Javascript can cause security issues, or
I'm mostly an ASP.NET developer, so I'm not very familiar with either J2EE or
Before everyone tells me that I shouldn't do client-side sanitization (I do in fact

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.