Dev.to Security πŸ” Cybersecurity πŸ‘ 0 πŸ“– 2 min read

A Lua Pattern Iterator Must Not Outlive the Socket

A Lua Pattern Iterator Must Not Outlive the Socket A Lua cosocket makes network code look local. OpenResty CVE-2026-136412 shows that object lifetime still follows the socket and the garbage collector. The vu

A Lua Pattern Iterator Must Not Outlive the Socket

A Lua cosocket makes network code look local. OpenResty CVE-2026-136412 shows that object lifetime still follows the socket and the garbage collector.

The vulnerability

CVE-2026-136412 affects OpenResty stream-lua-nginx-module before 0.0.20rc4. A receiveuntil() pattern iterator can be garbage-collected while the socket still references it. If a remote peer interrupts or closes the cosocket connection, a later read or socket close can use the stale pattern pointer. The public record describes nginx worker crash or memory corruption and lists CVSS 4.0 score 9.2.

The lifetime boundary

The pattern iterator is not just a helper value. It is state attached to an asynchronous receive operation. The socket must retain that state until completion, cancellation, and cleanup all finish. A garbage collector that frees the Lua object while C code keeps a raw reference creates two owners for the same memory lifetime. Remote peers can influence cancellation and connection teardown, so the bug is reachable through ordinary network behavior.

Inventory

Find OpenResty builds and custom nginx images that include stream-lua-nginx-module. Resolve the module version from the build manifest or binary package, not only the OpenResty product version. Identify stream-mode routes that call receiveuntil() and record which upstream clients can interrupt them. OpenResty 1.31.9.1 upgrades the module to the fixed v0.0.20rc4, but source builds may pin the old module independently.

Remediation

Upgrade OpenResty to 1.31.9.1 or later, or rebuild with stream-lua-nginx-module v0.0.20rc4 or later. Restart workers only through the deployment's normal rolling process after verifying the loaded module. Until patching, reduce exposure of affected stream endpoints and monitor for worker crashes or abnormal restarts. Do not treat a worker restart as proof of exploitation or as proof that the bug is absent.

Verification

Inspect package and build metadata for the exact module revision. Exercise connection interruption in a staging test and compare worker stability before and after the update. Review nginx error logs, core dumps, and service restarts for repeatable patterns tied to the affected route. Because the issue can corrupt memory, a crash-free test run is supporting evidence rather than a complete assurance.

References

πŸ“° Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.