Skip to content
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

Add header documentation with mobile preview #418

Merged
merged 7 commits into from
Mar 7, 2024
Merged

Conversation

aduth
Copy link
Member

@aduth aduth commented Mar 5, 2024

🛠 Summary of changes

This adds a new documentation page preview for the Header component, in response to a bug which surfaced in 18F/identity-dashboard#748 (comment) related to active hover states for dropdown navigation links.

This doesn't actually fix the issue addressed in the comment above, and instead is limited to just adding a page to the internal documentation.

Notably, this includes a live, simulated mobile preview using an iframe receiver communicated using postMessage. For the security-minded, this should probably raise some hairs, though (a) there is protection to ensure messages are only received from the same domain, (b) this site is not publicly hosted anywhere at the moment, and (c) the site does not store any valuable data which would be worth targeting. Edit: After ace14d0, this was updated to use a simple static page as the frame source.

📜 Testing Plan

  1. Locally, run npm start
  2. Visit http://localhost:4000/header/

👀 Screenshots

Example mobile preview:

image

docs/_includes/helpers/mobile-embed.html Outdated Show resolved Hide resolved
Comment on lines 24 to 27
const replacement = document.createElement('script');
replacement.innerHTML = script.innerHTML;
script.parentNode.replaceChild(replacement, script);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know your original comment mentioned this PR should raise some security eyebrows... just wanted to confirm yes eyebrows raised

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, on this code in particular, it's strange that browsers don't evaluate dynamically inserted script tags, while seemingly having no issue with inserting something equally exploitable like <img onload="somejavascript">.

An alternative approach could be to have just a standalone HTML page that already has the component markup in it, though that might end up with a lot more duplication, especially if we wanted to use it for more components.

I might time-box and see if I can put something together for that and what it ends up looking like. I tried in an earlier iteration and had some trouble, but I think I was fighting more with Jekyll than the approach itself.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For what it's worth, I've implemented something like this in the past and had previously spent a lot of time verifying the concept as safe, even with untrusted content in a secure context.

Although now that I write this, I probably need to harden this a bit more for the implementation to be truly safe (specifically iframe sandbox attribute). I'll see where I end up with my timeboxed experimentation whether this is an approach we go with.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in ace14d0 to avoid the postMessage communication and dynamic script insertion, and instead using a simple static page for the frame.

@aduth
Copy link
Member Author

aduth commented Mar 7, 2024

Visual regression failure is expected, since we're adding a new link to the sidebar navigation.

@aduth aduth merged commit 9e0fdf5 into main Mar 7, 2024
3 of 4 checks passed
@aduth aduth deleted the aduth-header-preview branch March 7, 2024 13:41
@aduth aduth mentioned this pull request Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants