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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: Replace ip function with a small helper function to address security concerns #26073

Closed
wants to merge 6 commits into from

Conversation

cosieLq
Copy link

@cosieLq cosieLq commented Feb 16, 2024

Closes #26014

What I did

I've listened to the suggestion from #26025 and added a small helper function to replace ip.address, so that we can remove the insecure package ip. What the helper function does is essentially the same as ip.address: it returns the first remotely accessible IPv4 address or otherwise the loopback.

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli/src/sandbox-templates.ts

  • Make 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/core team 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>

Copy link

socket-security bot commented Feb 16, 2024

Removed dependencies detected. Learn more about Socket for GitHub 鈫楋笌

馃毊 Removed packages: npm/@types/ip@1.1.3

View full report鈫楋笌

@valentinpalkovic valentinpalkovic self-assigned this Feb 17, 2024
@valentinpalkovic valentinpalkovic added maintenance User-facing maintenance tasks core security labels Feb 17, 2024
@AhmedMuhammedElsaid
Copy link

waiting for this PR to be merged ASAP !
ThanQ

const allIps = Object.values(os.networkInterfaces()).flat();
const allFilteredIps = allIps.filter((ip) => ip && ip.family === 'IPv4' && !ip.internal);

return allFilteredIps.length ? allFilteredIps[0]?.address : '127.0.0.1';

Choose a reason for hiding this comment

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

Isn't 0.0.0.0 better suited for the else part?

Copy link
Author

Choose a reason for hiding this comment

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

Good point. I've changed this to 0.0.0.0.

const allIps = Object.values(os.networkInterfaces()).flat();
const allFilteredIps = allIps.filter((ip) => ip && ip.family === 'IPv4' && !ip.internal);

return allFilteredIps.length ? allFilteredIps[0]?.address : '0.0.0.0';
Copy link
Contributor

Choose a reason for hiding this comment

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

I am curious whether returning 0.0.0.0 makes sense. Can the Storybook server be reached in the browser when 0.0.0.0 is used? If not, I would rather return null/undefined and handle it appropriately in the getServerAddresses function. It should return networkAddress: undefined. In this case, the network address shouldn't be logged at all to the user's console, after the server starts.

Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure which returned value is better. The Storybook server is reachable via 0.0.0.0 in my browsers. Maybe it also depends on how to interpret 'On your network' in the log.

@valentinpalkovic
Copy link
Contributor

@cosieLq Thank you so much for your contribution!

But I think we can close this. It seems that the security vulnerability was resolved in ip. A new version of ip was just released a couple of hours ago.

@valentinpalkovic
Copy link
Contributor

Superseded by #26086

@cosieLq
Copy link
Author

cosieLq commented Feb 19, 2024

@cosieLq Thank you so much for your contribution!

But I think we can close this. It seems that the security vulnerability was resolved in ip. A new version of ip was just released a couple of hours ago.

Sure! But I sort of agree with the suggestion from #26025 . Since Storybook uses only part of one function from ip, maybe it's worthy of thinking about whether to keep it as a dependency or just replace it.

@tony19
Copy link

tony19 commented Feb 21, 2024

FYI, ip 2.0.1 didn't completely fix the bug, and a new CVE might be coming. Maybe we should reconsider this PR to factor out the unstable module, especially since Storybook only uses one of its functions that can easily be recreated.

@ouuan
Copy link

ouuan commented Feb 21, 2024

FYI, the usage here is not affected by CVE-2023-42282, because your network interface will not provide malformed addresses. However, the current implementation of the ip.address() function is incorrect, see indutny/node-ip#61. It returns public addresses when the argument is 'private' and vice-versa. It's documented to return a private address when no argument is provided but actually it's returning a public address instead.

@xfournet
Copy link

Since we have again a security issue with ip (see CVE-2024-29415), wouldn't be the time to re-open this PR to definitively get rid off this lib ?
in my (relatively large) codebase only storybook still use this dependency

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci:normal core maintenance User-facing maintenance tasks security
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: The latest version depends on the highly vulnerable ip package
7 participants