@@ -73,4 +73,71 @@ describe("normalizeProviders", () => {
7373 await fs . rm ( agentDir , { recursive : true , force : true } ) ;
7474 }
7575 } ) ;
76+
77+ it ( "does not copy plaintext api keys from non-env SecretRefs into providers" , async ( ) => {
78+ const agentDir = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "openclaw-agent-" ) ) ;
79+ try {
80+ await fs . writeFile (
81+ path . join ( agentDir , "auth-profiles.json" ) ,
82+ JSON . stringify ( {
83+ version : 1 ,
84+ profiles : {
85+ "openai:default" : {
86+ id : "openai:default" ,
87+ provider : "openai" ,
88+ type : "api_key" ,
89+ key : "sk-live-from-exec" ,
90+ keyRef : { source : "exec" , provider : "default" , id : "keychain:openai" } ,
91+ } ,
92+ } ,
93+ providerOrder : { openai : [ "openai:default" ] } ,
94+ } ) ,
95+ ) ;
96+ const providers : NonNullable < NonNullable < OpenClawConfig [ "models" ] > [ "providers" ] > = {
97+ openai : {
98+ baseUrl : "https://api.openai.com/v1" ,
99+ api : "openai-completions" ,
100+ models : [ { id : "gpt-4.1-mini" , name : "GPT" , input : [ "text" ] , reasoning : false } ] ,
101+ } ,
102+ } ;
103+
104+ const normalized = normalizeProviders ( { providers, agentDir } ) ;
105+ expect ( normalized ?. openai ?. apiKey ) . toBeUndefined ( ) ;
106+ } finally {
107+ await fs . rm ( agentDir , { recursive : true , force : true } ) ;
108+ }
109+ } ) ;
110+
111+ it ( "uses env var name when auth profile uses env SecretRef" , async ( ) => {
112+ const agentDir = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "openclaw-agent-" ) ) ;
113+ try {
114+ await fs . writeFile (
115+ path . join ( agentDir , "auth-profiles.json" ) ,
116+ JSON . stringify ( {
117+ version : 1 ,
118+ profiles : {
119+ "openai:default" : {
120+ id : "openai:default" ,
121+ provider : "openai" ,
122+ type : "api_key" ,
123+ keyRef : { source : "env" , provider : "default" , id : "OPENAI_API_KEY" } ,
124+ } ,
125+ } ,
126+ providerOrder : { openai : [ "openai:default" ] } ,
127+ } ) ,
128+ ) ;
129+ const providers : NonNullable < NonNullable < OpenClawConfig [ "models" ] > [ "providers" ] > = {
130+ openai : {
131+ baseUrl : "https://api.openai.com/v1" ,
132+ api : "openai-completions" ,
133+ models : [ { id : "gpt-4.1-mini" , name : "GPT" , input : [ "text" ] , reasoning : false } ] ,
134+ } ,
135+ } ;
136+
137+ const normalized = normalizeProviders ( { providers, agentDir } ) ;
138+ expect ( normalized ?. openai ?. apiKey ) . toBe ( "OPENAI_API_KEY" ) ;
139+ } finally {
140+ await fs . rm ( agentDir , { recursive : true , force : true } ) ;
141+ }
142+ } ) ;
76143} ) ;
0 commit comments