Hash the web password and revoke sessions server-side
Store a scrypt hash (migrating a plaintext password without changing it), sign sessions with a generation that ./password and --revoke-all rotate, make logout a same-origin POST that revokes the token, add sign out everywhere, and close proxied websockets whose session ends. Enforce a strength rule for new passwords, back off logins per client and server-wide, check Origin on login, tighten next, add security headers and a __Host- cookie over https.
This commit is contained in:
@@ -140,7 +140,7 @@ class SetupNativeTests(unittest.TestCase):
|
||||
return setup_native.Setup(directory, prefix=Path(directory) / "prefix", runner=recorder,
|
||||
resolver=resolution, popen=fake_ntfy_serve,
|
||||
environ={"XDG_CONFIG_HOME": str(Path(directory) / "config"),
|
||||
"PIPELINES_WEB_PASSWORD": "chosen-password"})
|
||||
"PIPELINES_WEB_PASSWORD": "chosen tulip orbit canyon"})
|
||||
|
||||
@staticmethod
|
||||
def which_all(opencode="/usr/bin/opencode", pi=None, cc="/usr/bin/cc"):
|
||||
@@ -247,7 +247,10 @@ class SetupNativeTests(unittest.TestCase):
|
||||
installer.configure_web(prefix, setup_native.arguments([]))
|
||||
self.assertEqual(auth.read_bytes(), before)
|
||||
self.assertEqual(auth.stat().st_mode & 0o777, 0o600)
|
||||
self.assertEqual(json.loads(before)["password"], "chosen-password")
|
||||
stored = json.loads(before)
|
||||
self.assertNotIn("password", stored)
|
||||
self.assertNotIn(b"chosen tulip", before)
|
||||
self.assertTrue(setup_native.web_password.verify_password(stored["password_hash"], "chosen tulip orbit canyon"))
|
||||
self.assertTrue(Path(web["script"]).is_file())
|
||||
# The web app is built in Docker once and installed for the proxy.
|
||||
self.assertTrue(installer.runner.has("docker", "run", "pipelines-app-build", "web"))
|
||||
@@ -269,16 +272,17 @@ class SetupNativeTests(unittest.TestCase):
|
||||
installer.configure_web(prefix, setup_native.arguments([]))
|
||||
installer.environ["PIPELINES_WEB_PASSWORD"] = "short"
|
||||
with patch.object(setup_native.shutil, "which", side_effect=self.which_all()):
|
||||
with self.assertRaisesRegex(ValueError, "at least 8"):
|
||||
with self.assertRaisesRegex(ValueError, "too weak"):
|
||||
installer.configure_web(prefix, setup_native.arguments([]))
|
||||
installer.environ.pop("PIPELINES_WEB_PASSWORD")
|
||||
with patch.object(setup_native.shutil, "which", side_effect=self.which_all()), \
|
||||
patch.object(setup_native.sys.stdin, "isatty", return_value=True), \
|
||||
patch.object(setup_native.getpass, "getpass",
|
||||
side_effect=["short", "typed-password", "other-password",
|
||||
"typed-password", "typed-password"]):
|
||||
side_effect=["short", "typed tulip orbit canyon", "other tulip orbit canyon",
|
||||
"typed tulip orbit canyon", "typed tulip orbit canyon"]):
|
||||
web = installer.configure_web(prefix, setup_native.arguments([]))
|
||||
self.assertEqual(json.loads(Path(web["auth_file"]).read_text())["password"], "typed-password")
|
||||
stored = json.loads(Path(web["auth_file"]).read_text())["password_hash"]
|
||||
self.assertTrue(setup_native.web_password.verify_password(stored, "typed tulip orbit canyon"))
|
||||
|
||||
def test_fresh_install_skips_docker_migration(self):
|
||||
args = setup_native.arguments(["--fresh"])
|
||||
|
||||
Reference in New Issue
Block a user