diff options
author | Andreas Gohr <andi@splitbrain.org> | 2021-03-04 12:48:36 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-04 12:48:36 +0100 |
commit | 86491c6cddf80057c28aea48b309b081fd8b0497 (patch) | |
tree | f7d355d6c3e4c129730ecfcabe3c7c9451448b8c /lib/scripts/behaviour.js | |
parent | a8b6eaa91e516b6cec72bd298f13432609f06881 (diff) | |
parent | b68a7721c62562cbcd3924f5a14b4df85b5b2305 (diff) | |
download | dokuwiki-86491c6cddf80057c28aea48b309b081fd8b0497.tar.gz dokuwiki-86491c6cddf80057c28aea48b309b081fd8b0497.zip |
Merge pull request #3368 from splitbrain/fix3363
do not repeat successful security checks. fixes #3363
Diffstat (limited to 'lib/scripts/behaviour.js')
-rw-r--r-- | lib/scripts/behaviour.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/scripts/behaviour.js b/lib/scripts/behaviour.js index 70b60ef9a..41702fad7 100644 --- a/lib/scripts/behaviour.js +++ b/lib/scripts/behaviour.js @@ -56,6 +56,7 @@ var dw_behaviour = { dw_behaviour.checkWindowsShares(); dw_behaviour.subscription(); dw_behaviour.pageRestoreConfirm(); + dw_behaviour.securityCheck(); dw_behaviour.revisionBoxHandler(); jQuery(document).on('click','#page__revisions input[type=checkbox]', @@ -204,6 +205,36 @@ var dw_behaviour = { } }); } + }, + + /** + * Check that access to the data directory is properly secured + * + * A successful check (a 403 error was returned when loading the image) is saved + * to session storage and not repeated again until the next browser session. This + * avoids overeager security bans (see #3363) + */ + securityCheck: function () { + var $checkDiv = jQuery('#security__check'); + if (!$checkDiv.length) return; + if (sessionStorage.getItem('dw-security-check:' + DOKU_BASE)) { + // check was already executed successfully + $checkDiv.remove(); + return; + } + + var img = new Image(); + img.onerror = function () { + // successful check will not be repeated during session + $checkDiv.remove(); + sessionStorage.setItem('dw-security-check:' + DOKU_BASE, true); + } + img.onload = function () { + // check failed, display a warning message + $checkDiv.html(LANG.data_insecure); + $checkDiv.addClass('error'); + } + img.src = $checkDiv.data('src') + '?t=' + Date.now(); } }; |