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

MWPW-151376: Check sharepoint url #3733

Open
wants to merge 1 commit into
base: stage
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 9 additions & 8 deletions tools/floodgate/js/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ function getPromoteIgnorePaths(configJson) {
async function getConfig(fgColor) {
if (!decoratedConfig) {
const urlInfo = getUrlInfo();
if (urlInfo.isValid()) {
const configPath = `${urlInfo.origin}${FLOODGATE_CONFIG}`;
const configJson = await fetchConfigJson(configPath);
decoratedConfig = {
sp: getSharepointConfig(configJson, fgColor),
admin: getHelixAdminConfig(),
promoteIgnorePaths: getPromoteIgnorePaths(configJson),
};
if (!urlInfo.isValid()) {
throw new Error('Invalid Url Parameters that point to project file');
}
const configPath = `${urlInfo.origin}${FLOODGATE_CONFIG}`;
const configJson = await fetchConfigJson(configPath);
decoratedConfig = {
sp: getSharepointConfig(configJson, fgColor),
admin: getHelixAdminConfig(),
promoteIgnorePaths: getPromoteIgnorePaths(configJson),
};
}
return decoratedConfig;
}
Expand Down
41 changes: 21 additions & 20 deletions tools/loc/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,27 +188,28 @@ function getHelixAdminConfig() {
async function getConfig() {
if (!decoratedConfig) {
const urlInfo = getUrlInfo();
if (urlInfo.isValid()) {
const configPath = `${urlInfo.origin}${LOC_CONFIG}`;
const configJson = await fetchConfigJson(configPath);
const locales = getLocalesConfig(configJson);
const decoratedLocales = getDecoratedLocalesConfig(locales);
const workflowsConfig = getWorkflowsConfig(configJson);
decoratedConfig = {
locales,
decoratedLocales,
glaas: getDecoratedGLaaSConfig(configJson, decoratedLocales, workflowsConfig),
sp: getSharepointConfig(configJson),
admin: getHelixAdminConfig(),
getLivecopiesForLanguage(language) {
const localeConfig = decoratedLocales[language];
return localeConfig?.livecopies ? localeConfig.livecopies : null;
},
getWorkflowForLanguage(language, customWorkflow) {
return getWorkflowForLanguage(workflowsConfig, language, decoratedLocales, customWorkflow);
},
};
if (!urlInfo.isValid()) {
throw new Error('Invalid Url Parameters that point to project file');
}
const configPath = `${urlInfo.origin}${LOC_CONFIG}`;
const configJson = await fetchConfigJson(configPath);
const locales = getLocalesConfig(configJson);
const decoratedLocales = getDecoratedLocalesConfig(locales);
const workflowsConfig = getWorkflowsConfig(configJson);
decoratedConfig = {
locales,
decoratedLocales,
glaas: getDecoratedGLaaSConfig(configJson, decoratedLocales, workflowsConfig),
sp: getSharepointConfig(configJson),
admin: getHelixAdminConfig(),
getLivecopiesForLanguage(language) {
const localeConfig = decoratedLocales[language];
return localeConfig?.livecopies ? localeConfig.livecopies : null;
},
getWorkflowForLanguage(language, customWorkflow) {
return getWorkflowForLanguage(workflowsConfig, language, decoratedLocales, customWorkflow);
},
};
}
return decoratedConfig;
}
Expand Down
8 changes: 7 additions & 1 deletion tools/loc/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ export function getUrlInfo() {
function getParam(name) {
return location.searchParams.get(name);
}

function isValidReferrer(url) {
const allowedHosts = ['adobe.sharepoint.com'];
return allowedHosts.includes(new URL(url)?.hostname);
}

const projectName = getParam('project');
const sub = projectName ? projectName.split('--') : [];

Expand All @@ -83,7 +89,7 @@ export function getUrlInfo() {
ref,
origin: `https://${ref}--${repo}--${owner}.hlx.page`, // TODO ADD HLX5 SUPPORT
isValid() {
return sp && owner && repo && ref;
return sp && owner && repo && ref && isValidReferrer(sp);
},
};
return urlInfo;
Expand Down
Loading