1. function ensureSessionCookieGuard() {
  2. // Check if session cookies are enabled in the browser.
  3. const sessionCookiesEnabled = document.cookie.indexOf('sessionid=') !== -1;
  4. // If session cookies are not enabled, display a message and prevent execution.
  5. if (!sessionCookiesEnabled) {
  6. alert('Session cookies are required for this script to function. Please enable them in your browser settings.');
  7. return false; // Prevent execution
  8. }
  9. // Function to check for manual overrides of session cookie values.
  10. function checkSessionCookieOverrides() {
  11. // Get the current session cookie value.
  12. const sessionId = document.cookie.split('; ').find(cookie => cookie.startsWith('sessionid='))?.split('=')[1];
  13. //If sessionId is undefined, it means there is no session cookie.
  14. if (!sessionId) {
  15. return false;
  16. }
  17. // Check if the session cookie value has been manually overridden.
  18. // You can customize this check based on your specific override mechanism.
  19. // For example, checking for a specific attribute or value.
  20. if (sessionId === 'OVERRIDDEN_VALUE') {
  21. alert('Session cookie has been manually overridden. Script will not proceed.');
  22. return false; // Prevent execution
  23. }
  24. return true; // No override found, proceed.
  25. }
  26. // Check for overrides before each execution.
  27. if (!checkSessionCookieOverrides()) {
  28. return false; // Prevent execution
  29. }
  30. // Allow script execution if session cookies are enabled and no overrides are found.
  31. return true;
  32. }

Add your comment