From 5fbddcc683617c1d5d9b5c2ea7f576811cb6f48a Mon Sep 17 00:00:00 2001 From: Claas Augner Date: Fri, 21 Feb 2025 11:27:24 +0100 Subject: [PATCH 1/2] refactor(libs/play): extract isMDNReferer() --- libs/play/index.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libs/play/index.js b/libs/play/index.js index 82322d56dedd..920974fd1887 100644 --- a/libs/play/index.js +++ b/libs/play/index.js @@ -332,6 +332,13 @@ function playSubdomain(hostname) { return ""; } +/** + * @param {URL} referer + */ +function isMDNReferer(referer) { + return referer.hostname === ORIGIN_MAIN; +} + /** * @param {express.Request} req * @param {express.Response} res @@ -351,8 +358,7 @@ export async function handleRunner(req, res) { const isLocalhost = req.hostname === "localhost"; const hasMatchingHash = playSubdomain(req.hostname) === hash; const isIframeOnMDN = - referer.hostname === ORIGIN_MAIN && - req.headers["sec-fetch-dest"] === "iframe"; + isMDNReferer(referer) && req.headers["sec-fetch-dest"] === "iframe"; if ( !stateParam || From 70ceec7ca0c8e4bc109d0af137a440444b6c0a6a Mon Sep 17 00:00:00 2001 From: Claas Augner Date: Fri, 21 Feb 2025 11:30:34 +0100 Subject: [PATCH 2/2] enhance(libs/play): allow runner embedded on review pages --- cloud-function/README.md | 2 ++ libs/play/index.js | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/cloud-function/README.md b/cloud-function/README.md index 5b379aa514a9..925fdc3a5110 100644 --- a/cloud-function/README.md +++ b/cloud-function/README.md @@ -36,6 +36,8 @@ The function uses the following environment variables: requests to the main site. - `ORIGIN_LIVE_SAMPLES` (default: `"localhost"`) - The expected `Host` header value for requests to live samples. +- `ORIGIN_REVIEW` (default: `"content.dev.mdn.mozit.cloud"`) - The host of the + content preview pages. - `SOURCE_CONTENT` (default: `"http://localhost:8100"`) - The URL at which the client build is served. - `SOURCE_API` (default: `"https://developer.allizom.org/"`) - The URL at which diff --git a/libs/play/index.js b/libs/play/index.js index 920974fd1887..41916db887a5 100644 --- a/libs/play/index.js +++ b/libs/play/index.js @@ -4,6 +4,8 @@ import he from "he"; export const ORIGIN_PLAY = process.env["ORIGIN_PLAY"] || "localhost"; export const ORIGIN_MAIN = process.env["ORIGIN_MAIN"] || "localhost"; +export const ORIGIN_REVIEW = + process.env["ORIGIN_REVIEW"] || "content.dev.mdn.mozit.cloud"; /** @import { IncomingMessage, ServerResponse } from "http" */ /** @import * as express from "express" */ @@ -336,7 +338,12 @@ function playSubdomain(hostname) { * @param {URL} referer */ function isMDNReferer(referer) { - return referer.hostname === ORIGIN_MAIN; + const { hostname } = referer; + return ( + hostname === ORIGIN_MAIN || + hostname === ORIGIN_REVIEW || + hostname.endsWith(`.${ORIGIN_REVIEW}`) + ); } /**