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

Strip STATIC_URL from start of path to avoid SuspiciousFileOperation during embed #427

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rantecki
Copy link

With embed enabled, I was running into SuspicousFileOperation exceptions seemingly due to the /static/ at the start of the asset path.

    content = compress(paths, **kwargs)
  File "/home/richard/work/DE/heartbeat/env/src/django-pipeline/pipeline/compressors/__init__.py", line 73, in compress_css
    css = self.concatenate_and_rewrite(paths, output_filename, variant)
  File "/home/richard/work/DE/heartbeat/env/src/django-pipeline/pipeline/compressors/__init__.py", line 139, in concatenate_and_rewrite
    content = re.sub(URL_DETECTOR, reconstruct, content)
  File "/home/richard/work/DE/heartbeat/env/lib/python2.7/re.py", line 151, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "/home/richard/work/DE/heartbeat/env/src/django-pipeline/pipeline/compressors/__init__.py", line 135, in reconstruct
    output_filename, variant)
  File "/home/richard/work/DE/heartbeat/env/src/django-pipeline/pipeline/compressors/__init__.py", line 150, in construct_asset_path
    if self.embeddable(public_path, variant):
  File "/home/richard/work/DE/heartbeat/env/src/django-pipeline/pipeline/compressors/__init__.py", line 162, in embeddable
    if not (re.search(settings.PIPELINE_EMBED_PATH, path.replace('\\', '/')) and self.storage.exists(path)):
  File "/home/richard/work/DE/heartbeat/env/local/lib/python2.7/site-packages/django/core/files/storage.py", line 265, in exists
    return os.path.exists(self.path(name))
  File "/home/richard/work/DE/heartbeat/env/local/lib/python2.7/site-packages/django/contrib/staticfiles/storage.py", line 48, in path
    return super(StaticFilesStorage, self).path(name)
  File "/home/richard/work/DE/heartbeat/env/local/lib/python2.7/site-packages/django/core/files/storage.py", line 281, in path
    raise SuspiciousFileOperation("Attempted access to '%s' denied." % name)
django.core.exceptions.SuspiciousFileOperation: Attempted access to '/static/img/logo.png' denied.

This occurs regardless of whether I reference the asset using a relative url i.e. img/logo.png or an absolute url /static/img/logo.png in my LESS file.

I'm not sure if I'm doing something wrong, but stripping the STATIC_URL from paths prior to storage.exists() lookups appears to resolve it.

@ekohl
Copy link

ekohl commented Jul 4, 2016

Does 930b12c solve this?

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

Successfully merging this pull request may close these issues.

2 participants