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

  • SEARCH
  • Home
  • 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 8808605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:39:59+00:00 2026-06-14T02:39:59+00:00

I am learning about how to prevent CSRF using anti-CSRF tokens. Essentially, the idea

  • 0

I am learning about how to prevent CSRF using anti-CSRF tokens. Essentially, the idea is to:-

1) generate a token eg Md5 or Sha1 then store this value in a session variable:-

$token = md5(uniqid(rand(), TRUE));
$_SESSION['token'] = $token;

2) All forms include this token value in a POST hidden field

<input type='hidden' name='token' value='$nonce_token' />

Eg what it would look like to user in source code:-

<input type='hidden' name='token' value='9ee66e4e63a06ee4b83a3edde4ecd587' />

3) Once form sent check POST hidden field token value matches token stored in session value

if($_POST['token']==$_SESSION['token']){...ok...}

However, this process seems a little flawed since by including the token value in a hidden POST field an attack can simply just look at the website source code to see the token and then just include this in a malicious generated POST form which my application would thus succeed once received as token value sent would match the token value in my session variable, since I essentially show the token value in my hidden field to the attacker.

Thus, my question is what is the best way around this, as a few ideas I had still seem little flawed:-

1) Using _GET instead but this still has flaws like _POST

2) Changing the token value after x minutes or each request but causes usability issues when going back in browser or fail when user filling in form and token value would become outdated compared to updated session token value as hidden token value would not have updated whilst user filling in a form.

3) Try encrypting hidden POST form token value then decrypting on sending POST but encrypting/decrypting an already hashed value seems complicated especially one way encrypted has values like MD5 etc?

Any ideas would be much appreciated.

  • 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-14T02:40:01+00:00Added an answer on June 14, 2026 at 2:40 am

    However, this process seems a little flawed since by including the token value in a hidden POST field an attack can simply just look at the website source code

    No they can’t.

    Alice runs a website. Bob visits the website. Mallory is attacking Bob’s account.

    Bob gets a nonce token when he visits Alice’s website.

    If Mallory visited the site, Mallory would get a different nonce (because Mallory would have a different session).

    If Mallory generated a form with malicious data in it (on her website) and tricked Bob into submitting it, then the nonce Mallory put in the form would not match the nonce in Bob’s session and the submission would be rejected.

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

Sidebar

Related Questions

I am learning about raw sockets. I heard that ping utility is using raw
After learning about how to print out debug messages using Visual Studio's Tracepoint feature,
i'm currently learning about sockets with using java. I'm learning about TCP sockets and
Learning about notifyAll made me question something about notify: in a typical situation we
After learning about the Action delegate in C# I've been looking for ways I
I'm learning about C++11 concurrency, where my only prior experience with concurrency primitives was
I am learning about Algebraic DTs in haskell. What I would like to do
I'm learning about the MVC architecture these days and I'm confused MVC with the
I have been learning about Delegation and Data Sources for iOS programming and need
I've been learning about divs over the past few months, and am now able

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.