GHSA-jjq7-m736-w977: Code Injection
Summary
COSMOS reads configuration from a user-writable overlay (targetsmodified/) before the read-only plugin-installed targets/ tree, and the config subsystem executes code on those files: ConfigParser renders every file as ERB by default, a GENERICREADCONVERSION / GENERICWRITECONVERSION block is evaluated as code by GenericConversion (Ruby and Python), and the Script Runner suite analysis requires a procedure file. An authenticated user can write into targetsmodified/ below the admin tier (the storage-upload endpoint exempts that area from the admin gate, and the screen-save endpoint stores its body verbatim there), so the same root cause is reachable through several features, each giving arbitrary code execution on a COSMOS server.
Three vulnerable routes were identified, all reachable by an authenticated non-admin user (in the open-source edition authorize ignores the permission string, so any authenticated user qualifies):
1. Table definitions (immediate). tables#generate|report|load reads a definition from targetsmodified/ and ERB-renders it and evaluates its GENERICCONVERSION block in the cmd-tlm-api container. 2. Command/telemetry definitions (persistent). A file written to targetsmodified/<TARGET>/cmdtlm/ is overlaid by System.setuptargets and processed by PacketConfig in the decom/multi microservices: ERB-rendered in the Ruby implementation, and GENERIC-evaluated in both the Ruby and Python implementations (the Python ConfigParser does not run ERB). It executes on the next microservice (re)start. 3. Script Runner suites (immediate). A procedure written to targetsmodified/<TARGET>/procedures/ is required by the suite analysis, reachable at the read-only scriptview tier through scripts#body and runningscript#show (the analysis subprocess is spawned when OPENC3SERVICEPASSWORD is configured, which it is in the shipped .env).
Details
Root cause. TargetFile.body (Ruby openc3/lib/openc3/utilities/targetfile.rb, Python openc3/python/openc3/utilities/targetfile.py) reads {scope}/targetsmodified/{name} before {scope}/targets/{name}. The storage-upload endpoint storagecontroller.rb getuploadpresignedrequest is gated at systemset and exempts targetsmodified/ and tmp/ from its admin check (so a write there is not admin-gated); for a target path it additionally calls authorizebucketpath, which in the permission-enforcing edition requires tlm on the target, while in the open-source edition authorize ignores the permission string entirely. screenscontroller.rb create (systemset) stores its request body verbatim under targetsmodified/<target>/screens/. So a non-admin can place files in the overlay. The config subsystem then executes them.
Sink 1, ERB. ConfigParser#parsefile renders the file as ERB before parsing (runerb defaults to true): ruby openc3/lib/openc3/config/configparser.rb:402 output = ERB.new(File.read(filename)...commenterb(), trimmode: "-").result(...) Reached for table definitions via tablescontroller.rb -> Table.getdefinitions -> TableConfig.processfile -> parsefile, and for cmd/tlm definitions via System.setuptargets (system.rb, whose overlay loop copies targetsmodified/<T>/cmdtlm/ over the read-only files) -> PacketConfig#processfile -> parsefile.
Sink 2, GENERIC conversion. PacketConfig/TableConfig build a GenericConversion from a GENERICREADCONVERSIONSTART .. END / GENERICWRITECONVERSIONSTART .. END block, and GenericConversion#call evaluates it (independent of ERB): ruby openc3/lib/openc3/conversions/genericconversion.rb (call) eval(@codetoeval) Python openc3/python/openc3/conversions/genericconversion.py (call): compile()/exec()/eval() The read conversion fires on tables#report/load and during telemetry decom; the write conversion fires on tables#generate and on restoredefaults.
Sink 3, suite require. The Script Runner suite analysis executes the file: ruby openc3-cosmos-script-runner-api/scripts/runsuiteanalysis.rb:24 require ARGV[1] # runs all top-level code of the supplied file reached from Script.processsuite, invoked by scripts#body and runningscript#show (both scriptview) and scripts#create (scriptedit) when the file matches the suite pattern.
Permission tiers. Writing the payload needs systemset (screen save, storage upload) or scriptedit (script create); triggering needs system (tables) or scriptview (suite). These are below the tiers where COSMOS gates code execution elsewhere (plugin install requires admin, running a script requires scriptrun).
PoC
Table definition path, against a standard stack. Benign payload writes id to a marker file. This PoC uses the open-source password login; in the permission-enforcing edition substitute a bearer token for a user holding the permissions noted above. bash BASE=http://localhost:2900/openc3-api # adjust to your deployment TOKEN=$(curl -s -X POST "$BASE/auth/verify" -H 'Content-Type: application/json' -d '{"password":"<your password>"}')
1) Write the payload into targetsmodified/ via the screen save endpoint. curl -s -X POST "$BASE/screen" -H "Authorization: $TOKEN" \ --data-urlencode 'scope=DEFAULT' --data-urlencode 'target=INST' --data-urlencode 'screen=poc' \ --data-urlencode $'text=SCREEN AUTO AUTO 1.0\n<%= File.write("/tmp/erbrcepoc", id) %>\nLABEL poc'
2) Trigger by pointing a table action at that file. curl -s -X POST "$BASE/tables/generate" -H "Authorization: $TOKEN" \ --data-urlencode 'scope=DEFAULT' --data-urlencode 'definition=INST/screens/poc.txt' Then in the cmd-tlm-api container: cat /tmp/erbrcepoc shows uid=1001(openc3) .... The tables/generate request returns HTTP 500 (the screen lines are not valid table keywords); the marker shows the code already ran.
The same outcome without ERB, using the GENERIC sink, on the same tables/generate trigger: TABLE "data" BIGENDIAN KEYVALUE "poc" APPENDPARAMETER "item1" 8 UINT 0 255 0 "Item" GENERICWRITECONVERSIONSTART id > /tmp/erbrcepoc 0 GENERICWRITECONVERSIONEND
cmd/tlm path: upload a telemetry definition containing the same ERB or GENERIC block to targetsmodified/<TARGET>/cmdtlm/<file>.txt via the storage-upload presigned request (systemset), then the code runs in that target's decom microservice on its next restart. Suite path: write a suite-shaped procedure to targetsmodified/<TARGET>/procedures/<x>.rb and call scripts#body on it at scriptview.
The ERB table chain was confirmed end to end over HTTP against a booted Rails and puma instance.
Impact
Arbitrary code execution as the openc3 user in the cmd-tlm-api container and the per-target decom microservices and the script-runner. Those processes hold the Redis and bucket credentials and sit on the internal service network, so the executed code acts with that authority over configuration, telemetry, and command data across scopes. The API is served through Traefik, which the shipped compose binds to 127.0.0.1:2900, so a default single-host install is reachable only from the host; a multi-user deployment exposes the web port, and the AV:N rating reflects that standard remote-operator exposure.
All paths require valid authentication, and the triggering permissions (system/systemset/scriptview) are below the admin/scriptrun/plugin-install tiers where COSMOS gates code execution. In the open-source edition authorize checks only token validity and does not enforce the permission string, so any authenticated user can perform these requests.
Suggested fix
The fix is to treat the user-writable overlay as data, never code, and to gate the writers, applied uniformly: - Load table and cmd/tlm definitions for code-execution paths from the read-only targets/ tree only, or parse the targetsmodified overlay with ERB disabled (runerb=false); dynamically-created packet definitions are structural and never need ERB, so this does not regress that feature. - Allow only admin and the server-side dynamic-packet mechanism to write a cmdtlm overlay; reject non-canonical object keys so a positional path check cannot be bypassed by a key the object store normalizes differently. - Run the Script Runner suite analysis (which executes the file) only at the scriptrun tier, at every entry point. - Mirror the definition-read change in the Python implementation.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
rubygems/openc3to a version that resolves this vulnerability.Fixed in 7.3.0 - Configuration
For code-execution paths, load table and cmd/tlm definitions from the read-only targets/ tree only, or parse targets_modified/ with run_erb=false; apply the same definition-read behavior in the Python implementation.
ConfigParser and table/cmd-tlm definition readers in Ruby and Python run_erb = false - Compensating control
Allow only admin users and the server-side dynamic-packet mechanism to write the targets_modified/<TARGET>/cmd_tlm/ overlay, and reject non-canonical object keys before positional path checks so normalized keys cannot bypass authorization.
- Compensating control
Require the script_run permission tier for Script Runner suite analysis at every entry point, including scripts#body, running_script#show, and scripts#create, so suite files are not executed at the script_view or script_edit tiers.
Event History
Frequently Asked Questions
Who can exploit this issue?
An authenticated non-admin user can exploit the identified routes. In the open-source edition, the authorization check ignores the requested permission string, so any authenticated user qualifies.
Is administrator access required to place malicious files in the affected location?
No. The storage-upload endpoint exempts targets_modified/ from the admin gate, and the screen-save endpoint stores its request body verbatim in that user-writable overlay.
Where does code run when the table-definition route is used?
For tables#generate, tables#report, or tables#load, a definition from targets_modified/ is ERB-rendered and its GENERIC_READ_CONVERSION or GENERIC_WRITE_CONVERSION block is evaluated in the cmd-tlm-api container. This route provides immediate arbitrary code execution.