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

Improve shop domain sanitization #162

Merged
merged 2 commits into from
Jun 2, 2023

Conversation

stidges
Copy link
Contributor

@stidges stidges commented May 17, 2023

After launching our first app, we noticed a couple of weird shop domains trying to install our app (stuff like asfdasfd.asfdasfd.addf). I found that the shop domain sanization doesn't work fully in this case. I compared this to how the Shopify PHP package does this and added a few lines to improve it.

Let me know if you think throwing an exception is too much here, but I figured if someone tries to install an app with an invalid domain we don't want to process it in any case.

@Kyon147
Copy link
Owner

Kyon147 commented May 24, 2023

@stidges sounds like a good idea to me - I've not noticed any incorrect domains trying to be installed on my apps but better security and sanitization is always welcomed!

Throwing the exception might potentially bog down peoples logs, if bots decide to just spam an app on the install route. What are your thoughts?

@stidges
Copy link
Contributor Author

stidges commented May 25, 2023

Yes that's true.. My reason for adding the exception was because I think we wouldn't want to process a request with an invalid shop domain, and also because otherwise we'd have to update all the other code to check if the shop domain is empty/valid before using it

@Kyon147
Copy link
Owner

Kyon147 commented May 26, 2023

@stidges yeah that makes sense, an exception seems like the correct approach as people can always bind it in the Exception handler.

        $this->renderable(function(MissingShopDomainException $e){
            // Do something
        });

Copy link
Owner

@Kyon147 Kyon147 left a comment

Choose a reason for hiding this comment

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

LGTYVM

@Kyon147 Kyon147 merged commit da91520 into Kyon147:master Jun 2, 2023
@ClaraLeigh
Copy link
Contributor

This comment is more for anyone searching the repo, this PR is where the InvalidShopDomainException was created. For me it created about 100+ errors in my application as domains will now throw an error when incorrect, ie via a mocked relationship that doesn't use the myshopify domain.

Hope this saves someone else the 2hrs I spent trying to work out why a composer update broke everything.

@Kyon147
Copy link
Owner

Kyon147 commented Jun 27, 2023

@ClaraLeigh that is a great point - it might be worth adding in a whitelist for unit testing etc, so that we don't need to use myshopfiy in tests, but it might also be better to force tests to be closer to prod? Thoughts?

@ClaraLeigh
Copy link
Contributor

@Kyon147 I think it's probably fine as is. It just meant I had to create a new state for shopify versions of a factory and fake a domain name with myshopify attached. It probably should have been that way to begin with for data integrity but in my usecase I mock all the api calls, so the issue was just hidden from view until this change

@Kyon147
Copy link
Owner

Kyon147 commented Jun 27, 2023

@ClaraLeigh i've been there! Glad you got it sorted.

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.

3 participants