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

When the directory itself being a symlink does not work. #2646

Closed
hanxi opened this issue Jul 19, 2024 · 5 comments · Fixed by #2711
Closed

When the directory itself being a symlink does not work. #2646

hanxi opened this issue Jul 19, 2024 · 5 comments · Fixed by #2711
Assignees
Labels
staticfiles Static file serving

Comments

@hanxi
Copy link
Contributor

hanxi commented Jul 19, 2024

My test code:

from fastapi import FastAPI
import uvicorn

from staticfiles import StaticFiles

app = FastAPI()
app.mount("/music", StaticFiles(directory="/home/hanxi/work/xiaomusic/music", follow_symlink=True), name="music")

uvicorn.run(
    app,
    host=["::", "0.0.0.0"],
    port=3333,
)

The directory /home/hanxi/work/xiaomusic/music is a symlink.

> ls -l /home/hanxi/work/xiaomusic/music
lrwxrwxrwx 1 hanxi hanxi 26 Apr 30 12:10 /home/hanxi/work/xiaomusic/music -> /home/hanxi/nas/data/music

I fix this in hanxi@831cb5d

Need pr?

Important

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@Kludex
Copy link
Member

Kludex commented Sep 29, 2024

I guess this makes sense. We did have a security advisory about symlinks, so I'm a bit cautious.

Would you like to create a PR? Also, check the advisory GHSA-v5gw-mw7f-84px and see if we will not introduce something similar. 🙏

Thanks!

@hanxi
Copy link
Contributor Author

hanxi commented Sep 29, 2024

I test GHSA-v5gw-mw7f-84px case. test result is 404 Not Found. Review PR #2711 please.
Thanks!

@Kludex
Copy link
Member

Kludex commented Feb 18, 2025

It seems this PR caused some unexpected issues around:

I'm thinking about reverting this. Why does it benefit you having the directory as a symlink? @hanxi

@hanxi
Copy link
Contributor Author

hanxi commented Feb 18, 2025

I have a music directory that is shared by two web services. One of the web services uses it. Without changing the relative path, I created a symbolic link to music in the current directory of the web service.

eg:
/data/music is origin directory,
/web1/music and /web2/music link to /data/music。 web service is /web1/app.py and /web2/app.py.

If the code is rolled back, I want a new option to be able to handle this situation.

@Kludex

@davipt
Copy link
Contributor

davipt commented Mar 5, 2025

Please see if this helps #2896

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
staticfiles Static file serving
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants