-
Notifications
You must be signed in to change notification settings - Fork 25
DP-41580-a11y-fix-editor-high-zoom #3105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
clairesunstudio
wants to merge
12
commits into
develop
Choose a base branch
from
DP-41580-a11y-fix-editor-high-zoom
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3b3f4fd
add js override
clairesunstudio 557165b
add overlay and halts scrolling when menu is open
clairesunstudio 8b6470d
wip
clairesunstudio 639132d
Merge branch 'develop' into DP-41580-a11y-fix-editor-high-zoom
clairesunstudio c78e92d
Merge branch 'develop' into DP-41580-a11y-fix-editor-high-zoom
clairesunstudio 19d5e37
fix css
clairesunstudio 618275a
wip
clairesunstudio df600cd
fix inconsistent behavior after user clicking on the overlay to close…
clairesunstudio d941c53
cleanup console logs and unused code
clairesunstudio f558968
add back drupal tool bar close
clairesunstudio 17546b4
clean up
clairesunstudio 4c823a6
Merge branch 'develop' into DP-41580-a11y-fix-editor-high-zoom
clairesunstudio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
docroot/themes/custom/mass_admin_theme/css/overrides/toolbar-zoom-override.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /* Toolbar tray overlay */ | ||
| .toolbar-tray.is-active.toolbar-tray-vertical > nav.toolbar-lining { | ||
| padding-bottom: 60px; | ||
| } | ||
|
|
||
| html body .toolbar-tray-overlay { | ||
| position: fixed; | ||
| top: 0; | ||
| left: 0; | ||
| width: 100%; | ||
| height: 100%; | ||
| background-color: rgba(0, 0, 0, 0.5); | ||
| z-index: 500; | ||
| opacity: 0; | ||
| visibility: hidden; | ||
| transition: opacity 0.3s ease, visibility 0.3s ease; | ||
| cursor: pointer; | ||
| display: block; | ||
| } | ||
|
|
||
| html body .toolbar-tray-overlay.active { | ||
| opacity: 1; | ||
| visibility: visible; | ||
| } | ||
|
|
||
| /* Prevent page scrolling when toolbar tray is open */ | ||
| html body.toolbar-tray-open { | ||
| overflow: hidden; | ||
| height: 100vh; | ||
| position: fixed; | ||
| width: 100%; | ||
| } |
112 changes: 112 additions & 0 deletions
112
docroot/themes/custom/mass_admin_theme/js/toolbar-zoom-override.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| (function ($, Drupal) { | ||
| "use strict"; | ||
|
|
||
| /** | ||
| * Add overlay when toolbar tray is active | ||
| */ | ||
| Drupal.behaviors.toolbarTrayOverlay = { | ||
| attach: function (context, settings) { | ||
| // Only run once on document | ||
| if (context !== document) { | ||
| return; | ||
| } | ||
|
|
||
| // Create overlay element | ||
| const overlay = $('<div class="toolbar-tray-overlay"></div>'); | ||
|
|
||
| if (!$(".toolbar-tray-overlay").length) { | ||
| $("body").append(overlay); | ||
| } | ||
|
|
||
| // Function to show overlay and prevent scrolling | ||
| function showOverlay() { | ||
| $(".toolbar-tray-overlay").addClass("active"); | ||
| $("body").addClass("toolbar-tray-overlay-active"); | ||
| } | ||
|
|
||
| // Function to hide overlay and restore scrolling | ||
| function hideOverlay() { | ||
| $(".toolbar-tray-overlay").removeClass("active"); | ||
| $("body").removeClass("toolbar-tray-overlay-active"); | ||
| } | ||
|
|
||
| // Function to close the toolbar tray | ||
| function closeToolbarTray() { | ||
| // Manually removing active classes interferes with Drupal's toolbar toggle mechanism | ||
| // Find the active toolbar tab and simulate a click to close it | ||
| const activeTab = $(".toolbar-bar .toolbar-tab.is-active .toolbar-item"); | ||
|
|
||
| if (activeTab.length > 0) { | ||
| activeTab.trigger("click"); | ||
| } else { | ||
| // Fallback: try to use Drupal's toolbar model if available | ||
| if (Drupal.toolbar && Drupal.toolbar.models && Drupal.toolbar.models.toolbarModel) { | ||
| Drupal.toolbar.models.toolbarModel.set('activeTab', null); | ||
| } | ||
| } | ||
|
|
||
| hideOverlay(); | ||
| } | ||
|
|
||
| // Check toolbar state based on body class | ||
| function checkToolbarState() { | ||
| const bodyHasTrayOpen = $("body").hasClass("toolbar-tray-open"); | ||
|
|
||
| if (bodyHasTrayOpen) { | ||
| showOverlay(); | ||
| } else { | ||
| hideOverlay(); | ||
| } | ||
| } | ||
|
|
||
| // Handle clicks on navigation links within the toolbar tray | ||
| // When user navigates to a different page, the toolbar tray should close automatically | ||
| document.addEventListener('click', function(e) { | ||
| // Check if click is inside toolbar tray | ||
| const toolbarTray = e.target.closest('.toolbar-tray'); | ||
| if (!toolbarTray) return; | ||
|
|
||
| // Check if click is on a link | ||
| const link = e.target.closest('a'); | ||
| if (!link) return; | ||
|
|
||
| const systemPath = link.getAttribute('data-drupal-link-system-path'); | ||
| const role = link.getAttribute('role'); | ||
|
|
||
| // Check if the link is an actual nav link | ||
| if (role !== "button" && systemPath && systemPath.trim() !== "") { | ||
| closeToolbarTray(); | ||
| } | ||
| }, true); | ||
|
|
||
| // Handle overlay click to close tray | ||
| $(document).on("click", ".toolbar-tray-overlay.active", function (e) { | ||
| console.log("Overlay clicked"); | ||
| e.preventDefault(); | ||
| e.stopPropagation(); | ||
| closeToolbarTray(); | ||
| }); | ||
|
|
||
| // Monitor body class changes using MutationObserver (AFTER click handlers) | ||
| const observer = new MutationObserver(function (mutations) { | ||
| mutations.forEach(function (mutation) { | ||
| if (mutation.type === "attributes" && mutation.attributeName === "class") { | ||
| checkToolbarState(); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| // Start observing body class changes | ||
| observer.observe(document.body, { | ||
| attributes: true, | ||
| attributeFilter: ["class"], | ||
| }); | ||
|
|
||
| // Initial check on page load | ||
| setTimeout(function () { | ||
| checkToolbarState(); | ||
| }, 500); | ||
|
|
||
| }, | ||
| }; | ||
| })(jQuery, Drupal); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File: toolbar-zoom-override.js | Checkov ID: CKV3_SAST_74
How To Fix
const trustedOrigin = 'https://trusted.com';
window.contentWindow.postMessage(data, trustedOrigin);
window.addEventListener('message', function(event) {
if (event.origin !== trustedOrigin) return;
// Process event.data after verifying event.origin
}, false);
Description
CWE:
CWE-345: Insufficient Verification of Data AuthenticityOWASP:
A01:2021-Broken Access ControlIn web applications, the
postMessagemethod and theaddEventListenerformessageevents are used to facilitate cross-origin communication. When misconfigured, these can lead to security vulnerabilities such as data leakage or unauthorized actions.One common vulnerability arises when using the wildcard origin (
*) with thepostMessagemethod. This allows any website to receive the message, potentially leading to sensitive information being exposed.Similarly, not verifying the origin of the message in an
addEventListenerhandler can lead to processing messages from malicious sources.For example, vulnerable code might look like: