BR-002: refuse free text that looks like a wallet secret
This commit is contained in:
1 parent
85ea33e0b3
commit
a3661d2cc9
1 file changed
+41
-3
+41
-3
@@ -51,6 +51,11 @@ replaces the key with a new one, so the replacement may carry the other type, an
|
|||||||
a key that becomes a cloud key may not take a name the wallet software list
|
a key that becomes a cloud key may not take a name the wallet software list
|
||||||
already holds (section 28).
|
already holds (section 28).
|
||||||
|
|
||||||
|
Every free-text field is also checked against ``secret_guard`` before it is
|
||||||
|
accepted, so a seed phrase or a private key that was pasted by accident is
|
||||||
|
refused instead of stored. The check is local, and the message names the field
|
||||||
|
and the shape that was recognised, never the value (sections 2 and 15).
|
||||||
|
|
||||||
The BIP327/SLIP39 results are gone, together with the rest of that function
|
The BIP327/SLIP39 results are gone, together with the rest of that function
|
||||||
(section 24.2).
|
(section 24.2).
|
||||||
"""
|
"""
|
||||||
@@ -59,6 +64,7 @@ from datetime import date
|
|||||||
|
|
||||||
from alerts import ALERT_CODES, CLOSING_ACTIONS
|
from alerts import ALERT_CODES, CLOSING_ACTIONS
|
||||||
from database import KEY_COUNT, MAX_KEY_COUNT, MIN_KEY_COUNT, MIN_THRESHOLD
|
from database import KEY_COUNT, MAX_KEY_COUNT, MIN_KEY_COUNT, MIN_THRESHOLD
|
||||||
|
from secret_guard import find_secret, rejection_message
|
||||||
|
|
||||||
# Software compatibility requires an active choice, so "not assessed" is not
|
# Software compatibility requires an active choice, so "not assessed" is not
|
||||||
# submittable for a new registration (section 23.1).
|
# submittable for a new registration (section 23.1).
|
||||||
@@ -105,6 +111,16 @@ class WalletSoftwareNameInUse(ValidationError):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class SecretDetected(ValidationError):
|
||||||
|
"""Raised when a free-text field looks like a wallet secret.
|
||||||
|
|
||||||
|
The app never asks for a seed phrase or a private key and never stores one
|
||||||
|
(sections 2 and 15). The value is refused before anything is written, and the
|
||||||
|
message names the field and the shape that was recognised, never the value
|
||||||
|
itself, so the secret does not travel into a response or a log.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
def next_check_due(checked_at):
|
def next_check_due(checked_at):
|
||||||
"""Return the check date one calendar year later, clamping 29 February."""
|
"""Return the check date one calendar year later, clamping 29 February."""
|
||||||
checked = date.fromisoformat(checked_at)
|
checked = date.fromisoformat(checked_at)
|
||||||
@@ -298,7 +314,7 @@ def validate_wallet_software(payload, keys):
|
|||||||
names = []
|
names = []
|
||||||
seen = set()
|
seen = set()
|
||||||
for entry in entries:
|
for entry in entries:
|
||||||
name = _key_name(entry)
|
name = _key_name(entry, "wallet software name")
|
||||||
folded = name.casefold()
|
folded = name.casefold()
|
||||||
if folded in seen:
|
if folded in seen:
|
||||||
raise ValidationError("wallet software names must be unique")
|
raise ValidationError("wallet software names must be unique")
|
||||||
@@ -436,6 +452,7 @@ def _model(value):
|
|||||||
return None
|
return None
|
||||||
if len(model) > MAX_MODEL_LENGTH:
|
if len(model) > MAX_MODEL_LENGTH:
|
||||||
raise ValidationError("model is too long")
|
raise ValidationError("model is too long")
|
||||||
|
_reject_secret(model, "model")
|
||||||
return model
|
return model
|
||||||
|
|
||||||
|
|
||||||
@@ -466,8 +483,26 @@ def _rotation_type(value, key, name, software_names):
|
|||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
def _key_name(value):
|
def _reject_secret(value, field):
|
||||||
"""Return a configured key name, which must be non-empty text."""
|
"""Refuse text that looks like a wallet secret (sections 2 and 15).
|
||||||
|
|
||||||
|
The caller runs this before it stores anything, so a refused value is never
|
||||||
|
written to the database. ``rejection_message`` names the field and the shape
|
||||||
|
that was recognised, never the value, so the secret does not travel into a
|
||||||
|
response body or a log line.
|
||||||
|
"""
|
||||||
|
label = find_secret(value)
|
||||||
|
if label is not None:
|
||||||
|
raise SecretDetected(rejection_message(field, label))
|
||||||
|
|
||||||
|
|
||||||
|
def _key_name(value, field="key name"):
|
||||||
|
"""Return a configured key name, which must be non-empty text.
|
||||||
|
|
||||||
|
``field`` only names the field in the refusal of a value that looks like a
|
||||||
|
wallet secret, because this helper is shared by the key name and the wallet
|
||||||
|
software name; the other messages keep their existing wording.
|
||||||
|
"""
|
||||||
if not isinstance(value, str):
|
if not isinstance(value, str):
|
||||||
raise ValidationError("key name must be text")
|
raise ValidationError("key name must be text")
|
||||||
name = value.strip()
|
name = value.strip()
|
||||||
@@ -475,6 +510,7 @@ def _key_name(value):
|
|||||||
raise ValidationError("key name must not be empty")
|
raise ValidationError("key name must not be empty")
|
||||||
if len(name) > MAX_KEY_NAME_LENGTH:
|
if len(name) > MAX_KEY_NAME_LENGTH:
|
||||||
raise ValidationError("key name is too long")
|
raise ValidationError("key name is too long")
|
||||||
|
_reject_secret(name, field)
|
||||||
return name
|
return name
|
||||||
|
|
||||||
|
|
||||||
@@ -490,6 +526,7 @@ def _required_path(value, field):
|
|||||||
raise ValidationError(f"{field} must not be empty")
|
raise ValidationError(f"{field} must not be empty")
|
||||||
if len(path) > MAX_PATH_LENGTH:
|
if len(path) > MAX_PATH_LENGTH:
|
||||||
raise ValidationError(f"{field} is too long")
|
raise ValidationError(f"{field} is too long")
|
||||||
|
_reject_secret(path, field)
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
||||||
@@ -738,6 +775,7 @@ def _text(value, field, max_length):
|
|||||||
raise ValidationError(f"{field} must be text")
|
raise ValidationError(f"{field} must be text")
|
||||||
if len(text) > max_length:
|
if len(text) > max_length:
|
||||||
raise ValidationError(f"{field} is too long")
|
raise ValidationError(f"{field} is too long")
|
||||||
|
_reject_secret(text, field)
|
||||||
return text or None
|
return text or None
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user