Support environment variable placeholders in config validation - #3
Open
npeham wants to merge 1 commit into
Open
Conversation
The YAML import validation ran the LibreChat configSchema, whose MCP url
field resolves ${ENV_VAR} placeholders against process.env before URL
validation. The admin panel doesn't have each deployment's env vars set,
so placeholders like ${MASTRA_INTERNAL_URL} stayed literal and failed
URL validation, blocking a single canonical config shared across
environments.
Sanitize the parsed config before validation by swapping every string
holding a ${...} placeholder for a unique schema-safe sentinel, then
restore the originals verbatim after validation and AppService run, so
placeholders are preserved in the imported config.
https://claude.ai/code/session_015i1Rwi3ms2TbF1upWF7LbX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds support for environment variable placeholders (e.g.,
${ENV_VAR}) in LibreChat configuration files when imported via the admin panel. The admin panel doesn't have access to deployment-specific environment variables, so placeholders would previously fail schema validation. This change sanitizes placeholders before validation and restores them afterwards, allowing full structural validation while preserving placeholder syntax.Change Type
Implementation Details
New Utilities (
src/server/utils/envPlaceholder.ts)Two complementary functions handle placeholder management:
sanitizeEnvPlaceholders(value)— Recursively walks a config object and replaces any string containing${...}with a unique, schema-safe sentinel URL (https://env-placeholder.invalid/0, etc.), returning both the sanitized config and aMap<sentinel, original>for restoration.restoreEnvPlaceholders(value, placeholders)— Reverses the process by swapping sentinels back to their original placeholder strings using exact equality matching.The sentinel format is deliberately chosen to satisfy URL validators (used in schema constraints like
z.string().url()) while remaining obviously invalid for actual use.Integration (
src/server/config.ts)The
parseImportedYamlserver function now:configSchemaAppServicefailsThis ensures that configs with environment variable placeholders pass validation and are returned with their original placeholder syntax intact.
Testing
Added comprehensive unit tests in
src/server/utils/envPlaceholder.test.ts:configSchemafromlibrechat-data-providerAll tests pass and cover the core functionality and edge cases.
Checklist
https://claude.ai/code/session_015i1Rwi3ms2TbF1upWF7LbX