Skip to content

fix(ets): route ETS-specific functions through sandbox adapter#37

Merged
MikaAK merged 2 commits intoMikaAK:mainfrom
BobbieBarker:fix/ets-sandbox-isolation
Mar 16, 2026
Merged

fix(ets): route ETS-specific functions through sandbox adapter#37
MikaAK merged 2 commits intoMikaAK:mainfrom
BobbieBarker:fix/ets-sandbox-isolation

Conversation

@BobbieBarker
Copy link
Copy Markdown
Contributor

Summary

  • ETS-specific functions (update_counter/2, update_counter/3, insert_raw/1, match_object/1, match_object/2) were bypassing sandbox isolation by calling :ets directly instead of routing through @cache_adapter
  • Added defoverridable wrappers in the __using__ macro (lib/cache.ex) that prefix keys via maybe_sandbox_key and dispatch through @cache_adapter when sandbox?: true and adapter: Cache.ETS
  • The sandbox adapter (Cache.Sandbox) already had implementations for these functions — they just were never called from the generated module

Test plan

  • Added test/cache/ets_sandbox_test.exs with 11 tests verifying sandbox isolation for all affected functions
  • Each function has a test that writes data and a separate test verifying the data is not visible (isolation)
  • All existing tests pass (126/127 — the 1 failure in redis_json_test.exs is pre-existing and unrelated)

@BobbieBarker BobbieBarker force-pushed the fix/ets-sandbox-isolation branch from f201b7c to 5688897 Compare March 7, 2026 18:39
@MikaAK
Copy link
Copy Markdown
Owner

MikaAK commented Mar 9, 2026

I think this is a fundamental problem with the ets adapter, it probably should be calling something the module attribute to allow the sandbox switchover 🤔

@cking222
Copy link
Copy Markdown
Collaborator

cking222 commented Mar 9, 2026

I think this is a fundamental problem with the ets adapter, it probably should be calling something the module attribute to allow the sandbox switchover 🤔

I am open to feedback. If you want this to work differently let me know. I was optimistically trying to use the new ETS functionality you added, and found out that these functions don't play nice with the sandbox, so i whipped something up to cover the gap.

ETS-specific functions in the __using__ macro were calling :ets directly,
bypassing sandbox isolation. Move all calls through @cache_adapter so
the sandbox adapter is used when sandbox?: true is configured.

Add corresponding module-level functions to Cache.ETS that delegate
to :ets, matching the signatures already present in Cache.Sandbox.
@BobbieBarker BobbieBarker force-pushed the fix/ets-sandbox-isolation branch from 5688897 to 857efbf Compare March 10, 2026 20:46
…hing

Without this clause, nested tuples in sandbox data were compared with
strict equality instead of recursive pattern matching via match_pattern?.
@MikaAK MikaAK merged commit 72d2da4 into MikaAK:main Mar 16, 2026
1 check passed
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