-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
new_audit: ensure clickjacking mitigation through XFO or CSP #16290
base: main
Are you sure you want to change the base?
new_audit: ensure clickjacking mitigation through XFO or CSP #16290
Conversation
…ve self or none, but any value to relax the framing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you revert your changes to cli/test/smokehouse/frontends/smokehouse-bin.js
/** Title of a Lighthouse audit that evaluates whether the set CSP or XFO header is mitigating Clickjacking attacks. "XFO" stands for "X-Frame-Options". "CSP" stands for "Content-Security-Policy". */ | ||
title: 'Ensure Clickjacking mitigation through XFO or CSP.', | ||
/** Description of a Lighthouse audit that evaluates whether the set CSP or XFO header is mitigating Clickjacking attacks. This is displayed after a user expands the section to see more. No character length limits. The last sentence starting with 'Learn' becomes link text to additional documentation. "XFO" stands for "X-Frame-Options". "CSP" stands for "Content-Security-Policy". */ | ||
description: 'Deployment of either the X-Frame-Options or Content-Security-Policy (with the frame-ancestors directive) header will prevent Clickjacking attacks. While the XFO header is simpler to deploy, the CSP header is more flexible. [Learn more about mitigating Clickjacking with XFO and CSP](https://developer.chrome.com/docs/lighthouse/best-practices/clickjacking-mitigation).', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
description: 'Deployment of either the X-Frame-Options or Content-Security-Policy (with the frame-ancestors directive) header will prevent Clickjacking attacks. While the XFO header is simpler to deploy, the CSP header is more flexible. [Learn more about mitigating Clickjacking with XFO and CSP](https://developer.chrome.com/docs/lighthouse/best-practices/clickjacking-mitigation).', | |
description: 'The `X-Frame-Options` (XFO) header or the `frame-ancestors` directive in the `Content-Security-Policy` (CSP) header can be used to mitigate clickjacking attacks. While the XFO header is simpler to deploy, the `frame-ancestors` CSP directive is more flexible. [Learn more about mitigating clickjacking](https://developer.chrome.com/docs/lighthouse/best-practices/clickjacking-mitigation).', |
Also what makes the XFO simpler to deploy? Seems like they have the same level of complexity to deploy (just modify header values).
/** Description of a Lighthouse audit that evaluates whether the set CSP or XFO header is mitigating Clickjacking attacks. This is displayed after a user expands the section to see more. No character length limits. The last sentence starting with 'Learn' becomes link text to additional documentation. "XFO" stands for "X-Frame-Options". "CSP" stands for "Content-Security-Policy". */ | ||
description: 'Deployment of either the X-Frame-Options or Content-Security-Policy (with the frame-ancestors directive) header will prevent Clickjacking attacks. While the XFO header is simpler to deploy, the CSP header is more flexible. [Learn more about mitigating Clickjacking with XFO and CSP](https://developer.chrome.com/docs/lighthouse/best-practices/clickjacking-mitigation).', | ||
/** Summary text for the results of a Lighthouse audit that evaluates whether the set CSP or XFO header is mitigating Clickjacking attacks. This is displayed if there is neither a CSP nor XFO header deployed. "XFO" stands for "X-Frame-Options". "CSP" stands for "Content-Security-Policy". */ | ||
noClickjackingMitigation: 'No Clickjacking mitigation found.', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
noClickjackingMitigation: 'No Clickjacking mitigation found.', | |
noClickjackingMitigation: 'No XFO or CSP frame-ancestors found', |
// If there is none of the two headers, return early. | ||
if (!rawXfo.length && !cspHeaders.length) { | ||
return { | ||
score: 0, | ||
results: [{ | ||
severity: str_(i18n.UIStrings.itemSeverityHigh), | ||
description: str_(UIStrings.noClickjackingMitigation), | ||
directive: undefined, | ||
}], | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// If there is none of the two headers, return early. | |
if (!rawXfo.length && !cspHeaders.length) { | |
return { | |
score: 0, | |
results: [{ | |
severity: str_(i18n.UIStrings.itemSeverityHigh), | |
description: str_(UIStrings.noClickjackingMitigation), | |
directive: undefined, | |
}], | |
}; | |
} |
This is redundant, if the header lists are empty we will just skip to the bottom anyway.
// Check for frame-ancestors in CSP. | ||
if (cspHeaders.length) { | ||
for (const cspDirective of cspHeaders) { | ||
if (cspDirective.includes('frame-ancestors')) { | ||
// Pass the audit if frame-ancestors is present. | ||
return {score: 1, results: []}; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Check for frame-ancestors in CSP. | |
if (cspHeaders.length) { | |
for (const cspDirective of cspHeaders) { | |
if (cspDirective.includes('frame-ancestors')) { | |
// Pass the audit if frame-ancestors is present. | |
return {score: 1, results: []}; | |
} | |
} | |
} | |
// Check for frame-ancestors in CSP. | |
for (const cspHeader of cspHeaders) { | |
if (cspHeader.includes('frame-ancestors')) { | |
// Pass the audit if frame-ancestors is present. | |
return {score: 1, results: []}; | |
} | |
} |
Summary
Adding a new audit to Ligththouse, which detects missing Clickjacking mitigation through the X-Frame-Options or Content-Security-Policy HTTP header.
Part of a larger change to introduce more similar header deployments.
Similar to the HSTS audit (#16257), the description contains a placeholder doc link until the internal doc is approved. @adamraine FYI