LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-11-2021, 08:53 AM   #1
rblampain
Senior Member
 
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 11
Posts: 1,289

Rep: Reputation: 52
How can I control the effect of browser back button?


I have an HTML page containing a number of form fields but containing absolutely no user identification as the submission of the form must be anonymous.
When submitted, it calls a CGI script that creates and returns another HTML page with one more unique value (a random passphrase) besides summarizing the entries made in the first form for confirmation.
Clicking the browser back button from this second page returns the visitor to the reset first page allowing to reenter values, generating another "one more unique value" and the cycle can be repeated indefinitely.
However, because files have already been created on server according to it, I need that "one more unique value" to remain unchanged which necessitates skipping part of the code in CGI script when the value exists on subsequent visits.
I can only rely on that "one more unique value" to prevent duplication/multiplication of submitted forms.

Although no expert at it, I am aware of Javascript localStorage which could help.
Another solution would be an added hidden input field but this needs a recorded unique value in the first HTML page before being "downloaded" by the browser but I can not figure what the easiest solution to this problem could be.
I thought I should find it solved on Google but there is absolutely nothing similar or I am not Googling the right keywords.

Can anyone make a suggestion?

Thank you for your help.
 
Old 03-11-2021, 09:50 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,759

Rep: Reputation: 5930Reputation: 5930Reputation: 5930Reputation: 5930Reputation: 5930Reputation: 5930Reputation: 5930Reputation: 5930Reputation: 5930Reputation: 5930Reputation: 5930
One suggestion would be to use a session variable. Each page needs to start the session and the first would check to see if it exists and maybe pass a hidden field.
 
1 members found this post helpful.
Old 03-11-2021, 10:36 AM   #3
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,616

Rep: Reputation: 2555Reputation: 2555Reputation: 2555Reputation: 2555Reputation: 2555Reputation: 2555Reputation: 2555Reputation: 2555Reputation: 2555Reputation: 2555Reputation: 2555
Quote:
How can I control the effect of browser back button?
You don't.


Quote:
I have an HTML page containing a number of form fields but containing absolutely no user identification as the submission of the form must be anonymous.
You cannot entirely prevent duplicate submissions of truly anonymous data - if you don't know who someone is, you don't know whether they've made a submission already.

What you can do is generate your unique identifier on page 0, and traverse pages using POST form submissions only, requiring a valid unused unique identifier for both page 1 (where the data is filled in) and page 2 (where the data is saved).

If you receive a GET request for page 1/2, either display an error or goto the start of the process with a suitable message.
If you receive a POST request with an already used identifier, you either show an error or allow users to revise their submission.

Obviously don't store your unique identifiers in relation to other information (including via any logging or error tracking) - simply store the fact that they were generated, plus a reduced-resolution expiry time (e.g. always round up to the next hour), and clear them after a suitable period (maybe a couple of hours after generation, or whatever is appropriate).

This doesn't prevent deliberate attempts to submit twice - again, you can't do that with anonymous submissions - but it will help with accidental duplications.

None of this relies on LocalStorage/JavaScript/cookies/etc - it's all basic HTML and HTTP.

 
1 members found this post helpful.
Old 03-12-2021, 05:07 AM   #4
rblampain
Senior Member
 
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 11
Posts: 1,289

Original Poster
Rep: Reputation: 52
Thank you for the answers.
Quote:
This doesn't prevent deliberate attempts to submit twice
The intention is to prevent visitors who discover that pressing the back button gives them an opportunity to find another passphrase that they hope could be more easily memorised and, in the process, create hundreds of empty files on the server and hundreds of fictitious entries in a database (not to mention the security risk). Unless the confirmation of the passphrase is received, submissions go to device null, so duplicated submissions are not really the problem.
Quote:
What you can do is generate your unique identifier on page 0
I stumble on this, I have no idea how to do it. The identifier would have to be generated at the client and returned in the post so the page is identifiable from the same page visited by other clients.
AFAIK, identifiers apply only on elements, what I could not find was how to (easily) apply a unique identifier to a page, perhaps you can suggest how to Google this so I can learn what I don't know.
Providing the passphrase on page 0 reduces the problem mentioned above but does not eliminate it.

Last edited by rblampain; 03-12-2021 at 05:33 AM.
 
Old 03-14-2021, 01:04 PM   #5
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,243

Rep: Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322
Quote:
Originally Posted by rblampain View Post
reduces the problem mentioned above but does not eliminate it.
If I'm understanding what you're saying correctly, you have designed a system where "eliminating" this problem is not going to be possible.

That said:

Consider, if you haven't already, that the CGI script has access to headers.

Last edited by dugan; 03-14-2021 at 01:11 PM.
 
Old 03-14-2021, 11:45 PM   #6
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,243

Rep: Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322
Here's a key technical point that I'm not clear on.

If two people enter the exact same text into the form, do they get the same password, or do they get different passwords?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
jquery animation disjointed on browser back button secretlydead Programming 1 09-08-2011 12:15 PM
No Back Button on right click or browser qplumb Linux Mint 1 09-05-2009 06:04 PM
javascript - how do you redefine the browser's back button? BrianK Programming 1 10-26-2007 08:06 PM
Click back browser button 1inxs LQ Suggestions & Feedback 4 10-12-2005 07:07 PM
Back button to Go Back? javamdk Linux - Newbie 2 07-08-2004 11:34 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration