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

fix(serve): prevent serving unrestricted files #3321

Merged
merged 7 commits into from
May 10, 2021
Merged

fix(serve): prevent serving unrestricted files #3321

merged 7 commits into from
May 10, 2021

Conversation

underfin
Copy link
Member

@underfin underfin commented May 9, 2021

fix: #3281

Description

Additional context


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

packages/vite/src/node/server/middlewares/static.ts Outdated Show resolved Hide resolved
packages/vite/src/node/server/middlewares/error.ts Outdated Show resolved Hide resolved
packages/vite/src/node/config.ts Outdated Show resolved Hide resolved
packages/vite/src/node/config.ts Outdated Show resolved Hide resolved
@Shinigami92 Shinigami92 marked this pull request as draft May 10, 2021 10:22
@underfin underfin marked this pull request as ready for review May 10, 2021 11:25
@antfu antfu merged commit 7231b5a into main May 10, 2021
@antfu antfu deleted the fix-3281 branch May 10, 2021 12:22
@Shinigami92 Shinigami92 added the p3-minor-bug An edge case that only affects very specific usage (priority) label May 10, 2021
@lovasoa
Copy link
Contributor

lovasoa commented May 11, 2021

This breaks legitimate usecases when one wants to serve a folder that contains an explicit symlink to another one that is outside the server root.

@antfu
Copy link
Member

antfu commented May 11, 2021

@lovasoa You can configure it by https://vitejs.dev/config/#server-fsserve-root

@lovasoa
Copy link
Contributor

lovasoa commented May 11, 2021

Yes, but there is no reason to break existing setups in a minor version for something that is not a security vulnerability.

@antfu
Copy link
Member

antfu commented May 11, 2021

We have explained that in the changelog, and also see #2820. Sorry for the inconvenience, but we do think this is a serious security vulnerability.

@lovasoa
Copy link
Contributor

lovasoa commented May 11, 2021

This breaks existing monorepo setups, and serving files that are explicitly symlinked is not a security vulnerability.

Plus, how would I do if I had symlinked /a/b/c to /d/e/f, and was serving /d/e ? I would have to set the server.fsServe.root to / ? That would be a security issue.

@lovasoa
Copy link
Contributor

lovasoa commented May 11, 2021

we do think this is a serious security vulnerability.

To be clear: I also do agree that the previous behavior of serving any files from anywhere is a serious security vulnerability. But serving files that have been explicitly symlinked in the server root (and in node_modules in particular), is not a vulnerabilty.

@antfu
Copy link
Member

antfu commented May 11, 2021

Sure, this could indeed be overkill for some scenarios. But at this moment, I kinda think the trade-off is totally worth it. We could not figure out all the edge cases or do the assumptions about which files are safe and which are not.

So, we do open up for contributions to propose more fine-grained configurations API, for example like server.fsServe.allow and server.fsServe.disallow. Or in your case, we could find a way to let Vite detect those symlinks smartly and relaxes the restriction of them.

But that said, they all require some certain discussions, decision making, implementations and testing. The current approach is what we could have to deliver the security fix to users asap. Hope this could make me clear. Thanks

@lovasoa
Copy link
Contributor

lovasoa commented May 11, 2021

I do understand that this fix had to be rushed in order to patch the security issue quickly. Can I open a new issue to track a better fix that would avoid breakage for existing configurations ? Ideally, this should be fixed quickly before more people upgrade to v2.3.x and find themselves fix a broken configuration...

I don't think there is a need for an explicit allow and disallow list, symlinks are a more general solution to the problem.

@antfu
Copy link
Member

antfu commented May 11, 2021

Can I open a new issue to track a better fix that would avoid breakage for existing configurations ?

Sure, that would be great. Thanks

@lovasoa
Copy link
Contributor

lovasoa commented May 11, 2021

By the way, I love the quote on your github profile, and I think it applies well to this issue :

image

A ship in harbor is safe, but that is not what ships are built for.

😃

@lubomirblazekcz
Copy link
Contributor

@antfu https://vitejs.dev/config/#server-fsserve-root this documentation is really not helping much, it's not clear from it what should I set in the first place if I want to expose some directories for serving

@lovasoa
Copy link
Contributor

lovasoa commented May 11, 2021

@evromalarkey : I agree that the documentation is confusing.

In the current setup, it should be set to the common parent of all the directories you want to be able to serve. So if you want to serve /home/you/common and your project is in /home/you/projects/myproject, then your vite.config.js config should look like this :

export default {
  server: {
    fsServe: {
      // Allow serving all files starting from two levels above the current directory in the fs hierarchy 
      root: '../../' 
    }
  }
}

@antfu
Copy link
Member

antfu commented May 11, 2021

Yeah, good point. Would you like to make a PR to update the docs? Thanks

@lubomirblazekcz
Copy link
Contributor

Yeah I understand it now, thanks. Either way I think this change comes with a lot of problems, but it had to be done, I get it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

path traversal vulnerability
6 participants