Skip to content

Secret file path validation - #3791

Open
jmthomas wants to merge 6 commits into
mainfrom
secret-file-path-validation
Open

Secret file path validation#3791
jmthomas wants to merge 6 commits into
mainfrom
secret-file-path-validation

Conversation

@jmthomas

Copy link
Copy Markdown
Member

What changed

Validate that file paths passed to the SECRET keyword must be contained within /tmp (by default)

Why it changed

Allowing any file path would allow users to locate sensitive files in the filesystem

Testing strategy

Unit tests

jmthomas and others added 3 commits August 30, 2026 15:57
SECRET FILE paths are destinations COSMOS writes and reads back, so they
are now required to resolve inside /tmp (override with
OPENC3_SECRET_FILE_DIR). Paths are validated when a plugin is installed
and again at the read and write sinks in Ruby and Python.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Replace the manual dirname walk and string slicing with Pathname#ascend
and #relative_path_from. Also reject a broken symlink in the path, which
the previous exist? check skipped over: opening such a path for writing
creates the file the symlink points at.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Compare the expanded path against the base directory instead of
resolving it on disk. Validation now gives the same answer in every
container, since plugin install and the operator write run in different
ones and see different filesystems.

The operator resolves symlinks itself before writing a secret, which is
where the filesystem being checked is the one being written to.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@jmthomas
jmthomas requested review from clayandgen and mcosgriff and a lite review from Copilot August 31, 2026 00:00
@codecov

codecov Bot commented Aug 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.76923% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.27%. Comparing base (6affc24) to head (a082c8a).

Files with missing lines Patch % Lines
...enc3/lib/openc3/operators/microservice_operator.rb 77.77% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3791      +/-   ##
==========================================
+ Coverage   79.22%   79.27%   +0.05%     
==========================================
  Files         894      894              
  Lines       67034    67112      +78     
  Branches     2553     2601      +48     
==========================================
+ Hits        53105    53201      +96     
+ Misses      13267    13247      -20     
- Partials      662      664       +2     
Flag Coverage Δ
frontend 65.99% <ø> (-0.15%) ⬇️
python 79.39% <ø> (+0.04%) ⬆️
ruby-api 82.32% <ø> (+0.06%) ⬆️
ruby-backend 84.64% <90.76%> (+0.12%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens SECRET FILE handling by restricting secret file destinations to a controlled base directory (default /tmp, configurable via OPENC3_SECRET_FILE_DIR), reducing the risk of reading/writing arbitrary host filesystem paths via plugin configuration.

Changes:

  • Add lexical secret file path validation (secret_file_dir + validate_file_path) in both Ruby and Python Secrets utilities, and apply it to FILE secret reads.
  • Enforce SECRET / BRIDGE_SECRET validation in models at config-parse time and add operator-side checks to prevent symlink-based escapes when writing secrets.
  • Add unit tests and update docs/config metadata to document the new constraints.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
openc3/spec/utilities/secrets_spec.rb New Ruby unit coverage for secret file dir + path validation and FILE secret setup behavior
openc3/spec/operators/microservice_operator_spec.rb New operator specs covering safe secret file writes + symlink-related rejection
openc3/spec/models/microservice_model_spec.rb New specs validating SECRET parsing + rejecting out-of-base FILE paths
openc3/spec/models/interface_model_spec.rb New specs validating SECRET/BRIDGE_SECRET parsing + rejecting out-of-base FILE paths
openc3/python/test/utilities/test_secrets.py New Python unit coverage for secret file dir + path validation and FILE secret setup behavior
openc3/python/openc3/utilities/secrets.py Implement secret_file_dir/validate_file_path and enforce validation on FILE reads
openc3/lib/openc3/utilities/secrets.rb Implement secret_file_dir/validate_file_path (+ containment helper) and enforce validation on FILE reads
openc3/lib/openc3/operators/microservice_operator.rb Validate/normalize FILE secret destinations and add realpath/symlink checks before writing
openc3/lib/openc3/models/microservice_model.rb Validate SECRET definitions (type + FILE path restriction) during config handling
openc3/lib/openc3/models/interface_model.rb Validate SECRET/BRIDGE_SECRET definitions (type + FILE path restriction) during config handling
openc3/data/config/microservice.yaml Document FILE path restriction in keyword parameter descriptions
openc3/data/config/interface_modifiers.yaml Document FILE path restriction for SECRET and BRIDGE_SECRET
docs.openc3.com/docs/development/microservices.md Update docs example and explain FILE secret destination restrictions

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread openc3/lib/openc3/models/microservice_model.rb
Comment thread openc3/lib/openc3/models/interface_model.rb
Comment thread openc3/lib/openc3/operators/microservice_operator.rb Outdated
Store the uppercased secret type and the expanded FILE path back into the
parsed parameters so downstream ENV/FILE comparisons and file writes see
canonical values. In the operator, validate the deepest existing directory
before mkdir_p so a symlinked component can no longer cause directories to
be created outside the secret file dir, and log distinct errors for a
symlinked file versus a path escaping the base.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

@clayandgen clayandgen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Include OPENC3_SECRET_FILE_DIR in the .env / compose.yaml ?

@sonarqubecloud

sonarqubecloud Bot commented Sep 3, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
21.2% Duplication on New Code (required ≤ 3%)
Vulnerabilities with severity Critical found (required < Minor)
Bugs with severity Major found (required < Minor)
Code smells with severity Major found (required < Major)

See analysis details on SonarQube Cloud

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.

3 participants