Skip to content

Commit f3361a0

Browse files
authored
Merge pull request #888 from pradnya-orchestral/OWASP_timeInactivity
If User is inactive for longer time the user should get logout from application
2 parents 7205c66 + bb970a9 commit f3361a0

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ angular.module('main')
2323
// render and likely freeze the browser window for deeply nested JSON object results.
2424
// Value is in bytes.
2525
// max_execution_result_size_for_render: 200 * 1024,
26-
//
26+
// set application inactivity time default for 2 hr, here it is in seconds.
27+
// application_inactivity_time : 7200,
2728
// Set to true to display StackStorm and st2web version in the header
2829
//show_version_in_header: false;
2930

modules/st2-menu/menu.component.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import api from '@stackstorm/module-api';
2222
import Link from '@stackstorm/module-router/link.component';
2323

2424
import componentStyle from './style.css';
25+
const APPLICATION_INACTIVITY_TIME = 7200; // 2 hr time here it is in seconds
2526

2627
class Icon extends React.Component {
2728
static propTypes = {
@@ -63,17 +64,42 @@ export default class Menu extends React.Component {
6364
style: componentStyle,
6465
}
6566

66-
componentDidMount() {
67+
componentDidMount () {
68+
this.idleLogout();
6769
window.addEventListener('storage', this.storageChange());
68-
}
6970

71+
}
72+
7073
componentWillUnmount() {
7174
window.removeEventListener('storage',this.storageChange());
7275
}
7376

7477
docsLink = 'https://docs.stackstorm.com/'
7578
supportLink = 'https://forum.stackstorm.com/'
7679

80+
idleLogout() {
81+
let t;
82+
window.onload = resetTimer;
83+
window.onmousemove = resetTimer;
84+
window.onmousedown = resetTimer; // catches touchscreen presses as well
85+
window.ontouchstart = resetTimer; // catches touchscreen swipes as well
86+
window.onclick = resetTimer; // catches touchpad clicks as well
87+
window.onkeydown = resetTimer;
88+
window.addEventListener('scroll', resetTimer, true);
89+
90+
function logoutFunction() {
91+
// your logout code for too long inactivity goes here
92+
api.disconnect();
93+
window.location.reload();
94+
}
95+
96+
function resetTimer() {
97+
window.clearTimeout(t);
98+
const millisecondTime = window.st2constants.st2Config.application_inactivity_time * 1000 || APPLICATION_INACTIVITY_TIME * 1000;
99+
t = window.setTimeout(logoutFunction, millisecondTime); // time is in milliseconds,application will logout after 2 hr. We can set whatever time we want.
100+
}
101+
}
102+
77103
storageChange () {
78104
window.addEventListener('storage', (event) => {
79105
if (event.key === 'logged_in' && (event.oldValue !== event.newValue)) {

0 commit comments

Comments
 (0)