Safeguard
Security Guides•

Which third-party scripts belong on a patient portal page?

Allow almost none on pages behind login. Use an allowlist, sandbox what you must keep, lock down the tag manager and prefer a collector you control.

Safeguard Security Team
3 min read

Almost none. On pages behind login, allow only scripts you host or have reviewed and pinned, sandbox anything else in an iframe, restrict the tag manager and send analytics through a collector you control. A third-party script runs with the same access as your own code and can see what the page shows.

Why portals are different

A marketing page and a patient portal have different risk. A script on the portal can read what is on screen, including names, appointment details and messages, and it can send that anywhere it likes. A tag manager lets non-engineers add such scripts without a code review.

The OWASP Third Party JavaScript Management Cheat Sheet gives specific controls. It suggests loading vendor code from another domain inside an iframe, which keeps it away from the host page's DOM and cookies, and using the sandbox attribute to restrict it. It also advises Subresource Integrity with crossorigin set to anonymous, and notes that tag-manager delivered code is hard to pin because content can change without a deployment.

Allowlist by page type

Page typeThird-party scripts
Public marketingReviewed, limited
Sign in and sign upMinimal, ideally none
Behind loginNone by default
Payment or identity stepsNone

Write this table into your engineering standards and check it in code review.

Controls to apply

  1. Keep a written inventory of every script, who owns it and why it is there.
  2. Where a vendor script must remain, load it in a sandboxed iframe from a separate domain and pass only the values it needs through postMessage, checking the message origin.
  3. Add Subresource Integrity hashes where the vendor allows it.
  4. In the tag manager, disable custom HTML and custom JavaScript tags, limit tags to data layer values and require two-factor authentication.
  5. Treat tag manager publishing like a production deployment: review changes as application code.
  6. Define a host-controlled data layer with only the values you choose to expose.
  7. Route analytics through a collector you control, with a fixed event schema.

The cheat sheet notes a data layer is not a sandbox, so the data layer alone does not isolate scripts running in the page.

Check what is really loading

Open a portal page in a browser with network inspection and list every domain contacted. Compare it with the inventory. The difference is your unknown risk. Repeat after each marketing change.

Where Safeguard fits

Safeguard scans the packages in your own front end, and its gates can require review of new dependencies. Auditing which third-party scripts load at runtime is a separate task, and the steps above cover it. A free scan is available at gold.safeguard.sh/scan.

Quick check

Is Subresource Integrity enough on its own?

No. It pins a file, but it does not help with tag manager content that changes, and it does not limit what an approved script can do.

Who should approve a new portal script?

An engineer and a privacy owner together, with the data flow written down.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.