SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Sep 2005
    Posts
    103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    secure ****-clone voting

    Hi all, I'm writing a script to allow users to vote on news articles, and I'm unsure how to go about securing the vote button from double voting, or other's voting in other's names.

    the script is simple at the moment, it simply passes the article id and user id's to in an ajax call, and then the article is promoted. But, This certainly can't be secure as it would seem to me that someone could find a way of changing the user id, so the vote would count in another's name. I've noticed that **** and pligg both are passing md5 hash's around in the ajax calls, but as to how this is being used to secure the voting process is beyond me.

    I'll continue to ponder this, but any info or advice would be well appreciated.

    thanks,

  2. #2
    SitePoint Zealot
    Join Date
    Sep 2005
    Posts
    103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    erm... **** is sitepoint slang for d i g g.

    curious why it should be parsed out though... over-modding is a baaaaad thing IMO

  3. #3
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Keep the user's ID in a session rather than the URL; the user can't modify it.

    As for ****... they have this policy where if your forum is used for "**** me and I'll **** you" type activity, they'll ban your entire domain. SitePoint doesn't want its domain banned. Moderators can't catch everything instantly.

  4. #4
    SitePoint Zealot
    Join Date
    Sep 2005
    Posts
    103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks Dan..

    unfortunately I'm using ajax to do the "promoting". so it means that user sessions aren't available to the php document in question, and must be submitted via javascript call, and hence must be dumped into html the document.. I do not know if it is possible to change page content inside the browser (maybe with grease monkey?), so I'm not even sure if this is something to be concerned with... but currently I've assigned security keys to each user which get passed along with the id on each story promotion request, which would prevent a hacker from simply having to change the user id from 6 to 7, and getting to vote twice.. he would need to know the users id and corresponding security key to exploit it..

    i suppose it'll work, unless anyone can see a flaw with this...

    thanks. I'll show it off when it's done innit.
    Last edited by grafenberg; Dec 20, 2006 at 15:39.

  5. #5
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Your JavaScript call which saves the vote sends an HTTP request to a PHP script. That PHP script has access to the session, which contains the user ID from when the user initially logged in. Therefore you do have access to the user ID and the entire process is secure. The user ID, nor any other identifying key, need not appear anywhere in the HTML of the page to be tracked.

    If necessary I could write some example code, but it's pretty straightforward. Your XMLHttpRequest is simply something like http://www.example.com/savevote.php?...&vote=thumbsup. The savevote.php file reads the user ID from $_SESSION where it was placed when the user logged in at an earlier time. That allows you to prevent duplicate voting by checking if a vote already exists by that user ID for that article (by either a SELECT query or putting a UNIQUE constraint on the column forcing another vote's INSERT query to fail).


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •