Skip to content

Allow storage proxy to work with IPv4 #893

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

Open
wants to merge 3 commits into
base: release/5.0
Choose a base branch
from

Conversation

droguljic
Copy link
Contributor

Storage proxy signed cookies would get assigned to wrong domain if
configured host name is IPv4 address, thus blocking display of assets.
Problem is in psl package which parses IPv4 addresses, thus producing
wrong domains.
Fix detects IPv4 addresses using regular expression and just returns
null for domain.

@underscope underscope requested a review from MiroDojkic June 17, 2021 06:22
@underscope
Copy link
Collaborator

@droguljic Please base this on release/5.0 😉 Thx!

Comment on lines 12 to 15
function getDomain() {
if (IPV4_REGEX.test(config.hostname)) return null;
return psl.parse(config.hostname).domain;
}
Copy link
Member

Choose a reason for hiding this comment

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

Does this work only for the local proxy provider?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mostly, as domain is not specified and thus determined by viewer URL, which in turn won't expose signed cookies to CloudFront.
There is possibility for this to work with CloudFront in following circumstances, host name is set to IPv4, viewer URL is different from host name and CloudFront CNAME option is set to match viewer URL, thus signed cookies are set on correct domain, but I doubt this as a real use case.
This fix mostly targets Local proxy, as without it local proxy cannot work when host name is IPv4.

Copy link
Member

Choose a reason for hiding this comment

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

@droguljic got it. Can we throw an error in case that the proxy is set to CloudFront and the hostname is IPV4 to warn developer that their configuration is invalid?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MiroDojkic done. Please see the latest commit.

Copy link
Member

Choose a reason for hiding this comment

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

@droguljic sorry for nitpicking, but should we move config validation to storage providers where the rest of the validation is?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MiroDojkic inside this file https://github.com/ExtensionEngine/tailor/blob/release/5.0/config/server/index.js?
In order to put it here, logic for testing is something IPv4 needs to be extracted into separate function, probably into server/shared/util/isIpv4. Importing something from server into config seems a bit weird and copy pasting regular expression is not DRY, so I'm in dilemma again.

Copy link
Member

Choose a reason for hiding this comment

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

@droguljic yep. If it's not being used anywhere else, we could put it at the bottom of config/server/index.js. If the file becomes too bloated with noise, would it make sense to extract it to something like config/server/validation.js?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MiroDojkic it needs to be used in two places, server/shared/storage/proxy/mw.js and config/server/index.js, already is used in former and will be added to latter. Maybe adding new dependency is-ip is a better option and it'll definitely resolve this dilemma, so going with new dependency.

Copy link
Member

Choose a reason for hiding this comment

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

@droguljic good idea!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MiroDojkic done.

Storage proxy signed cookies would get assigned to wrong domain if
configured host name is IPv4 address, thus blocking display of assets.
Problem is in `psl` package which parses IPv4 addresses, thus producing
wrong domains.
Fix detects IPv4 addresses using regular expression and just returns
`null` for domain.
@droguljic droguljic force-pushed the fix/storage-proxy-cookie-domain branch from 610974a to 4159f62 Compare June 17, 2021 10:32
@droguljic droguljic changed the base branch from develop to release/5.0 June 17, 2021 10:32
@underscope underscope requested a review from MiroDojkic June 18, 2021 12:19
@underscope underscope added the 👈 needs code review Code review label label Jun 18, 2021
Storage proxy middleware will throw an error for IPv4 host name
and CloudFront proxy combination.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
👈 needs code review Code review label
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants