-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Builder-Vite: Fix logic related to setting allowedHosts when IP address used #31472
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile
| !ipRegex.test(options.host) | ||
| ) { | ||
| config.server.allowedHosts = [options.host.toLowerCase()]; | ||
| if (options.host && !config.server.allowedHosts) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Check for undefined/null specifically rather than falsy values to avoid overriding empty arrays
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty array should likely be overridden if options.host is set.
|
@JReinhold @valentinpalkovic https://github.com/storybookjs/storybook/pull/30523/files#r2079670800
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile
|
|
||
| if (ipRegex.test(options.host)) { | ||
| // If options.host is set to an IP address then allow all hosts | ||
| config.server.allowedHosts = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Consider adding a warning log when allowing all hosts, as this reduces security
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A warning here would be appropriate, let me know what you'd like the warning message to be.
Or, if you'd prefer to not set allowedHosts to true then this would be a good place to add a warning to inform users that only the direct IP address and localhost will be allowed and that other hostnames will be rejected unless an allowedHosts array is added to the viteFinal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you for your patience @JSMike. Can you help me understand why this condition is necessary - why do we need to set true when it's an IP address? What is stopping us from just setting that IP address as the only entry in allowedHosts?
I'm sure there is a reason for this, but I haven't been able to find it through the various related issues/PRs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My thought is when I set an IP address for the host, I'm usually trying to use the IP/Host configuration assigned to the host machine. When developing with docker containers I typically end up setting to the host to '0.0.0.0' in order to then inherit the binding of the machine, as the exact hostname/url isn't always known. In these cases the default of localhost typically does not apply. If this is an advanced use case that should always require setting the allowedHosts variable that would be understandable. My idea with this logic was also to more closely align with how the configuration worked for Storybook prior to the change from Vite. This is really just my opinion. If you'd prefer to not have this logic then I can update the PR. Or maybe this logic should only apply specifically when using '0.0.0.0', as that's specifying to listen on all network interfaces?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or maybe this logic should only apply specifically when using '0.0.0.0', as that's specifying to listen on all network interfaces?
I like this approach actually, I think we should make it like this, including a warning stating it, like:
Setting server.allowedHosts to true in the Vite config because you set --host to 0.0.0.0. You can manually override this in your viteFinal configuration, see https://vite.dev/config/server-options.html#server-allowedhosts and https://storybook.js.org/docs/api/main-config/main-config-vite-final
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'll push something up soon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JReinhold I updated the logic and the messaging. Let me know if that looks good or you'd like any additional changes.
|
View your CI Pipeline Execution ↗ for commit 9baeb4d
☁️ Nx Cloud last updated this comment at |
a7205f3 to
529154e
Compare
7185d02 to
e80df3b
Compare
84aa210 to
f30ca5b
Compare
f30ca5b to
6585c65
Compare
Package BenchmarksCommit: No significant changes detected, all good. 👏 |
8280b40 to
554d2d9
Compare
ae01da9 to
2a45f63
Compare
JReinhold
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only a minor request on the logging, otherwise LGTM ❤️
b4e50f8 to
aea6501
Compare
|
@JReinhold applied the requested changes, let me know if anything else needs fixing. |
aea6501 to
9baeb4d
Compare
|
Thank you ❤️ |
Related to #30523, #30432, and #30338
What I did
Previous PR set
allowedHoststotrueby default, this was reverted but no longer set theallowedHostsvalue when an IP address was used foroptions.host.This change sets
allowedHoststotrueonly ifallowedHostsis undefined and an IP address is passed as the host. Otherwise no hostname other than 'localhost' would be allowed to access the devserver.Note, this is my personal opinion on what the logic should be, to more closely align with existing functionality prior to the breaking change from Vite. If, for security reasons, this is not desired then updating the PR to add a warning to the console would be another good option, along with additional documentation on setting
allowedHostswhen using the Vite dev-server with Storybook.Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!
Documentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal,ci:mergedorci:dailyGH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli-storybook/src/sandbox-templates.tsMake sure this PR contains one of the labels below:
Available labels
bug: Internal changes that fixes incorrect behavior.maintenance: User-facing maintenance tasks.dependencies: Upgrading (sometimes downgrading) dependencies.build: Internal-facing build tooling & test updates. Will not show up in release changelog.cleanup: Minor cleanup style change. Will not show up in release changelog.documentation: Documentation only changes. Will not show up in release changelog.feature request: Introducing a new feature.BREAKING CHANGE: Changes that break compatibility in some way with current major version.other: Changes that don't fit in the above categories.🦋 Canary release
This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the
@storybookjs/coreteam here.core team members can create a canary release here or locally with
gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>Greptile Summary
This PR enhances Vite server security in Storybook by implementing stricter host access controls while maintaining flexibility for custom configurations.
code/builders/builder-vite/src/vite-server.tsto restrict access to localhost by default, following Vite's secure practices--hostCLI flag orviteFinalconfigThe changes improve security while maintaining backward compatibility and providing clear paths for customization when needed.
💡 (3/5) Reply to the bot's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!