Reject untrusted Lua bytecode while preserving script caching - #2138
Open
Tiago Nápoli (tiagonapoli) wants to merge 24 commits into
Open
Tiago Nápoli (tiagonapoli) wants to merge 24 commits into
Tiago Nápoli (tiagonapoli) wants to merge 24 commits into
Conversation
added 9 commits
September 15, 2026 14:34
Keep application bytecode caching while requiring customer input to compile in text-only mode and tagging internally generated chunks for binary-only loading. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ec2a6abf-4bb4-48e1-a752-32672cb07303
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ec2a6abf-4bb4-48e1-a752-32672cb07303
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ec2a6abf-4bb4-48e1-a752-32672cb07303
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ec2a6abf-4bb4-48e1-a752-32672cb07303
Generate the test bytecode directly through Garnet's internal compiler instead of round-tripping through a Lua script. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ec2a6abf-4bb4-48e1-a752-32672cb07303
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ec2a6abf-4bb4-48e1-a752-32672cb07303
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ec2a6abf-4bb4-48e1-a752-32672cb07303
Keep regression coverage focused on supported network-facing scripting workflows. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ec2a6abf-4bb4-48e1-a752-32672cb07303
Remove the unrelated ScriptHashKey allocation refactor from the Lua bytecode fix. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ec2a6abf-4bb4-48e1-a752-32672cb07303
Tiago Nápoli (tiagonapoli)
marked this pull request as ready for review
September 16, 2026 17:21
Copilot started reviewing on behalf of
Tiago Nápoli (tiagonapoli)
September 16, 2026 17:21
View session
Replace the implicit source-data constructor with a named FromSource factory. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ec2a6abf-4bb4-48e1-a752-32672cb07303
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The claimed host-inserted source-cache behavior lacks automated regression coverage.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Hardens Lua scripting by treating customer input as text while retaining Garnet-generated bytecode caching.
Changes:
- Adds explicit text and trusted-binary chunk types and loading modes.
- Compiles source safely before caching internal bytecode.
- Adds bytecode rejection and exact-length parsing tests.
File summaries
| File | Description |
|---|---|
LuaScriptTests.cs |
Adds scripting security regressions. |
LuaScriptRunnerTests.cs |
Tests compilation and chunk tagging. |
SessionScriptCache.cs |
Separates source compilation from cached loading. |
NativeMethods.cs |
Adds text-only and binary-only native loaders. |
LuaStateWrapper.cs |
Exposes mode-specific loading wrappers. |
LuaScriptHandle.cs |
Tags cached script data by origin. |
LuaRunner.Loader.cs |
Safely compiles source into bytecode. |
LuaRunner.Functions.cs |
Propagates chunk loading mode. |
LuaRunner.cs |
Distinguishes public source from internal bytecode. |
LuaCommands.cs |
Routes commands through secure loading paths. |
LuaScriptCacheOperations.cs |
Updates cache benchmarks for the new APIs. |
Review details
- Files reviewed: 11/11 changed files
- Comments generated: 1
- Review effort level: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+210
to
+213
| if (luaScriptHandle.Chunk.Kind == LuaScriptChunkKind.GarnetGeneratedBinary) | ||
| return TryLoadCompiled(session, luaScriptHandle.Chunk, digest, ref luaScriptHandle, out runner, out digestOnHeap); | ||
|
|
||
| return TryCompileAndLoad(session, luaScriptHandle.ScriptData.Span, digest, ref luaScriptHandle, out runner, out digestOnHeap); |
added 13 commits
September 16, 2026 10:37
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ec2a6abf-4bb4-48e1-a752-32672cb07303
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ec2a6abf-4bb4-48e1-a752-32672cb07303
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ec2a6abf-4bb4-48e1-a752-32672cb07303
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ec2a6abf-4bb4-48e1-a752-32672cb07303
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ec2a6abf-4bb4-48e1-a752-32672cb07303
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ec2a6abf-4bb4-48e1-a752-32672cb07303
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ec2a6abf-4bb4-48e1-a752-32672cb07303
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ec2a6abf-4bb4-48e1-a752-32672cb07303
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ec2a6abf-4bb4-48e1-a752-32672cb07303
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ec2a6abf-4bb4-48e1-a752-32672cb07303
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ec2a6abf-4bb4-48e1-a752-32672cb07303
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ec2a6abf-4bb4-48e1-a752-32672cb07303
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ec2a6abf-4bb4-48e1-a752-32672cb07303
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
EVALandSCRIPT LOADloadstringcompatibility handlingSecurity boundary
Customer input is always treated as source text and compiled with mode
t. Only successful internal compilation produces aGarnetGeneratedBinarychunk, which is cached and subsequently loaded with modeb. The publicLuaScriptHandleconstructor creates source-text handles, so arbitrary host-provided bytes cannot opt into binary loading.Testing
EVAL,SCRIPT LOAD, cache exclusion, blocked side effects, compilation failure output, embedded NUL input, host-inserted source, and cross-session cachingSupersedes #2111 while retaining bytecode caching.