Skip to content

Conversation

@Mehul-Porwal
Copy link
Contributor

Any website can include zendesk_app_framework, embed one of our iframed app, and be able to sniff the events and data. This PR is adding a whitelist of domains to prevent this.

Reported Issue: https://support.zendesk.com/agent/tickets/3371584

@zendesk/vegemite

Limitations: Since this is a front-end only fix, anyone can easily bypass this, we should think about adding nginx rules on the app assets to not be allowed to be iframed on any other domains.

lib/client.js Outdated
/.*dashboard\.zopim\.org.*/gi
];

var i;
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't just declare the iterator var in the for statement? Seems unnecessary to pull it out. If you were going to do that, I'd expect you might save the length of the Array in the constant into another var, like len = WHITELISTED_ORIGINS.length.

this._context = options.context || null;
this.ready = false;

var WHITELISTED_ORIGINS = [
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm guessing it was a conscious choice to make the Regexp literals simple so as to be unambiguous? (Could have put all of them into a single Regexp with optional groups, then just avoided the loop below)

if (WHITELISTED_ORIGINS[i].test(this._origin)) {
break;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we extract this into a function that returns true if the origin passed matches any regex, then if the function returns true throw the exception below?

Copy link
Contributor

Choose a reason for hiding this comment

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

Could we add a test please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll move it to a separate function. I think I also need to add *.apps.zdusercontent.com to the list.

@Mehul-Porwal
Copy link
Contributor Author

@svizzari @danielbreves Please help review again. 🙏

}

describe('isDomainValid', function() {
it('Should instantiate client when domain is valid 1', function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we refer to the domain in the description, rather than a count, just so it's easier understand when they fail?

Copy link
Contributor

@svizzari svizzari left a comment

Choose a reason for hiding this comment

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

Approved with a minor comment on test structure

window.addEventListener.callArgWith(1, evt);
}

describe('isDomainValid', function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

isOriginValid to match the helper method (intent)? Or, possibly just change to:

describe("with a valid origin", () => {})
describe("with an invalid origin", () => {})

?

@Mehul-Porwal Mehul-Porwal force-pushed the mehul/origin_security_issue branch from b3783ed to cee0754 Compare March 28, 2018 02:37
@Mehul-Porwal Mehul-Porwal force-pushed the mehul/origin_security_issue branch from cee0754 to 4ac65ea Compare April 5, 2018 10:46
@Mehul-Porwal
Copy link
Contributor Author

@svizzari @danielbreves Do you know why the tests are failing?

@danielbreves
Copy link
Contributor

danielbreves commented Apr 6, 2018

Seems like it's failing on master too, since @ocke's merge: https://travis-ci.org/zendesk/zendesk_app_framework_sdk/builds/359212069

@Mehul-Porwal Mehul-Porwal merged commit 04a958a into master Apr 16, 2018
@Mehul-Porwal Mehul-Porwal deleted the mehul/origin_security_issue branch April 16, 2018 00:40
@Mehul-Porwal
Copy link
Contributor Author

@token-cjg Can I request you to QA this PR, it is already deployed to Staging and Master. The first step is to verify that all apps should continue to function normally in all stages including Master, Staging and Production. Second step should be to test the use case mentioned in https://support.zendesk.com/agent/tickets/3371584.

@Mehul-Porwal Mehul-Porwal restored the mehul/origin_security_issue branch May 4, 2018 03:03
@Mehul-Porwal Mehul-Porwal deleted the mehul/origin_security_issue branch May 4, 2018 03:04
@token-cjg
Copy link

@zendesk/wombat, might be similar to https://github.com/zendesk/zendesk_app_market/pull/2737 and https://github.com/zendesk/zendesk_app_market/pull/2743 in impact re: host-mapped accounts.

@Mehul-Porwal, I think you've reverted this now and merged the revert into master, yes?

@zendesk-deploy
Copy link

This PR was deployed to Production Release. Reference: v2.0.13

@zendesk-deploy
Copy link

This PR was deployed to Pod18. Reference: v2.0.13

@zendesk-deploy
Copy link

This PR was deployed to Pod17. Reference: v2.0.13

@zendesk-deploy
Copy link

This PR was deployed to Update Major Version. Reference: v2.0.13

@zendesk-deploy
Copy link

This PR was deployed to Pod19-Pod24 (Release). Reference: v2.0.16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants