|
17 | 17 | <script><%- javascript %></script> |
18 | 18 | <link rel="icon" type="image/png" href="<%- cdn %><%- countlyFavicon %>"> |
19 | 19 | <script type="text/javascript"> |
| 20 | + // Restore URL hash preserved during OAuth2 authentication flow |
| 21 | + // The hash was saved in sessionStorage on the login page before OAuth2 redirect. |
| 22 | + // After successful authentication and redirect back to the dashboard, we restore it here |
| 23 | + // so users land on the page they originally intended to visit (e.g., #/analytics/sessions). |
| 24 | + // NOTE: The key 'countly_oauth_return_hash' must match the key used in login.html |
| 25 | + (function() { |
| 26 | + var OAUTH_HASH_KEY = 'countly_oauth_return_hash'; |
| 27 | + try { |
| 28 | + var savedHash = sessionStorage.getItem(OAUTH_HASH_KEY); |
| 29 | + if (savedHash && savedHash.length > 1) { |
| 30 | + // Clear the saved hash immediately to prevent reuse |
| 31 | + sessionStorage.removeItem(OAUTH_HASH_KEY); |
| 32 | + |
| 33 | + // Validate hash format: must start with # and contain only safe URL characters |
| 34 | + // Allow: alphanumeric, forward slash, hyphen, underscore, dot, question mark, equals, ampersand, percent |
| 35 | + var hashPattern = /^#[a-zA-Z0-9\/_\-\.?=&%]+$/; |
| 36 | + |
| 37 | + if (hashPattern.test(savedHash)) { |
| 38 | + // Additional check: ensure no javascript: or data: protocol |
| 39 | + var lowerHash = savedHash.toLowerCase(); |
| 40 | + if (lowerHash.indexOf('javascript:') === -1 && |
| 41 | + lowerHash.indexOf('data:') === -1 && |
| 42 | + lowerHash.indexOf('<script') === -1) { |
| 43 | + // Restore the hash to the current URL |
| 44 | + if (window.location.hash !== savedHash) { |
| 45 | + window.location.hash = savedHash; |
| 46 | + } |
| 47 | + } |
| 48 | + } |
| 49 | + } |
| 50 | + } catch(e) { |
| 51 | + // Ignore if sessionStorage is not available |
| 52 | + } |
| 53 | + })(); |
| 54 | + |
20 | 55 | //no one should really need this |
21 | 56 | window.eval = function(){ |
22 | 57 | console.log("eval not available"); |
|
0 commit comments