mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-11-13 12:23:44 +01:00
fix(import): resolve symlinks when checking the upload path
The temp root is resolve()d in settings but the file path was only abspath()ed, so a symlink inside the temp folder could point outside it and still pass the check. Resolve both sides the same way. Also drop the unused /temp folder from the prod image.
This commit is contained in:
1 parent
38118c56d3
commit
e0c1e4d5ff
3 files changed
+13
-4
No files matched your search
@@ -1131,7 +1131,8 @@ class ImportService:
|
|||||||
Validates that the file path is within the allowed temporary directory.
|
Validates that the file path is within the allowed temporary directory.
|
||||||
Returns the absolute path.
|
Returns the absolute path.
|
||||||
"""
|
"""
|
||||||
abs_path = os.path.abspath(file_path)
|
# resolve() like IMPORT_TEMP_ROOT, so symlinks can't point outside it
|
||||||
|
abs_path = str(Path(file_path).resolve())
|
||||||
if not Path(abs_path).is_relative_to(settings.IMPORT_TEMP_ROOT):
|
if not Path(abs_path).is_relative_to(settings.IMPORT_TEMP_ROOT):
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"Invalid file path. File must be in {settings.IMPORT_TEMP_ROOT}"
|
f"Invalid file path. File must be in {settings.IMPORT_TEMP_ROOT}"
|
||||||
|
|||||||
@@ -149,3 +149,13 @@ class ImportTempRootTests(ImportObjectPermissionTestCase):
|
|||||||
):
|
):
|
||||||
with self.subTest(path=path), self.assertRaises(ValueError):
|
with self.subTest(path=path), self.assertRaises(ValueError):
|
||||||
service._validate_file_path(str(path))
|
service._validate_file_path(str(path))
|
||||||
|
|
||||||
|
def test_service_rejects_symlinks_pointing_outside_temp_root(self):
|
||||||
|
link = self.temp_root / "link.csv"
|
||||||
|
try:
|
||||||
|
link.symlink_to("/etc/passwd")
|
||||||
|
except OSError:
|
||||||
|
self.skipTest("symlinks not available")
|
||||||
|
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
self._service()._validate_file_path(str(link))
|
||||||
@@ -69,9 +69,7 @@ RUN sed -i 's/\r$//g' /start && \
|
|||||||
COPY --chown=app:app ./app .
|
COPY --chown=app:app ./app .
|
||||||
|
|
||||||
RUN chown -R app:app /usr/src/app && \
|
RUN chown -R app:app /usr/src/app && \
|
||||||
chown -R app:app /usr/src/frontend && \
|
chown -R app:app /usr/src/frontend
|
||||||
mkdir /temp && \
|
|
||||||
chown -R app:app /temp
|
|
||||||
|
|
||||||
USER app
|
USER app
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user