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

feat(venmo): allow trusted domains #439

Merged
merged 5 commits into from
Jun 12, 2023
Merged
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: 12 additions & 5 deletions src/child/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,18 @@ export function normalizeChildProps<P, X>(
for (const key of Object.keys(props)) {
const prop = propsDef[key];

if (
prop &&
prop.sameDomain &&
(origin !== getDomain(window) || !isSameDomain(parentComponentWindow))
) {
const trustedChild: boolean =
prop && prop.trustedDomains && prop.trustedDomains.length > 0
? prop.trustedDomains.includes(getDomain(window))
: origin === getDomain(window) || isSameDomain(parentComponentWindow);

// let trustedDomains override sameDomain prop
if (prop && prop.sameDomain && !trustedChild) {
continue;
}

// sameDomain was not set and trusted domains must match
if (prop && prop.trustedDomains && !trustedChild) {
continue;
}

Expand Down
1 change: 1 addition & 0 deletions src/component/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ export type PropDefinitionType<T, P, S: $Values<typeof PROP_TYPE>, X> = {|
validate?: ({| value: T, props: PropsType<P> |}) => void,
sameDomain?: boolean,
serialization?: $Values<typeof PROP_SERIALIZATION>,
trustedDomains?: $ReadOnlyArray<string>,
|};

export type BOOLEAN_DEFINITION_TYPE = typeof PROP_TYPE.BOOLEAN;
Expand Down
17 changes: 12 additions & 5 deletions src/parent/parent.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,18 @@ export function parentComponent<P, X, C>({
continue;
}

if (
prop &&
prop.sameDomain &&
!matchDomain(initialChildDomain, getDomain(window))
) {
const trustedChild: boolean =
prop && prop.trustedDomains && prop.trustedDomains.length > 0
? prop.trustedDomains.includes(initialChildDomain)
: matchDomain(initialChildDomain, getDomain(window));

// let trustedDomains override sameDomain prop
if (prop && prop.sameDomain && !trustedChild) {
continue;
}

// sameDomain was not set and trusted domains must match
if (prop && prop.trustedDomains && !trustedChild) {
continue;
}

Expand Down
4 changes: 2 additions & 2 deletions test/tests/domain.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe("parent domain check", () => {
return component().render(getBody());
});

it("allowedParentDomains is specified as a regex and parent domian match", () => {
it("allowedParentDomains is specified as a regex and parent domain match", () => {
window.__component__ = () => {
return zoid.create({
tag: "test-parent-domain-regex",
Expand Down Expand Up @@ -163,7 +163,7 @@ describe("parent domain check", () => {
});
});

it("xprops.getParentDomain should pass the correct domain", () => {
it("xprops.getParent should pass the correct domain", () => {
return wrapPromise(({ expect }) => {
window.__component__ = () => {
return zoid.create({
Expand Down
Loading
Loading