Skip to content

fix(core): validate module ids when they are deserialized - #117

Merged
htcom-code merged 1 commit into
mainfrom
fix/module-id-validation
Nov 29, 2026
Merged

htcom-code merged 1 commit into
mainfrom
fix/module-id-validation

Conversation

@htcom-code

Copy link
Copy Markdown
Owner

Summary

ModuleId derived Deserialize with #[serde(transparent)], so ids read from the deploy envelope, a signed manifest's id or a stored record skipped ModuleId::parse. The id is a path segment of the filesystem module store and of the worker/OCI control socket (whose directory the OCI runtime bind-mounts), so an unchecked id could escape those roots.

  • protrus-core: ModuleId now deserializes through parse (#[serde(into = "String", try_from = "String")]). The serialized form is unchanged.
  • protrus-store-fs: module_dir checks the id is a single path segment under modules/ (defence in depth; new FsStoreError::UnsafeModuleId).
  • protrus-host: both control-socket paths are built by one helper, worker_control_socket, which applies the same check.
  • protrus-web: a new DeployBody extractor for POST /platform/modules and PUT /platform/modules/{id}. A JSON body serde refuses, including a bad record.module_id, now gets the documented 400 INVALID_ARGUMENT problem (design 24, "bad deploy envelope"; Java maps IllegalArgumentException the same way in ProteanAdminErrorAdvice). Before, it got axum's plain-text 422. A missing or wrong content type still gets axum's own rejection. The manifest route and the MCP deploy tools already reported serde failures, and now reject bad ids too.
  • docs/design/24: non-parity row added. Java stores the descriptor id as given, while Rust validates it.

Shared-lib names, scope names, uses entries and bundle file paths were checked and are already validated before they reach a path.

Closes #116

Verification

  • cargo test --workspace: 38 suites, 408 passed, 0 failed, 6 ignored
  • New tests: module_id_deserializes_only_through_parse (core), a_manifest_id_that_is_not_a_module_id_does_not_deserialize (artifact), a_record_cannot_carry_a_module_id_that_escapes_the_store (store-fs), deploy_rejects_a_body_module_id_that_is_not_a_path_segment (web: POST, PUT and from-manifest)

ModuleId derived Deserialize with serde(transparent), so an id read
from a deploy body, a signed manifest or a stored record skipped
ModuleId::parse. The id is a path segment of the filesystem store and
of the worker/OCI control socket, whose directory the OCI runtime
bind-mounts, so an unchecked id could escape those roots.

- Deserialize ModuleId through parse (try_from = "String")
- Check again that the id stays one path segment where the store
  directory and the control socket path are built
- Answer a deploy JSON body serde refuses with the documented 400
  INVALID_ARGUMENT problem, as the manifest route already does
- Regression tests for deserialization, the deploy routes and the
  filesystem store

Closes #116

Tags: #security #core #web #store
Co-Authored-By: htjulia <htjulia1@gmail.com>
@htcom-code
htcom-code merged commit b64d31a into main Nov 29, 2026
4 checks passed
@htcom-code
htcom-code deleted the fix/module-id-validation branch November 29, 2026 12:31
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.

fix(core): validate module ids when they are deserialized

1 participant