File tree Expand file tree Collapse file tree 5 files changed +24
-1
lines changed
libs/react-client/src/types Expand file tree Collapse file tree 5 files changed +24
-1
lines changed Original file line number Diff line number Diff line change 7878# Enable third parties caching (e.g., LangChain cache)
7979cache = false
8080
81+ # Whether to persist user environment variables (API keys) to the database
82+ # Set to true to store user env vars in DB, false to exclude them for security
83+ persist_user_env = false
84+
85+ # Whether to mask user environment variables (API keys) in the UI with password type
86+ # Set to true to show API keys as ***, false to show them as plain text
87+ mask_user_env = false
88+
8189# Authorized origins
8290allow_origins = ["*"]
8391
@@ -399,6 +407,10 @@ class ProjectSettings(BaseModel):
399407 user_session_timeout : int = 1296000 # 15 days
400408 # Enable third parties caching (e.g LangChain cache)
401409 cache : bool = False
410+ # Whether to persist user environment variables (API keys) to the database
411+ persist_user_env : Optional [bool ] = False
412+ # Whether to mask user environment variables (API keys) in the UI with password type
413+ mask_user_env : Optional [bool ] = False
402414
403415
404416class ChainlitConfigOverrides (BaseModel ):
Original file line number Diff line number Diff line change @@ -838,6 +838,7 @@ async def project_settings(
838838 "ui" : cfg .ui .model_dump (),
839839 "features" : cfg .features .model_dump (),
840840 "userEnv" : cfg .project .user_env ,
841+ "maskUserEnv" : cfg .project .mask_user_env ,
841842 "dataPersistence" : data_layer is not None ,
842843 "threadResumable" : bool (config .code .on_chat_resume ),
843844 "markdown" : markdown ,
Original file line number Diff line number Diff line change @@ -141,13 +141,21 @@ async def persist_file(
141141 return {"id" : file_id }
142142
143143 def to_persistable (self ) -> Dict :
144+ from chainlit .config import config
144145 from chainlit .user_session import user_sessions
145146
146147 user_session = user_sessions .get (self .id ) or {} # type: Dict
147148 user_session ["chat_settings" ] = self .chat_settings
148149 user_session ["chat_profile" ] = self .chat_profile
149150 user_session ["client_type" ] = self .client_type
150- metadata = clean_metadata (user_session )
151+
152+ # Check config setting for whether to persist user environment variables
153+ user_session_copy = user_session .copy ()
154+ if not config .project .persist_user_env :
155+ # Remove user environment variables (API keys) before persisting to database
156+ user_session_copy ["env" ] = {}
157+
158+ metadata = clean_metadata (user_session_copy )
151159 return metadata
152160
153161
Original file line number Diff line number Diff line change @@ -86,6 +86,7 @@ const Env = () => {
8686 < Label htmlFor = { key } > { key } </ Label >
8787 < Input
8888 id = { key }
89+ type = { config ?. maskUserEnv !== false ? "password" : "text" }
8990 { ...register ( key ) }
9091 className = {
9192 touchedFields [ key ] && errors [ key ] ? 'border-red-500' : ''
Original file line number Diff line number Diff line change @@ -82,6 +82,7 @@ export interface IChainlitConfig {
8282 } ;
8383 debugUrl ?: string ;
8484 userEnv : string [ ] ;
85+ maskUserEnv ?: boolean ;
8586 dataPersistence : boolean ;
8687 threadResumable : boolean ;
8788 chatProfiles : ChatProfile [ ] ;
You can’t perform that action at this time.
0 commit comments