mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-29 06:17:25 +00:00
fix(web-app-jitsi): store password digests in the realign test and drop the rejected comments
Review fixes on #3102: the test fixture and the stubbed prosodyctl now keep a SHA-256 digest of each account password instead of the password itself (CodeQL alert 1328, clear-text storage of sensitive information), and the two mid-code comment lines in realign_accounts.sh are gone because the repository comment lint rejects them (test-lint, job 140962063131); the root cause stays in the history of the previous commit. 🎯 Fix: 90 % 💥 Break: 2 % 💸 Tokens: – ⏱️ Velocity: – 🛡️ Security: 100 % 🏆 Score: 88 🚦 Gate: ✅ 90/5, tokens and velocity <= 100, security 100 % Created-with: https://s.veen.world/skills Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
35a1d98529
commit
3c33d9076d
2 files changed
+18
-8
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import hashlib
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
@@ -19,6 +20,7 @@ DECLARED = {
|
||||
}
|
||||
|
||||
PROSODYCTL_STUB = """#!{python}
|
||||
import hashlib
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
@@ -34,6 +36,10 @@ def record(entry):
|
||||
handle.write(entry + "\\n")
|
||||
|
||||
|
||||
def digest(password):
|
||||
return hashlib.sha256(password.encode("utf-8")).hexdigest()
|
||||
|
||||
|
||||
if len(args) == 1 and args[0].startswith(">"):
|
||||
host, user, password = (
|
||||
bytes.fromhex(value).decode("utf-8")
|
||||
@@ -45,7 +51,7 @@ if len(args) == 1 and args[0].startswith(">"):
|
||||
)
|
||||
account = store / f"{{user}}@{{host}}"
|
||||
record(f"test {{user}}@{{host}}")
|
||||
if account.is_file() and account.read_text(encoding="utf-8") == password:
|
||||
if account.is_file() and account.read_text(encoding="utf-8") == digest(password):
|
||||
print("Result: true")
|
||||
sys.exit(0)
|
||||
print("Error: Auth failed. Invalid username or password.", file=sys.stderr)
|
||||
@@ -58,20 +64,24 @@ if action == "password":
|
||||
if not account.is_file():
|
||||
print("Error: No such user", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
account.write_text(password, encoding="utf-8")
|
||||
account.write_text(digest(password), encoding="utf-8")
|
||||
print("OK: User password changed")
|
||||
sys.exit(0)
|
||||
if action == "create":
|
||||
if account.is_file():
|
||||
print("Error: User exists", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
account.write_text(password, encoding="utf-8")
|
||||
account.write_text(digest(password), encoding="utf-8")
|
||||
print("OK: User created")
|
||||
sys.exit(0)
|
||||
sys.exit(2)
|
||||
"""
|
||||
|
||||
|
||||
def digest(password):
|
||||
return hashlib.sha256(password.encode("utf-8")).hexdigest()
|
||||
|
||||
|
||||
class TestRealignAccounts(unittest.TestCase):
|
||||
def setUp(self):
|
||||
tmp = tempfile.TemporaryDirectory()
|
||||
@@ -100,7 +110,9 @@ class TestRealignAccounts(unittest.TestCase):
|
||||
|
||||
def plant(self, **passwords):
|
||||
for user, password in passwords.items():
|
||||
(self.store / f"{user}@{DOMAIN}").write_text(password, encoding="utf-8")
|
||||
(self.store / f"{user}@{DOMAIN}").write_text(
|
||||
digest(password), encoding="utf-8"
|
||||
)
|
||||
|
||||
def realign(self, **env):
|
||||
done = subprocess.run(
|
||||
@@ -132,13 +144,13 @@ class TestRealignAccounts(unittest.TestCase):
|
||||
self.plant(**{**DECLARED, "focus": "stale"})
|
||||
done = self.realign()
|
||||
self.assertEqual(self.writes(), [f"password focus@{DOMAIN}"])
|
||||
self.assertEqual(self.stored("focus"), DECLARED["focus"])
|
||||
self.assertEqual(self.stored("focus"), digest(DECLARED["focus"]))
|
||||
self.assertEqual(done.stdout.count("[CHANGED]"), 1)
|
||||
|
||||
def test_missing_accounts_are_registered_with_the_declared_password(self):
|
||||
done = self.realign()
|
||||
for user in ACCOUNTS:
|
||||
self.assertEqual(self.stored(user), DECLARED[user])
|
||||
self.assertEqual(self.stored(user), digest(DECLARED[user]))
|
||||
self.assertEqual(done.stdout.count("[CHANGED]"), len(ACCOUNTS))
|
||||
|
||||
def test_a_password_with_lua_and_shell_metacharacters_verifies_unchanged(self):
|
||||
|
||||
Reference in new issue
Block a user