Skip to content

Fix lua-enable-insecure-api default value cannot be changed to yes - #3548

Merged
enjoy-binbin merged 2 commits into
valkey-io:unstablefrom
enjoy-binbin:allow_insecure_api
Apr 27, 2026
Merged

enjoy-binbin merged 2 commits into
valkey-io:unstablefrom
enjoy-binbin:allow_insecure_api

Conversation

@enjoy-binbin

Copy link
Copy Markdown
Member

The default value of lua-enable-insecure-api cannot be safely changed
from no to yes due to two issues:

  1. In createEngineContext(), lua_enable_insecure_api was hardcoded to 0
    before initializing Lua states, so deprecated APIs (newproxy, setfenv,
    getfenv) were never registered in the global table regardless of the
    actual config value. Once the global table is locked, the config
    change has no effect.

  2. lua_insecure_api_current was initialized to 0 (struct zero-init) and
    never synced with the final config value. If the default was changed
    to yes(1), a subsequent CONFIG SET no would see both values as 0 and
    skip the evalReset() call in updateLuaEnableInsecureApi().

Fix by reading the real config via isLuaInsecureAPIEnabled() in
createEngineContext() before Lua state initialization, and syncing
lua_insecure_api_current after all config sources (default, config file,
command-line args) are applied.

The default value of lua-enable-insecure-api cannot be safely changed
from no to yes due to two issues:

1. In createEngineContext(), lua_enable_insecure_api was hardcoded to 0
   before initializing Lua states, so deprecated APIs (newproxy, setfenv,
   getfenv) were never registered in the global table regardless of the
   actual config value. Once the global table is locked, the config
   change has no effect.

2. lua_insecure_api_current was initialized to 0 (struct zero-init) and
   never synced with the final config value. If the default was changed
   to yes(1), a subsequent CONFIG SET no would see both values as 0 and
   skip the evalReset() call in updateLuaEnableInsecureApi().

Fix by reading the real config via isLuaInsecureAPIEnabled() in
createEngineContext() before Lua state initialization, and syncing
lua_insecure_api_current after all config sources (default, config file,
command-line args) are applied.

Signed-off-by: Binbin <[email protected]>
@codecov

codecov Bot commented Apr 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.35%. Comparing base (9709843) to head (fd0f7ef).
⚠️ Report is 15 commits behind head on unstable.

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #3548      +/-   ##
============================================
- Coverage     76.46%   76.35%   -0.12%     
============================================
  Files           159      159              
  Lines         81675    80055    -1620     
============================================
- Hits          62454    61125    -1329     
+ Misses        19221    18930     -291     
Files with missing lines Coverage Δ
src/server.c 89.50% <100.00%> (+0.09%) ⬆️

... and 125 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Signed-off-by: Binbin <[email protected]>

@rjd15372 rjd15372 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@enjoy-binbin enjoy-binbin moved this to To be backported in Valkey 7.2 Apr 27, 2026
@enjoy-binbin enjoy-binbin moved this to To be backported in Valkey 8.0 Apr 27, 2026
@enjoy-binbin enjoy-binbin moved this to To be backported in Valkey 8.1 Apr 27, 2026
@enjoy-binbin enjoy-binbin moved this to To be backported in Valkey 9.0 Apr 27, 2026
@enjoy-binbin enjoy-binbin moved this to To be backported in Valkey 9.1 Apr 27, 2026
@enjoy-binbin
enjoy-binbin merged commit a3e44a5 into valkey-io:unstable Apr 27, 2026
58 checks passed
@enjoy-binbin
enjoy-binbin deleted the allow_insecure_api branch April 27, 2026 03:04
sarthakaggarwal97 pushed a commit to sarthakaggarwal97/valkey that referenced this pull request Apr 27, 2026
…alkey-io#3548)

The default value of lua-enable-insecure-api cannot be safely changed
from no to yes due to two issues:

1. In createEngineContext(), lua_enable_insecure_api was hardcoded to 0
before initializing Lua states, so deprecated APIs (newproxy, setfenv,
   getfenv) were never registered in the global table regardless of the
   actual config value. Once the global table is locked, the config
   change has no effect.

2. lua_insecure_api_current was initialized to 0 (struct zero-init) and
   never synced with the final config value. If the default was changed
   to yes(1), a subsequent CONFIG SET no would see both values as 0 and
   skip the evalReset() call in updateLuaEnableInsecureApi().

Fix by reading the real config via isLuaInsecureAPIEnabled() in
createEngineContext() before Lua state initialization, and syncing
lua_insecure_api_current after all config sources (default, config file,
command-line args) are applied.

Signed-off-by: Binbin <[email protected]>
madolson pushed a commit that referenced this pull request Apr 27, 2026
…3548)

The default value of lua-enable-insecure-api cannot be safely changed
from no to yes due to two issues:

1. In createEngineContext(), lua_enable_insecure_api was hardcoded to 0
before initializing Lua states, so deprecated APIs (newproxy, setfenv,
   getfenv) were never registered in the global table regardless of the
   actual config value. Once the global table is locked, the config
   change has no effect.

2. lua_insecure_api_current was initialized to 0 (struct zero-init) and
   never synced with the final config value. If the default was changed
   to yes(1), a subsequent CONFIG SET no would see both values as 0 and
   skip the evalReset() call in updateLuaEnableInsecureApi().

Fix by reading the real config via isLuaInsecureAPIEnabled() in
createEngineContext() before Lua state initialization, and syncing
lua_insecure_api_current after all config sources (default, config file,
command-line args) are applied.

Signed-off-by: Binbin <[email protected]>
@sarthakaggarwal97 sarthakaggarwal97 added the release-notes This issue should get a line item in the release notes label Apr 28, 2026
@sarthakaggarwal97 sarthakaggarwal97 moved this from To be backported to Done in Valkey 9.1 May 16, 2026
sarthakaggarwal97 pushed a commit that referenced this pull request Jul 17, 2026
…yes (#3548) (#4182)

Backport of #3548 to 9.0. Picked up from the "Needs attention" list in
sweep #4167,
which skipped it because the target branch lacks
src/modules/lua/engine_lua.c.

**Adaptation for 9.0:** only fix #2 from the original PR (the
`lua_insecure_api_current` sync in server.c) applies here. Fix #1 does
not
exist on 9.0: the Lua engine is not modularized on this branch
(src/lua/, not
src/modules/lua/), there is no per-engine-context
`lua_enable_insecure_api`
field hardcoded to 0, and the deprecated-API allowlist gate reads
`server.lua_enable_insecure_api` directly in `luaNewIndexAllowList`
(script_lua.c). Since `evalInit()` runs in `initServer()` after
`loadServerConfig()`, the config-file value is already honored at Lua
state
initialization. The engine_lua.c hunk is therefore dropped.

**Validation on 9.0:**
- Full `unit/scripting` suite passes with the fix
- Both new tests fail without the fix with the expected symptom:
`getfenv()`
remains accessible after `CONFIG SET lua-enable-insecure-api no` because
`updateLuaEnableInsecureApi()` sees `0 != 0` as false and skips
`evalReset()`

Signed-off-by: Binbin <[email protected]>
Co-authored-by: Binbin <[email protected]>
sarthakaggarwal97 pushed a commit that referenced this pull request Jul 17, 2026
…3548)

The default value of lua-enable-insecure-api cannot be safely changed
from no to yes due to two issues:

1. In createEngineContext(), lua_enable_insecure_api was hardcoded to 0
   before initializing Lua states, so deprecated APIs (newproxy, setfenv,
   getfenv) were never registered in the global table regardless of the
   actual config value. Once the global table is locked, the config
   change has no effect.

2. lua_insecure_api_current was initialized to 0 (struct zero-init) and
   never synced with the final config value. If the default was changed
   to yes(1), a subsequent CONFIG SET no would see both values as 0 and
   skip the evalReset() call in updateLuaEnableInsecureApi().

Fix by reading the real config via isLuaInsecureAPIEnabled() in
createEngineContext() before Lua state initialization, and syncing
lua_insecure_api_current after all config sources (default, config file,
command-line args) are applied.

8.1 backport note: only fix #2 (the lua_insecure_api_current sync in
server.c) applies to this branch. Bug #1 does not exist on 8.1: there is
no per-engine-context lua_enable_insecure_api field hardcoded to 0 --
the Lua engine has not been modularized here (src/lua/, not
src/modules/lua/). The deprecated-API allowlist gate reads
server.lua_enable_insecure_api directly (script_lua.c
luaNewIndexAllowList), and evalInit() runs in initServer() after
loadServerConfig(), so the config-file value is already honored at Lua
state initialization. The engine_lua.c hunk is therefore dropped.
Validated: the two new tests fail on 8.1 without the server.c sync and
pass with it.

Signed-off-by: Binbin <[email protected]>
@valkeyrie-ops valkeyrie-ops Bot moved this from To be backported to Done in Valkey 8.1 Jul 17, 2026
sarthakaggarwal97 pushed a commit that referenced this pull request Jul 17, 2026
…3548)

The default value of lua-enable-insecure-api cannot be safely changed
from no to yes due to two issues:

1. In createEngineContext(), lua_enable_insecure_api was hardcoded to 0
   before initializing Lua states, so deprecated APIs (newproxy, setfenv,
   getfenv) were never registered in the global table regardless of the
   actual config value. Once the global table is locked, the config
   change has no effect.

2. lua_insecure_api_current was initialized to 0 (struct zero-init) and
   never synced with the final config value. If the default was changed
   to yes(1), a subsequent CONFIG SET no would see both values as 0 and
   skip the evalReset() call in updateLuaEnableInsecureApi().

Fix by reading the real config via isLuaInsecureAPIEnabled() in
createEngineContext() before Lua state initialization, and syncing
lua_insecure_api_current after all config sources (default, config file,
command-line args) are applied.

8.0 backport note: only fix 2 (the lua_insecure_api_current sync in
server.c) applies to this branch. Bug 1 does not exist on 8.0: there is
no per-engine-context lua_enable_insecure_api field hardcoded to 0 --
the Lua engine has not been modularized here (Lua scripting lives in
src/script_lua.c / src/eval.c; there is no engine_lua.c). The deprecated-API allowlist gate reads
server.lua_enable_insecure_api directly (src/script_lua.c
luaNewIndexAllowList), and scriptingInit() runs in initServer() after
loadServerConfig(), so the config-file value is already honored at Lua
state initialization. The engine_lua.c hunk is therefore dropped.
Validated: the two new tests fail on 8.0 without the server.c sync and
pass with it.

Signed-off-by: Binbin <[email protected]>
@valkeyrie-ops valkeyrie-ops Bot moved this from To be backported to Done in Valkey 8.0 Jul 17, 2026
sarthakaggarwal97 pushed a commit that referenced this pull request Jul 17, 2026
…3548)

The default value of lua-enable-insecure-api cannot be safely changed
from no to yes due to two issues:

1. In createEngineContext(), lua_enable_insecure_api was hardcoded to 0
   before initializing Lua states, so deprecated APIs (newproxy, setfenv,
   getfenv) were never registered in the global table regardless of the
   actual config value. Once the global table is locked, the config
   change has no effect.

2. lua_insecure_api_current was initialized to 0 (struct zero-init) and
   never synced with the final config value. If the default was changed
   to yes(1), a subsequent CONFIG SET no would see both values as 0 and
   skip the evalReset() call in updateLuaEnableInsecureApi().

Fix by reading the real config via isLuaInsecureAPIEnabled() in
createEngineContext() before Lua state initialization, and syncing
lua_insecure_api_current after all config sources (default, config file,
command-line args) are applied.

7.2 backport note: only fix 2 (the lua_insecure_api_current sync in
server.c) applies to this branch. Bug 1 does not exist on 7.2: there is
no per-engine-context lua_enable_insecure_api field hardcoded to 0 --
the Lua engine has not been modularized here (Lua scripting lives in
src/script_lua.c / src/eval.c; there is no engine_lua.c). The deprecated-API allowlist gate reads
server.lua_enable_insecure_api directly (src/script_lua.c
luaNewIndexAllowList), and scriptingInit() runs in initServer() after
loadServerConfig(), so the config-file value is already honored at Lua
state initialization. The engine_lua.c hunk is therefore dropped.
Validated: the two new tests fail on 7.2 without the server.c sync and
pass with it.

Signed-off-by: Binbin <[email protected]>
@valkeyrie-ops valkeyrie-ops Bot moved this from To be backported to Done in Valkey 7.2 Jul 17, 2026
@sarthakaggarwal97 sarthakaggarwal97 moved this from To be backported to Done in Valkey 9.0 Jul 17, 2026
@TwizzyDizzy

TwizzyDizzy commented Aug 3, 2026 •

