mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-02 08:56:07 +00:00
fix: write the admin password file without following symlinks
In Docker, migrate runs as root while data/ belongs to www-data, so a planted data/admin_password symlink would make root overwrite its target. Remove any existing path first and create the file with O_CREAT|O_EXCL|O_NOFOLLOW (mode set via fchmod). install.sh's /tmp fallback log is now created with mktemp instead of a fixed name.
This commit is contained in:
parent
02dd838a56
commit
40822e7184
3 changed files with 21 additions and 4 deletions
|
|
@ -38,3 +38,17 @@ class GeneratedAdminPasswordTestCase(TestCase):
|
|||
self.assertNotIn(password, output)
|
||||
self.assertIn(str(password_file), output)
|
||||
self.assertIsNotNone(authenticate(username="admin", password=password))
|
||||
|
||||
def test_does_not_follow_a_planted_symlink(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
(Path(tmp) / "data").mkdir()
|
||||
victim = Path(tmp) / "victim"
|
||||
victim.write_text("original\n")
|
||||
(Path(tmp) / "data" / "admin_password").symlink_to(victim)
|
||||
|
||||
self._run_create_admin(tmp)
|
||||
|
||||
password_file = Path(tmp) / "data" / "admin_password"
|
||||
self.assertEqual(victim.read_text(), "original\n")
|
||||
self.assertFalse(password_file.is_symlink())
|
||||
self.assertEqual(stat.S_IMODE(password_file.stat().st_mode), 0o600)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue