Merge pull request #389 from naturallaw777/fix/clear-text-root-password
fix: hash root password instead of storing in clear text (CWE-312)
This commit is contained in:
@@ -1554,7 +1554,11 @@ def _resolve_credential(cred: dict) -> dict | None:
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
value = prefix + raw + suffix
|
# Detect scrypt hash (salt_hex:hash_hex) — passwords stored securely
|
||||||
|
if re.match(r'^[0-9a-f]{32}:[0-9a-f]{64,}$', raw):
|
||||||
|
value = "(stored securely — use Security Reset to set a new one)"
|
||||||
|
else:
|
||||||
|
value = prefix + raw + suffix
|
||||||
result = {"label": label, "value": value, "multiline": multiline}
|
result = {"label": label, "value": value, "multiline": multiline}
|
||||||
|
|
||||||
if qrcode:
|
if qrcode:
|
||||||
@@ -5173,7 +5177,7 @@ async def api_security_reset():
|
|||||||
try:
|
try:
|
||||||
os.makedirs("/var/lib/secrets", exist_ok=True)
|
os.makedirs("/var/lib/secrets", exist_ok=True)
|
||||||
with open("/var/lib/secrets/root-password", "w") as f:
|
with open("/var/lib/secrets/root-password", "w") as f:
|
||||||
f.write(new_root_password)
|
f.write(_hash_password(new_root_password))
|
||||||
os.chmod("/var/lib/secrets/root-password", 0o600)
|
os.chmod("/var/lib/secrets/root-password", 0o600)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
errors.append(f"write root-password: {exc}")
|
errors.append(f"write root-password: {exc}")
|
||||||
@@ -5195,7 +5199,7 @@ async def api_security_reset():
|
|||||||
except OSError:
|
except OSError:
|
||||||
pass # Non-fatal
|
pass # Non-fatal
|
||||||
|
|
||||||
return {"ok": True, "new_password": new_free_password, "errors": errors}
|
return {"ok": True, "new_password": new_free_password, "new_root_password": new_root_password, "errors": errors}
|
||||||
|
|
||||||
|
|
||||||
@app.post("/api/security/verify-integrity")
|
@app.post("/api/security/verify-integrity")
|
||||||
|
|||||||
@@ -111,7 +111,15 @@ in
|
|||||||
echo "$ROOT_PASS" > "$SECRET_FILE"
|
echo "$ROOT_PASS" > "$SECRET_FILE"
|
||||||
chmod 600 "$SECRET_FILE"
|
chmod 600 "$SECRET_FILE"
|
||||||
fi
|
fi
|
||||||
echo "root:$(cat "$SECRET_FILE")" | chpasswd
|
# If the file contains a scrypt hash (salt:hash), skip chpasswd — the
|
||||||
|
# password was already set via the Hub security reset endpoint and this
|
||||||
|
# service is only re-running as a manual recovery step.
|
||||||
|
CONTENT="$(cat "$SECRET_FILE")"
|
||||||
|
if echo "$CONTENT" | grep -qE '^[0-9a-f]{32}:[0-9a-f]{64,}$'; then
|
||||||
|
echo "root-password-setup: stored value is already hashed — skipping chpasswd" >&2
|
||||||
|
else
|
||||||
|
echo "root:$CONTENT" | chpasswd
|
||||||
|
fi
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user