mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-31 02:06:52 +00:00
fix(secrets): normalize inline SecretRef token/key to tokenRef/keyRef in runtime snapshot (#31047)
* fix(secrets): normalize inline SecretRef token/key to tokenRef/keyRef in runtime snapshot
When auth-profiles.json uses an inline SecretRef as the token or key
value directly (e.g. `"token": {"source":"file",...}`), the resolved
plaintext was written back to disk on every updateAuthProfileStoreWithLock
call, overwriting the SecretRef.
Root cause: collectTokenProfileAssignment and collectApiKeyProfileAssignment
detected inline SecretRefs but did not promote them to the canonical
tokenRef/keyRef fields. saveAuthProfileStore only strips plaintext when
tokenRef/keyRef is set, so the inline case fell through and persisted
plaintext on every save.
Fix: when an inline SecretRef is detected and no explicit tokenRef/keyRef
exists, promote it to the canonical field and delete the inline form.
saveAuthProfileStore then correctly strips the resolved plaintext on write.
Fixes #29108
* fix test: cast inline SecretRef loadAuthStore mocks to AuthProfileStore
* fix(secrets): fix TypeScript type error in runtime test loadAuthStore lambda
* test(secrets): keep explicit keyRef precedence over inline key ref
---------
Co-authored-by: Peter Steinberger <steipete@gmail.com>
This commit is contained in:
@@ -241,6 +241,10 @@ function collectApiKeyProfileAssignment(params: {
|
||||
if (!resolvedKeyRef) {
|
||||
return;
|
||||
}
|
||||
if (inlineKeyRef && !keyRef) {
|
||||
params.profile.keyRef = inlineKeyRef;
|
||||
delete (params.profile as unknown as Record<string, unknown>).key;
|
||||
}
|
||||
if (keyRef && isNonEmptyString(params.profile.key)) {
|
||||
params.context.warnings.push({
|
||||
code: "SECRETS_REF_OVERRIDES_PLAINTEXT",
|
||||
@@ -271,6 +275,10 @@ function collectTokenProfileAssignment(params: {
|
||||
if (!resolvedTokenRef) {
|
||||
return;
|
||||
}
|
||||
if (inlineTokenRef && !tokenRef) {
|
||||
params.profile.tokenRef = inlineTokenRef;
|
||||
delete (params.profile as unknown as Record<string, unknown>).token;
|
||||
}
|
||||
if (tokenRef && isNonEmptyString(params.profile.token)) {
|
||||
params.context.warnings.push({
|
||||
code: "SECRETS_REF_OVERRIDES_PLAINTEXT",
|
||||
|
||||
Reference in New Issue
Block a user