Copy link
Copy Markdown

Hi @enjoy-binbin I'm seeing this in my sentinel 9.1.1 logs. Just from a quick guess: Sentinel does not seem to have those CLI commands (CONFIG GET lua-enable-insecure-api). vcli and scli are just local wrappers for the CLI on our side.

root@dev-valkey01-CUSTOMER /var/log/valkey # vcli
127.0.0.1:6379> CONFIG GET lua-enable-insecure-api
1) "lua-enable-insecure-api"
2) "no"
root@dev-valkey01-CUSTOMER /var/log/valkey # scli
127.0.0.1:26379> CONFIG GET lua-enable-insecure-api
(error) ERR unknown command 'CONFIG', with args beginning with: 'GET' 'lua-enable-insecure-api'

Sentinel log - this happens on every start of Sentinel:

224492:X 03 Aug 2026 17:53:53.323 # <lua> Unable to determine 'lua-enable-insecure-api' configuration value: ERR unknown command 'CONFIG', with args beginning with: 'GET' 'lua-enable-insecure-api' 

224492:X 03 Aug 2026 17:53:53.324 # <lua> Unable to determine 'lua-enable-insecure-api' configuration value: ERR unknown command 'CONFIG', with args beginning with: 'GET' 'lua-enable-insecure-api' 

Should I open an issue for that?

Cheers
Thomas

@enjoy-binbin

enjoy-binbin commented Aug 4, 2026 •

Copy link
Copy Markdown
Member Author

@TwizzyDizzy Thanks for the report. TBH, i actually came across this log locally today as well (before seeing your report). Sentinel doesn't support CONFIG command, i am taking a look (you can also open an issue if you'd like).

Handled in #4327

@TwizzyDizzy

TwizzyDizzy commented Aug 4, 2026 •

Copy link
Copy Markdown

Nah, you got that PR going, that's fine with me. It's not that there are any functional issues that I'm aware of. Thank you for fixing it, though :)

Cheers
Thomas

zuiderkwast pushed a commit that referenced this pull request Aug 11, 2026
Previously we will load the Lua engine under the Sentinel mode.
Its OnLoad then probed `CONFIG GET lua-enable-insecure-api`, which
Sentinel rejects, producing a warning log (added in #3548):

```
<lua> Unable to determine 'lua-enable-insecure-api' configuration value:
ERR unknown command 'CONFIG', with args beginning with: 'GET' 'lua-enable-insecure-api'
```

Sentinel does not support SCRIPTING commands (EVAL/SCRIPT) nor the
MODULE commands, so the statically linked Lua engine is not needed
here. Skip moduleLoadStatic("lua") when server.sentinel_mode is set.

Signed-off-by: Binbin <[email protected]>
valkeyrie-ops Bot pushed a commit that referenced this pull request Aug 15, 2026
Previously we will load the Lua engine under the Sentinel mode.
Its OnLoad then probed `CONFIG GET lua-enable-insecure-api`, which
Sentinel rejects, producing a warning log (added in #3548):

```
<lua> Unable to determine 'lua-enable-insecure-api' configuration value:
ERR unknown command 'CONFIG', with args beginning with: 'GET' 'lua-enable-insecure-api'
```

Sentinel does not support SCRIPTING commands (EVAL/SCRIPT) nor the
MODULE commands, so the statically linked Lua engine is not needed
here. Skip moduleLoadStatic("lua") when server.sentinel_mode is set.

Signed-off-by: Binbin <[email protected]>
sarthakaggarwal97 pushed a commit that referenced this pull request Aug 30, 2026
Previously we will load the Lua engine under the Sentinel mode.
Its OnLoad then probed `CONFIG GET lua-enable-insecure-api`, which
Sentinel rejects, producing a warning log (added in #3548):

```
<lua> Unable to determine 'lua-enable-insecure-api' configuration value:
ERR unknown command 'CONFIG', with args beginning with: 'GET' 'lua-enable-insecure-api'
```

Sentinel does not support SCRIPTING commands (EVAL/SCRIPT) nor the
MODULE commands, so the statically linked Lua engine is not needed
here. Skip moduleLoadStatic("lua") when server.sentinel_mode is set.

Signed-off-by: Binbin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-notes This issue should get a line item in the release notes

Projects

Status: Done
Status: Done
Status: Done
Status: Done
Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants