feat(assessment): find the attempt behind a leaked task text

This commit is contained in:
shira committed 2026-10-11 13:19:38 +03:00
1 parent bb917bf62e
commit 5a731c25b7
26 files changed
+2500

No files matched your search

+18
View File
@@ -86,6 +86,24 @@ func (config *Config) loadIdentity(lookup LookupEnv) error {
return err
}
// IdentityKeySecretFromEnv reads IDENTITY_KEY_SECRET for an operator command
// that recomputes keyed values of the server, such as the codes of the leak
// trace. It never draws an ephemeral secret: a random one would make every
// value unreadable, and a command that silently searched with it would report
// nothing found. The error never contains the secret.
func IdentityKeySecretFromEnv(lookup LookupEnv) ([]byte, error) {
secret := strings.TrimSpace(valueOrDefault(lookup, "IDENTITY_KEY_SECRET", ""))
switch {
case secret == "":
return nil, errors.New("config.IdentityKeySecretFromEnv - IDENTITY_KEY_SECRET is not set")
case strings.HasPrefix(secret, examplePlaceholderPrefix):
return nil, errors.New("config.IdentityKeySecretFromEnv - IDENTITY_KEY_SECRET is an example placeholder")
case len(secret) < MinIdentityKeySecretBytes:
return nil, fmt.Errorf("config.IdentityKeySecretFromEnv - IDENTITY_KEY_SECRET must have at least %d bytes", MinIdentityKeySecretBytes)
}
return []byte(secret), nil
}
// ValidateIdentity checks the registration settings. Errors never include
// the secret.
func (config Config) ValidateIdentity() error {
+23
View File
@@ -135,3 +135,26 @@ func TestLoadFromEnvRejectsThePlaceholderSecret(t *testing.T) {
t.Fatalf("LoadFromEnv() error = %v, want a refusal that does not quote the value", err)
}
}
func TestIdentityKeySecretFromEnvRefusesWhatTheServerCouldNotUseAndNeverEchoesIt(t *testing.T) {
secret := strings.Repeat("s", MinIdentityKeySecretBytes)
got, err := IdentityKeySecretFromEnv(func(key string) (string, bool) { return " " + secret + " ", key == "IDENTITY_KEY_SECRET" })
if err != nil || string(got) != secret {
t.Fatalf("IdentityKeySecretFromEnv(valid) = %q, %v, want the trimmed secret", got, err)
}
for name, value := range map[string]string{
"unset": "",
"placeholder": "replace-this-with-a-generated-secret-of-enough-length",
"too short": "short-secret",
} {
t.Run(name, func(t *testing.T) {
_, err := IdentityKeySecretFromEnv(func(key string) (string, bool) { return value, key == "IDENTITY_KEY_SECRET" && value != "" })
if err == nil {
t.Fatal("IdentityKeySecretFromEnv() succeeded, want an error")
}
if value != "" && strings.Contains(err.Error(), value) {
t.Fatalf("the error contains the secret: %v", err)
}
})
}
}