Secure development

Controlling the trust and privileges of third-party JavaScript

Browser origins: browser, code, gate arranged to illustrate controlling the trust and privileges of third-party javascript.

Controlling the trust and privileges of third-party JavaScript connects a security requirement to the behaviour of a real feature. The relevant controls need to remain effective across custom code, integrations and the production configuration. Understanding controlling the trust and privileges of third-party JavaScript helps establish which security property the feature needs and where that property is actually enforced.

What does this involve?

Browser security is influenced by origins, embedded content, messaging and the way returned data is interpreted. A server can make a correct decision while client-side code later exposes the result to an unintended page or execution context.

Tags, aka marketing tags, analytics tags etc. are small bits of JavaScript on a web page. They can also be HTML image elements when JavaScript is disabled. The reason for them is to collect data on the web user actions and browsing context for use by the web page owner in marketing.

Analytics tags send information back to a marketing information database; information like what user action was just taken, browser metadata, location information, page metadata etc. The rationale for analytics tags is to provide data from the user's browser DOM to the vendor for some form of marketing analysis. This data can be anything available in the DOM. The data is used for user navigation and clickstream analysis, identification of the user to determine further content to display etc., and various marketing analysis functions.

Why it matters

Consider a realistic failure: a third-party script receives access to private page content and user actions far beyond its advertised purpose.

A browser trust failure can affect signed-in users, private responses or actions taken with a user's session. The assessment should identify the relevant browser behaviour and the server-side permissions that remain in force.

Implementation guidance should be applied to a real feature and its deployment. Framework defaults, custom handlers and integrated services all influence whether the intended protection remains effective.

How penetration testers check for it

Trace the relevant feature from its entry point to the data or operation it protects, including custom code and alternate paths.

  • Map trusted origins, embedded resources and messaging relationships.
  • Review response policies and actual browser behaviour.
  • Trace untrusted data into rendering and navigation.
  • Check credentialed requests and sensitive state changes.

How to fix it

Use the appropriate maintained mechanisms and verify the result in the actual production configuration.

  • In-house script mirroring (to prevent alterations by 3rd parties),.
  • Secure transmission of the third-party code (to prevent modifications while in-transit) and various types of sandboxing. See below for more details.
  • Change what DOM object data is read, and when, to send to the vendor.
  • Use a host-defined data layer to limit the data intended for collection. This agreement does not restrict the privileges of JavaScript executing in the page.
  • Validate messaging origins and intended recipients.
  • Retain independent server-side identity and permission checks.

A policy finding needs application context. The absence of a particular header or browser feature is not, by itself, proof that protected data can be accessed.

Recheck the changed behaviour against the original failure conditions and the legitimate user journey. Keep enough evidence to show which release and configuration were verified, and include related entry points that depend on the same security decision.

Read about our methodology or contact pentested.com to discuss secure development and code review.

See your first test report this week.

Book a 30 minute demo. We will verify one of your targets with you and run a test against it, so you can judge the results on your own systems.

Book a demo