nic-6443 commented on issue #13055: URL: https://github.com/apache/apisix/issues/13055#issuecomment-4676895121
I dug into this and reproduced it on openresty 1.29.2.4 — the bug is real but it lives in lua-nginx-module, not APISIX. In init_by_lua, lua-resty-core replaces `os.getenv` (resty/core/misc.lua) with a shim backed by the C function `ngx_http_lua_ffi_get_conf_env`, and that function matches env entries with `ngx_strncmp(name, var[i].data, var[i].len)` without checking the queried name ends there — so the first declared entry whose name is a prefix of the query wins, which is exactly the order sensitivity you saw. It only affects init_by_lua because nginx applies `env` directives to the real environ later (worker init), after which the shim removes itself. That also means #13147 can't fix it: during init_by_lua the `ffi.C.environ` snapshot doesn't contain `env NAME=VALUE` directive vars at all, so the new lookup misses and falls back to the same buggy shim — I verified this by simulating the override. I think the right fix is a one-line exact-length check in `ngx_http_lua_ffi_get_conf_env` upstream, plus a runtime patch on the APISIX side until that's released. Happy to file the upstream issue/PR if this direction makes sense. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
