Skip to content

fix(PM-204): open redirect issues #7027

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

Merged
merged 6 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
13 changes: 11 additions & 2 deletions src/server/routes/contentful.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
getService,
getSpaceId,
articleVote,
ALLOWED_DOMAINS,
} from '../services/contentful';

const cors = require('cors');
Expand All @@ -37,7 +38,11 @@ routes.use(
version,
} = req.params;
const spaceId = getSpaceId(spaceName);
res.redirect(`https://${ASSETS_DOMAIN}/spaces/${spaceId}/environments/${environment}/${id}/${version}/${name}`);
if (!ALLOWED_DOMAINS.includes(ASSETS_DOMAIN)) {
throw new Error('Invalid domain detected!');
}
const url = new URL(`https://${ASSETS_DOMAIN}/spaces/${spaceId}/environments/${environment}/${id}/${version}/${name}`);
res.redirect(url.href);
},
);

Expand All @@ -52,8 +57,12 @@ routes.use(
spaceName,
version,
} = req.params;
if (!ALLOWED_DOMAINS.includes(IMAGES_DOMAIN)) {
throw new Error('Invalid domain detected!');
}
const spaceId = getSpaceId(spaceName);
res.redirect(`https://${IMAGES_DOMAIN}/spaces/${spaceId}/environments/${environment}/${id}/${version}/${name}`);
const url = new URL(`https://${IMAGES_DOMAIN}/spaces/${spaceId}/environments/${environment}/${id}/${version}/${name}`);
res.redirect(url.href);
},
);

Expand Down
1 change: 1 addition & 0 deletions src/server/services/contentful.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const PREVIEW_URL = 'https://preview.contentful.com/spaces';
export const ASSETS_DOMAIN = 'assets.ctfassets.net';
export const IMAGES_DOMAIN = 'images.ctfassets.net';

export const ALLOWED_DOMAINS = ['assets.ctfassets.net', 'images.ctfassets.net'];
const MAX_FETCH_RETRIES = 5;

/**
Expand Down
11 changes: 8 additions & 3 deletions src/shared/components/TopcoderHeader/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import './style.scss';
/* global window, document */

const BASE_URL = config.URL.BASE;
const VALID_BASE_URLS = ['https://www.topcoder-dev.com', 'https://www.topcoder.com'];

const MENU = [{
title: 'Compete',
Expand Down Expand Up @@ -426,9 +427,13 @@ export default class TopcoderHeader extends React.Component {
ref={(input) => { this.searchInput = input; }}
onKeyPress={(event) => {
if (event.key === 'Enter') {
window.location = `${BASE_URL}/search/members?q=${
encodeURIComponent(event.target.value)
}`;
if (!VALID_BASE_URLS.includes(BASE_URL)) {
return;
}
const query = event.target.value.trim();
const url = new URL(`${BASE_URL}/search/members`);
url.searchParams.append('q', query);
window.location = url.href;
}
}}
onBlur={closeSearch}
Expand Down
Loading