Avatar of srtindall
srtindall
 asked on

How do I kill a session when closing a tab without logging off?

Have a web app open with sensitive data in a browser tab.  The user closes the tab without logging off of the application.  The browser is still open with other tabs.  I can go onto another tab and select "reopen closed tabs" & my sensitive data is returned to me with the session still live.

We've tried the below suggestions, however, this is not working as needed.

http://stackoverflow.com/questions/1921941/close-kill-the-session-when-the-browser-or-tab-is-closed

http://stackoverflow.com/questions/19582615/end-session-on-browser-tab-close?answertab=active#tab-top

http://forums.asp.net/t/1527772.aspx?Kill+session+whether+user+closes+tab+or+closes+browser

http://yuvrajingale.wordpress.com/2013/01/23/how-to-destroy-session-when-users-close-the-browser-tab-in-php/
Web Development SoftwareSecurity

Avatar of undefined
Last Comment
McKnife

8/22/2022 - Mon
HainKurt

on close show a message and force user to click logout!
HainKurt

or like this

$(window).unload(function() {
    var answer=confirm("Are you sure you want to leave?");
if(answer){
    //ajax call here -- call your logout.aspx
    }
});


or just call logout...

$(window).unload(function() {
    //ajax call here -- call your logout.aspx
    }
});
ajeab

for IE
try
setting --> Advanced --> under Browsing section, uncheck "reuse windows for launching shortcut" ,

under Security section "donot save encrypted pages to disk" check
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
HainKurt

ajeab, this is webapp and author wants to control this...
not trying to force all users do some changes to their browsers, which is not possible...
srtindall

ASKER
This code works when closing the browser window, but doesn't work on closing just the tab.

Any solutions for closing the tab with the browser window staying open?
ASKER CERTIFIED SOLUTION
HainKurt

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Gary

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
HainKurt

+1 Gary

Apart from that it's a bad idea anyway - what if I open a link in a new tab and close the old tab or the new one - then you kill my session and I lose everything.

sometimes i duplicate a page and close one randomly later :) if you implement such thing, i will get really mad...
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
HainKurt

just did a test with my bank site...

logged in, duplicated page (my accounts), closed randomly one of them... no issues... they work fine...

Then i copied url and closed all bank sites (tabs) and opened a new tab, and pasted the url

voila! page is there!...

summary: put a warning on your page, saying

BEWARE!!! Just do not close the site! use LOGOUT! or else your data may be stolen (public computers)
McKnife

What are you trying to protect against? Someone establishes a session, I guess https is used. If he closes the browser, the session is gone. If he closes only the tab, it is not gone, that's it.
So you fear that he closes the tab and leaves his computer unattended and unlocked afterwards? He should lock his computer.
srtindall

ASKER
Thanks for the Beware comment, already working down that path.

Not sure I get the "it's a bad idea"

I'm trying to protect PHI data.  Can't control if the end user locks his/her computer, especially on a public computer.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
HainKurt

even the big banks do not do such thing, so why worry? educate your users...
also, keep your session timeout short (5 min for example) instead of default (15-20 min)
Gary

The best thing you can do is adopt a 10 minute session (Hain says 5 minutes, I think that is too short - I know I could spend 10 minutes looking through a statement)
And here is the biggie no "Remember me".
If people are stupid enough to use a public computer and not do a complete log out well you can't fix stupid.

If someone want's to do anything other than look at things, say change the password then you ask them to enter the password again - this can eliminate the kind of hacking I think you are trying to prevent.  It's an hassle but is quite widely implemented where you are transferring money, changing the password etc to prevent any possibility of someone else using the account.
McKnife

"I'm trying to protect PHI data.  Can't control if the end user locks his/her computer, especially on a public computer" - and you are sure this type of data may even be viewed on public computers? No matter how the login/logout is managed, the data is already at risk when you use an untrusted machine to view it.
You should limit the ability of viewing the data to managed computers only that have a lockscreen policy enforced. If you make it viewable from anywhere, you are at fault already. The login info could get compromised easily, screenshots could be taken, anything.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ajeab

I'm in similar situation as your.  my EHR using IE only and lot of setting has to be done.  that is why I'm now evaluate visual app (citrix xenapp, 2x, vmview)  this way you will be sure that IE session do not remain on remote computer. but it's not cheap.  you will need at minimum RDS server,  RDS client license, and couple of VMs for gateway.
McKnife