Skip to main content

Double Submit Cookie

Double submit cookie is one of the prevention method for Cross-Site Request Forgery (CSRF). Same as the synchronizer token pattern, it is using a cryptographic random value to validate a request agent. However, the implementation is different since the way it is saved is dissimilar. Here, the generated token value is saved in the browser, not on the server. Therefore servers no need to save huge amounts of data. When a user makes a request, the server compared the token value in the form DOM element (in the body) and token in the cookie header of the request. 
(Click on the images to view clearly)


Source code of the implemented program can be downloaded from here.


A login page, index.html has been implemented to enroll users.



Once the user entered the credentials, the form data will be submitted to login_handler.php using POST method.


If the username and password are correct, the user session is started and the username will be assigned to the session variable 'uname'. By default, the session identifier is saved as a cookie in the browser when session_start() is activated. Then the 32-byte length random binary is created and it is converted to a hex value. The random value (CSRF token) is assigned to the variable ‘token’. Further, the token is set as a cookie in the browser by passing the parameter like, token name, token value, and life span (1 day). Then the user will be redirected to home.html. The failed logins are redirected to index.php. 


In home.html, using getCookie function, particular CSRF token value will be extracted from the cookie and the derived value is assigned to the DOM element which has id as dom_csrf.



When the user submits the home.html form, the form data will be sent to form_submit.php.


The form_submit.php checks whether the token value in cookies is available or not. At the same time, token value in the form DOM element is compared with token value in the cookie. If both the values are same, the program displays a success message. If not CSRF token not matched message will be shown when the token is mismatched or the token not exist.

Comments

Popular posts from this blog

Exploit Windows 2000 machine using the Metaspolit framework from the Kali Linux machine.

Exploit Windows 2000 machine using the Metaspolit framework from the Kali Linux machine. When the windows 2000 the machine came for public use, many vulnerabilities were identified. This was caused by the number of vulnerabilities in IIS services. Many attacks came from remote sources through the internet and there were critical flaws due to the vulnerable encryption methods. From this article how the vulnerabilities of windows would be identified using Nessus, and exploit it using Metasploit in kali machine will be described. To do it I am using my main operating system (OS) kali and virtual machine windows 2000. For that IP range of both machines should be in the same range to ensure those are in the same network. Therefore network setting was fix as bridge adaptor in windows virtual machine. Check IP of kali using ifconfig Check IP of windows using ipconfig Then Nessus vulnerability s...

Plain Blue screen - Kali Linux

When user login to the kali machine, the screen may look plain blue color without any application icon due to the Gnome corruption. To recover gnome with all previously installed packages restart the machine. Select advanced options for kali GNU /Linux Then select *Kali GNU/Linux, with Linux 4.15.0-Kali2-amd64 (recovery mode) When the terminal finish, loading the contents, type root password to log in. To recover the Gnome, Type below command in the root user terminal,       sudo dpkg --configure -a Finally, you can get your previous Kali Linux as it was.