Skip to content

Enhance email preview with external link handling and iframe support - #7

Open
projecthanif wants to merge 1 commit into
mainfrom
issue/#1
Open

Enhance email preview with external link handling and iframe support#7
projecthanif wants to merge 1 commit into
mainfrom
issue/#1

Conversation

@projecthanif

Copy link
Copy Markdown
Collaborator

This pull request improves the handling of external links in the email HTML preview, ensuring that clicking links inside the sandboxed iframe opens them in the user's default browser rather than inside the app. It also updates the test email script to include an external link for easier testing.

External link handling improvements:

  • Added a JavaScript interceptor to the email HTML preview iframe (email-html-view.blade.php) that captures clicks on external links (http(s), mailto, tel), prevents default navigation, and sends the URL to the parent window via postMessage.
  • Updated the iframe's sandbox attribute to allow scripts (but not navigation or same-origin access), and injects the interceptor script into the rendered HTML.
  • Added Alpine.js logic to listen for the postMessage event and call a Livewire method to open the link externally.

Backend support for external link opening:

  • Implemented the openExternalLink Livewire method in ViewEmail.php, which validates the URL scheme and uses the OS shell to open the link in the default browser. [1] [2]

Test email update:

  • Modified send_test_email.py to include an external link in both the plain text and HTML parts of the test email, making it easier to verify the new link handling behavior. [1] [2]

Copilot AI review requested due to automatic review settings July 25, 2026 17:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@projecthanif

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6037506bf2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

no allow-popups): the email HTML is untrusted and can't touch the app's cookies/DOM
or navigate/pop out on its own — it can only ask the parent (via the interceptor
script above) to hand a link off to the OS browser. --}}
<iframe srcdoc="{{ $previewHtml }}" class="ev-iframe" sandbox="allow-scripts"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep scripts embedded in captured emails disabled

When an HTML email contains a script that calls parent.postMessage({nativemailerPreview: true, url: 'https://…'}, '*'), this permission executes it immediately when the preview loads. The source check cannot distinguish that untrusted script from the injected interceptor because both run in the same iframe, so an attacker can invoke Shell::openExternal() without a click or repeatedly launch URLs and protocol handlers; keep untrusted scripts disabled or remove all executable email content before granting allow-scripts.

Useful? React with 👍 / 👎.

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