Skip to content
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

skip empty srcs for safe iframe srcs #3216

Merged
merged 2 commits into from
Mar 12, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions build/flaws.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,15 @@ function injectFlaws(doc, $, options, document) {
doc.flaws[flawName] &&
doc.flaws[flawName].length > 0
) {
throw new Error(
`${flawName} flaws: ${doc.flaws[flawName].map((f) => f.explanation)}`
);
// To make the stdout output a bit more user-friendly, print one warning
// for each explanation
doc.flaws[flawName].forEach((flaw, i) => {
console.warn(
i + 1,
chalk.yellow(`${chalk.bold(flawName)} flaw: ${flaw.explanation}`)
);
});
throw new Error(`${doc.flaws[flawName].length} ${flawName} flaws`);
}
}
}
Expand Down Expand Up @@ -103,8 +109,6 @@ function injectUnsafeHTMLFlaws(doc, $, { rawContent }) {
}

const safeIFrameSrcs = [
LIVE_SAMPLES_BASE_URL.toLowerCase(),
INTERACTIVE_EXAMPLES_BASE_URL.toLowerCase(),
// EmbedGHLiveSample.ejs
"https://mdn.github.io",
// EmbedYouTube.ejs
Expand All @@ -114,12 +118,22 @@ function injectUnsafeHTMLFlaws(doc, $, { rawContent }) {
// EmbedTest262ReportResultsTable.ejs
"https://test262.report",
];
if (LIVE_SAMPLES_BASE_URL) {
safeIFrameSrcs.push(LIVE_SAMPLES_BASE_URL.toLowerCase());
}
if (INTERACTIVE_EXAMPLES_BASE_URL) {
safeIFrameSrcs.push(INTERACTIVE_EXAMPLES_BASE_URL.toLowerCase());
}

$("script, embed, object, iframe").each((i, element) => {
const { tagName } = element;
if (tagName === "iframe") {
// For iframes we only check the 'src' value
const src = $(element).attr("src");
if (src.startsWith("/") && !src.includes("://")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also check for !src.startsWith("//") as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right!

// Local URLs are always safe
return;
}
if (!safeIFrameSrcs.find((s) => src.toLowerCase().startsWith(s))) {
addFlaw(element, `Unsafe <iframe> 'src' value (${src})`);
}
Expand Down