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

Block api calls to other sites - related ticket https://trello.com/c/… #341

Merged
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
9 changes: 9 additions & 0 deletions packages/cms/lib/modules/api-proxy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ module.exports = {
pathRewrite: {['^' + apiPath]: '/api'},
onProxyReq: (proxyReq, req, res) => {

const siteId = req.data.global.siteId;
let path = req.path;
let match = path.match(/\/api\/site\/(\d+)\//);
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be better to make the latest slash optional so it also matches this record:

/api/site/12

Regex: \/api\/site\/(\d+)\/?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Fixed.

if (match && match[1] != siteId) {
return res.status(403).json({
'message' : self.apos.i18n.__('The api call is for another site')
});
}

/**
* Validate the request with captcha if send by a form
*/
Expand Down