Implementing browser controls against clickjacking
Implementing browser controls against clickjacking 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 browser controls against clickjacking 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.
Note that these mechanisms are all independent of each other, and where possible more than one of them should be implemented in order to provide defense in depth.
The frame-ancestors directive can be used in a Content-Security-Policy HTTP response header to indicate whether or not a browser should be allowed to render a page in a or . Sites can use this to avoid Clickjacking attacks by ensuring that their content is not embedded into other sites.
Why it matters
Consider a realistic failure: a sensitive approval page can be framed by another site that disguises what a click will authorise.
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.
- Implementing JavaScript code in the page to attempt to prevent it being loaded in a frame (known as a "frame-buster").
- This prevents any domain from framing the content. This setting is recommended unless a specific need has been identified for framing.
- For an HTTPS page, this allows its own origin, HTTPS subdomains of somesite.com, and to frame it. The two HTTPS host expressions use the default port (443). The wildcard matches subdomains, not the bare somesite.com host; add that host explicitly if required.
- DENY, which prevents any domain from framing the content. The "DENY" setting is recommended unless a specific need has been identified for framing.
- 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.
Related issues
- Reviewing browser security headers against application requirements
- Implementing reliable CSRF protection for browser actions
- Developing browser extensions with safe permissions and messaging
Read about our methodology or contact pentested.com to discuss secure development and code review.