Browse Source

Potential fix for pull request finding 'CodeQL / Uncontrolled data used in path expression'

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
pull/3865/head
Edward 3 weeks ago
committed by GitHub
parent
commit
d721cbd013
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 9
      sapl/materia/views.py

9
sapl/materia/views.py

@ -2380,7 +2380,14 @@ class DocumentoAcessorioEmLoteView(PermissionRequiredMixin, FilterView):
str(doc.id)) str(doc.id))
if not os.path.exists(diretorio): if not os.path.exists(diretorio):
os.makedirs(diretorio) os.makedirs(diretorio)
file_path = os.path.join(diretorio, arquivo.name) safe_filename = os.path.basename(arquivo.name)
file_path = os.path.join(diretorio, safe_filename)
real_diretorio = os.path.realpath(diretorio)
real_file_path = os.path.realpath(file_path)
if os.path.commonpath([real_diretorio, real_file_path]) != real_diretorio:
msg = _('Nome de arquivo inválido.')
messages.add_message(request, messages.ERROR, msg)
return self.get(request, self.kwargs)
shutil.copy2(tmp.name, file_path) shutil.copy2(tmp.name, file_path)
doc.arquivo.name = file_path.split( doc.arquivo.name = file_path.split(
MEDIA_ROOT + "/")[1] # Retira MEDIA_ROOT do nome MEDIA_ROOT + "/")[1] # Retira MEDIA_ROOT do nome

Loading…
Cancel
Save