Skip to content

django.core.exceptions.SuspiciousFileOperation: The joined path (C:\) is located outside of the base path component #2057

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

Closed
legghe opened this issue Jan 14, 2025 · 8 comments

Comments

@legghe
Copy link

legghe commented Jan 14, 2025

Bug Description

On Windows systems, the Static Files panel fails when trying to resolve static files paths.
The issue occurs because the toolbar tries to resolve paths starting with '/', which on Windows
gets interpreted as 'C:', triggering Django's SuspiciousFileOperation protection.

Environment

  • OS: Windows 11
  • Django version: 5.1.4
  • Django Debug Toolbar version: 5.0.1

Stack Trace

====== Safe Join Debug ======
Base path: C:\Users\xxxxxx\Documents\xxxxxx\src\assets
Final path: C:
Paths to join: ('/',)
normcase(final_path): c:
normcase(base_path + sep): c:\users\xxxxx\documents\xxxxxx\src\assets
dirname(normcase(base_path)): c:\users\xxxxxx\documents\xxxxxx\src

Proposed Fix

Modified safe_join to handle root paths on Windows by replacing '/' with '' as the first path element.

@matthiask
Copy link
Member

Can you post the value of your staticfiles settings? STATIC_ROOT, STATIC_URL etc?

./manage.py diffsettings may help with that.

@legghe
Copy link
Author

legghe commented Jan 14, 2025 via email

@tim-schilling
Copy link
Member

I may not understand things properly, but this:

STATICFILES_DIRS = [
    ('', BASE_DIR / 'src' / 'assets'),
]

seems suspect. It looks like that's used to declare a prefix, but I wonder what happens when it's an empty string. Maybe that's the problem?

What happens if that is ('something', BASE_DIR / 'src' / 'assets') does it still error?

@legghe
Copy link
Author

legghe commented Jan 14, 2025 via email

@tim-schilling
Copy link
Member

It sounds like we can close this?

@legghe
Copy link
Author

legghe commented Jan 15, 2025 via email

@tim-schilling
Copy link
Member

If you're referring to venv\Lib\site-packages\django\utils_os.py that's not a toolbar file, it's a django one.

@legghe legghe closed this as completed Jan 15, 2025
@legghe
Copy link
Author

legghe commented Jan 15, 2025 via email

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

No branches or pull requests

3 participants