rlgarris682 has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I am a new Perl Monk and have a brief question concerning security.

I have devised a fairly simple yet I believe very robust security system for acessing a limited access part of website and would like an assement.

I have written an HTML file with a Javascript in it that will be used to gain access to the limited access part of the website.

In this HTML file is two scripts the 1st script contacts the server and the server sends a random chracter string to the client side javascript. The second script concatenates the random string with a second secret string embedded in the HTML file and then SHA1 hashes this into a new string. See http://pajhome.org.uk/crypt/md5/sha1src.html The script sets this string as a cookie and effectively this new string then becomes the session id for the user and the user can proceed to access the limited part of the website for one session. One the server side, the server has a copy of the secret code that the cleint will be using and of course knows the random string it just generated. The server (which is of course mod_perl) will then SHA1 hash the secret code and its randomly generated string to see if the session id is valid. In addition to this is after the challenge, hash, and authentication is completed a password is asked for.

I know this in fact a virtual duplicate of CHAP login method just used in a different way, but I wanted to know if there are any obvious security threats I missed.

For anyone wondering: The HTML file will kept on the client computer and the secret code will be a 192 hex string. The reason I am not just using password security is that I am doing this for a client who has trouble remembering passwords so he keeps his passwords simple. THis security feature prevents random guessing machines from nailing his password. If someone tries to contact the limited part of the site and does not have a valid session id then the server will simply respond with a 404 page not found error -- this will fend off most robots and people for that matter.

2003-04-28 edit ybiC: format with (evidently intended) paragraphs, urlify link

Replies are listed 'Best First'.
Re: Security and JavaScript
by Improv (Pilgrim) on Apr 29, 2003 at 00:34 UTC
    So, what security failures are you aiming to prevent? If you're only aiming to prevent random guessing machines from getting in, it's not a bad system, provided that the mathematics behind SHA algorithm arn't too bad. However, it won't offer any protection at all against network sniffing, and if the network does get sniffed between, there's a chance (I think) for the client key to be comprimised. It might help if you have a password being asked for regardless of if the hash went ok, so as to make it harder for people to know if they get the hash part right. You might want to complement this with SSL too.

      Right yeah actually the secret code kept in the html file is never sent as plain text only the hash of the randomly generated number and secret code is so even if a packet sniffer gets hold of the hash it wouldn't do them any good because that hash is only valid for that session and linked to the clients original ip address. The SHA1 algorithm is a 160-bit one-way encryption and is more secure than MD5.

Re: Security and JavaScript
by thraxil (Prior) on Apr 29, 2003 at 00:56 UTC

    if i'm reading it right, this doesn't sound all that solid to me. what's keeping a password guessing bot from just mimicking all of the javascript's functionality? especially since it looks like all of your 'secret' strings are sent across the network in cleartext.

    really, the only way to protect yourself at all from a brute force guesser is to cut off the IP after a couple incorrect guesses. even then, a determined attacker with access to a lot of IP addresses and in no hurry could still be dangerous.

    another big problem i see with your approach is just the amount of complexity involved. cryptographic protocols are exceedingly hard to design and implement correctly. the more complex it is, the easier it is to screw up one little piece and comprimise the whole system.

    if your client is going to insist on using weak, guessable passwords, probably the best thing you could do would be to implement a public key system. the client creates a keypair on their machine, encrypting the private key with whatever weak password they want to use, and gives you a copy of the public key. then the server generates a random challenge string, encrypts it with their public key and sends it to the browser. the user copies and pastes the ciphertext into a pgp app, decrypts it and pastes the results back into a web-form. the server checks it and sets a session cookie if it matches the original. this would still have to be done over SSL or the session could be hijacked later on by someone snooping the network. as long as the client's machine or private key isn't comprimised, you're ok.

    the simplest and most highly recommended solution though is to just convince your client that they need to use good passwords and then use regular HTTP authentication over SSL.

    anders pearson

      Please read the post I put above this one

      Thank you for your help. Yes I am already using SSL encryption but that doesn't stop someone from getting into the page and trying passwords and yes I will block IP adresses after 3 unsucessful tries at a password

      To clarify my original posting (since my friend Ryan just informed me to use html tags in my positings this should read better) I am NEVER sending the secret code as plain text. The secret code is SHA1 hashed with the randomly generated number received from the server. So even if the session id is found by a packet sniffer then it wouldn't do any good since it is only for this session (the session would be linked to the client's ip address in addition)

      Anyway the only security purpose this really servers is to indentify the remote user's computer.

      In simplest terms, if you are the client and I am the server, it is like are you who you say you are? And if so hash this random number with the secret code and send me the result

      Then I will do the same with what I know to be the secret code and with the random string I just generated and if our two hashes match I will let you access this part of my site

      If you want more implentation details of the javascript see this page

      If you were curious as well I am using mod_perl with CGI::Session using /IP-match/ on (I prefer CGI session to Apache::Session, although both are good, I just have more experience with CGI::Session)

        ok, is the idea that the HTML file with the 'secret' string is sitting on the client's hard-drive being accessed as a local file and presumably previously copied there in some secure manner? that wasn't clear to me from your initial description but it sounds like that must be what you're doing. (i had been assuming that all files involved were sent over from the webserver).

        if this is the case, then i agree with jonnyfolk and perrin below that having the client enter a password is somewhat superflous. you already have a shared secret, just use it as the password over an SSL connection. don't bother with javascript.

        anders pearson

Re: Security and JavaScript
by perrin (Chancellor) on Apr 29, 2003 at 05:26 UTC
    I don't understand why JavaScript is involved in this at all. Why are you not simply setting a cookie that you can verify from the server? What would stop someone from reading the secret word in the HTML, along with all the code to generate a correct hash?
Re: Security and JavaScript
by cLive ;-) (Prior) on Apr 29, 2003 at 01:24 UTC

    The reason I am not just using password security is that I am doing this for a client who has trouble remembering passwords so he keeps his passwords simple

    /me re-reads the post and sees this is already done - lol. But, I think your solution is a little overkill. If you're going to all the trouble of encrypting a random string, why bother with the password at all? When you send the request to the server for the random string, why not just lock the login to that IP. That, combined with the existing encryption ideas would surely be enough. (unless there are other people with access to the client's machine, I suppose :)

    If you just have the one client who wants access, why not create an html page with a form that submits to the site. Include a nice long hidden field in the form (a long password), or use JS to set a local cookie before login. Then simply get the client to save the html file on their hard drive and open the local page when logging in. That way there's nothing for a bot / outsider to hit.

    .02

    cLive ;-)

      Okay this is my final post for tonight before I go play basketabll

      Your right it is a little overkill but this simply assure that someone won't just stumble upon the admistration section of the website and since the implementation of this sounds a lot more difficult that it actually is (I have it done pretty much) I understand your thought. TY for the input

Re: Security and JavaScript
by jonnyfolk (Vicar) on Apr 29, 2003 at 07:29 UTC
    If you are doing all this for a client who doesn't like long passwords, and you are giving him an HTML file to sit on his computer, why not just embed the 'secret code' into the password field (you get to choose the password) and the guy just submits the password you chose from the HTML file. No extra scripting necessary :)