Skip to content

Comments

feat(config): support Docker Compose _FILE secrets for env vars#5529

Open
themavik wants to merge 2 commits intoInfisical:mainfrom
themavik:feat/docker-secrets-file-env-support-v3
Open

feat(config): support Docker Compose _FILE secrets for env vars#5529
themavik wants to merge 2 commits intoInfisical:mainfrom
themavik:feat/docker-secrets-file-env-support-v3

Conversation

@themavik
Copy link
Contributor

@themavik themavik commented Feb 21, 2026

Adds resolveDockerSecrets() to read _FILE environment variables, enabling Docker Compose secrets support for sensitive configuration.

@maidul98
Copy link
Collaborator

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 21, 2026

Greptile Summary

Added resolveDockerSecrets() function to automatically read Docker Compose/Swarm secrets from *_FILE environment variables.

Key Changes:

  • Imported fs module at line 1
  • Added resolveDockerSecrets() function (lines 23-34) that iterates through all env vars, finds those ending in _FILE, and reads the file contents into the base variable name
  • Function executes immediately on module load (line 35)
  • Removed various code comments throughout the schema definition (cleanup changes)

Critical Security Issue:
The implementation has a path traversal vulnerability that allows reading arbitrary files from the filesystem. Any user who can control environment variables (through container configs, CI/CD, or deployment manifests) can read any file the process has access to, including system files, application secrets, and sensitive data.

Additional Issues:

  • No file size limits - could cause memory DoS by reading large files
  • Silent error handling hides security-relevant failures
  • Missing documentation - users won't know this feature exists

Confidence Score: 1/5

  • This PR introduces a critical path traversal vulnerability that must be fixed before merging
  • Score of 1 reflects the critical security vulnerability allowing arbitrary file reads. While the feature itself is useful for Docker secrets, the implementation lacks basic security controls (path validation, file size limits) that could be exploited by attackers with environment variable control
  • backend/src/lib/config/env.ts requires immediate security fixes for path traversal and DoS vulnerabilities

Important Files Changed

Filename Overview
backend/src/lib/config/env.ts Adds Docker secrets support via _FILE suffix resolution. Found critical path traversal vulnerability allowing arbitrary file reads.

Last reviewed commit: 8ae642e

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 4 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +23 to +34
function resolveDockerSecrets() {
for (const [key, filePath] of Object.entries(process.env)) {
if (!key.endsWith("_FILE") || !filePath) continue;
const baseKey = key.slice(0, -5);
if (process.env[baseKey]) continue;
try {
process.env[baseKey] = fs.readFileSync(filePath, "utf8").trim();
} catch {
// Intentionally silent — downstream Zod schema will report missing required variable
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Critical Path Traversal Vulnerability

Bad actors can use any *_FILE env var to read arbitrary files from the filesystem using path traversal patterns. An attacker with control over environment variables (e.g., through container orchestration misconfigurations, CI/CD injection, or compromised deployment configs) could:

  1. Exfiltrate sensitive files by setting them as config values that get logged or transmitted
  2. Read application secrets from other locations on the filesystem
  3. Access system files like private keys or database configs

Required Fix: Restrict file paths to allowed directories (e.g., /run/secrets/, /var/run/secrets/). Use path.resolve() to get absolute paths and verify they start with an allowed directory prefix before reading.

const baseKey = key.slice(0, -5);
if (process.env[baseKey]) continue;
try {
process.env[baseKey] = fs.readFileSync(filePath, "utf8").trim();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing file size limit allows reading extremely large files into memory, potentially causing DoS. Add max file size check (e.g., 1MB limit) before readFileSync.

Comment on lines +30 to +32
} catch {
// Intentionally silent — downstream Zod schema will report missing required variable
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Silent error handling hides critical issues. If an attacker provides an invalid path, you won't know whether the file doesn't exist or if there's a permission issue. Consider logging errors or at least distinguishing between ENOENT and EACCES.

Comment on lines +16 to +22
/**
* Resolve Docker Compose / Swarm _FILE-suffixed env vars.
* For every env var that ends with _FILE, read the file it points to and
* set the base env var (without the suffix) to the file contents — unless
* the base var is already explicitly set.
* Example: ENCRYPTION_KEY_FILE=/run/secrets/enc_key → ENCRYPTION_KEY=<file contents>
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How will customers discover this _FILE suffix feature? No documentation found in the /docs folder for Docker secrets or _FILE environment variables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants