js: Protect registry tables and namespaces from endpoint writes - #8359
Open
Eddy Ashton (eddyashton) wants to merge 3 commits into
Open
js: Protect registry tables and namespaces from endpoint writes#8359Eddy Ashton (eddyashton) wants to merge 3 commits into
Eddy Ashton (eddyashton) wants to merge 3 commits into
Conversation
BaseDynamicJSEndpointRegistry stores endpoint metadata, module source, compiled QuickJS bytecode and runtime options in KV tables under a configurable prefix (default public:custom_endpoints). check_kv_map_access treats these as ordinary public app tables, so any JS endpoint executing in a read-write transaction could overwrite them, including planting bytecode consumed by KvBytecodeModuleLoader and rewriting endpoint auth policies. The registry now always intersects the app-provided namespace restriction with a built-in one that makes its own tables READ_ONLY. Table names are resolved at request time via a virtual get_registry_managed_tables(), so subclasses which reassign the map names (GovernanceDrivenJSRegistry) or add tables (DynamicJSEndpointRegistry audit tables) are covered without reserving unrelated namespaces. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Reserve the registry namespace by default and allow applications to opt out through the existing namespace restriction setter. Clear cached interpreters when policy changes so retained KV handles cannot preserve stale permissions. Cover defaults, opt-outs, namespace boundaries and policy changes with unit and end-to-end tests. Keep cache extensions source-compatible and document the behavior in the next release. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot started reviewing on behalf of
Eddy Ashton (eddyashton)
September 11, 2026 16:29
View session
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
A critical namespace-protection issue remains unresolved, along with requested regression coverage for reassigned registry tables.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Protects JS registry-managed tables and namespaces from endpoint writes by default, with opt-out support and interpreter-cache invalidation when policies change.
Changes:
- Adds registry table and namespace protections.
- Clears cached interpreters after policy changes.
- Adds unit/e2e coverage and updates release metadata.
File summaries
| File | Description |
|---|---|
tests/programmability.py |
Tests namespace protection and boundaries. |
src/js/test/js.cpp |
Tests restrictions, opt-outs, and cache behavior. |
src/js/registry.cpp |
Applies effective restrictions and cache invalidation. |
src/js/interpreter_cache.h |
Implements interpreter-cache clearing. |
python/pyproject.toml |
Updates the package version. |
include/ccf/js/registry.h |
Defines protection configuration and managed tables. |
include/ccf/js/interpreter_cache_interface.h |
Adds cache-invalidation interface support. |
CMakeLists.txt |
Updates JS test sources. |
CHANGELOG.md |
Documents the behavior change. |
Review details
Suppressed comments (2)
include/ccf/js/registry.h:187
- Please add a regression test for the reassigned-table path represented by
GovernanceDrivenJSRegistry. The new tests only instantiateDynamicJSEndpointRegistrywith tables underpublic:custom_endpoints.*, so they do not exercise this override with thepublic:ccf.gov.*maps assigned byinclude/ccf/js/samples/governance_driven_registry.h:28-33; a regression here could leave the shipped registry tables writable without failing the added coverage.
std::set<std::string> get_registry_managed_tables() const override
{
auto tables =
BaseDynamicJSEndpointRegistry::get_registry_managed_tables();
tables.insert(recent_actions_map);
src/js/test/js.cpp:426
- This loop only tests names in
public:custom_endpoints.*, where the prefix match alone protects them. It does not exercise the purpose of the new exact-table set for a subclass that reassigns a registry member to an application table outside the prefix; add a fixture with such a reassignment. Without this, exact-table protection could regress while all current tests pass.
for (const auto* suffix :
{"modules",
"modules_quickjs_bytecode",
"modules_quickjs_version",
"metadata",
"interpreter_flush",
"runtime_options",
"recent_actions",
"audit.input",
"audit.info",
"my_table"})
{
check_write(
fmt::format("public:custom_endpoints.{}", suffix),
!protect_registry_tables && read_write);
- Files reviewed: 9/9 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| BaseDynamicJSEndpointRegistry::BaseDynamicJSEndpointRegistry( | ||
| ccf::AbstractNodeContext& context, const std::string& kv_prefix) : | ||
| ccf::UserEndpointRegistry(context), | ||
| registry_managed_prefix(fmt::format("{}.", kv_prefix)), |
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
JS endpoints could directly modify registry-managed code and endpoint metadata outside the installation path. This makes those tables and the configured registry namespace read-only by default.
protect_registry_tables = trueto the existing namespace restriction setter. Passingfalseopts out;({}, false)restores platform-only permissions.Validation
js_test,programmability, andjs_generic.js_testandprogrammability_and_jwtwithCR_FILTER=programmability.scripts/ci-checks.sh.