BR-002: name a pasted secret before the field length limit

This commit is contained in:
ai-bot committed 2026-10-14 15:15:58 +00:00
1 parent 60329bad61
commit 0a467ba6a2
1 file changed
+13 -5
+13 -5
View File
@@ -54,7 +54,9 @@ already holds (section 28).
Every free-text field is also checked against ``secret_guard`` before it is 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 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 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). and the shape that was recognised, never the value (sections 2 and 15). It runs
before the length limit of the field, so a secret is always answered with what it
looks like rather than with "too long".
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).
@@ -450,9 +452,9 @@ def _model(value):
model = value.strip() model = value.strip()
if not model: if not model:
return None return None
_reject_secret(model, "model")
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
@@ -490,6 +492,12 @@ def _reject_secret(value, field):
written to the database. ``rejection_message`` names the field and the shape 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 that was recognised, never the value, so the secret does not travel into a
response body or a log line. response body or a log line.
It also runs **before** the length limit of the field it belongs to. The
other way round a seed phrase pasted into a short label field would be
answered with "too long", which invites the user to shorten the phrase
instead of removing it. The length limit stays as the outer bound and is
still applied to everything the guard lets through.
""" """
label = find_secret(value) label = find_secret(value)
if label is not None: if label is not None:
@@ -508,9 +516,9 @@ def _key_name(value, field="key name"):
name = value.strip() name = value.strip()
if not name: if not name:
raise ValidationError("key name must not be empty") raise ValidationError("key name must not be empty")
_reject_secret(name, field)
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
@@ -524,9 +532,9 @@ def _required_path(value, field):
path = value.strip() path = value.strip()
if not path: if not path:
raise ValidationError(f"{field} must not be empty") raise ValidationError(f"{field} must not be empty")
_reject_secret(path, field)
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
@@ -773,9 +781,9 @@ def _text(value, field, max_length):
text = value.strip() text = value.strip()
else: else:
raise ValidationError(f"{field} must be text") raise ValidationError(f"{field} must be text")
_reject_secret(text, field)
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