Repository navigation
fix: guard against nil matched_ssl in verify_https_client - #14057
bhuvan-somisetty wants to merge 3 commits into
Conversation
In verify_https_client, ngx.ctx.matched_ssl is accessed without checking whether matched_ssl or matched_ssl.value is nil. When an HTTPS request arrives without a matching custom SSL configuration in APISIX (such as falling back to default certificates or unconfigured SNI), ngx.ctx.matched_ssl is nil, triggering a fatal runtime error: "attempt to index local 'matched_ssl' (a nil value)". Add nil checks for matched_ssl and matched_ssl.value before accessing matched_ssl.value.client. Signed-off-by: bhuvan-somisetty <somisettybhuvan5@gmail.com>
|
Thanks for the fix and for adding a test. There are two CI issues to address first: the new test assigns to the read-only With an artificially constructed nil I tested base/head with OpenResty 1.25.3.1 and etcd 3.5.11, using both an unpatched TLS implementation and a build with the corresponding APISIX patches. Unknown SNI, direct-IP requests without SNI, and requests with no SSL objects were rejected during ClientHello. Valid requests and ordinary TLS session resumptions retained Could you share the complete relevant configuration, |
Fix test case TEST 29 in t/node/client-mtls.t to populate scheme in api_ctx.var cache instead of writing to read-only ngx.var.scheme, and run reindex to adhere to test code style requirements. Signed-off-by: bhuvan-somisetty <somisettybhuvan5@gmail.com>
|
Thanks for the review and catching those! I've updated the test to mock Regarding the live TLS handshake path: as you noted, OpenResty/Nginx will reject unknown SNIs during ClientHello before reaching access phase when strict TLS termination is in effect. The nil dereference occurs in custom or embedded deployments where SSL termination or handshake bypass allows the access phase to run over HTTPS without an APISIX SSL entity populating |
|
The HTTPS mock here appears to be lost before verification: Lines 883 to 885 in 5460871
Lines 850 to 855 in 5460871 Our Nginx probe confirmed that the verifier receives Could you mock the scheme on the context created inside |
1 similar comment
|
The HTTPS mock here appears to be lost before verification: Lines 883 to 885 in 5460871
Lines 850 to 855 in 5460871 Our Nginx probe confirmed that the verifier receives Could you mock the scheme on the context created inside |
Export verify_https_client on apisix module to allow direct testing with a synthetic HTTPS context, ensuring the test exercises the nil matched_ssl guard directly without being shadowed by http_access_phase initialization. Signed-off-by: bhuvan-somisetty <somisettybhuvan5@gmail.com>
|
Good catch! I've exported |
Description
In
verify_https_client(ctx)(apisix/init.lua),local matched_ssl = ngx.ctx.matched_sslis read and immediately indexed viamatched_ssl.value.clientwithout checking whethermatched_sslormatched_ssl.valueis nil.When an HTTPS request arrives without a matching custom SSL configuration in APISIX (for example, falling back to default certificates configured via Nginx directives or when connecting to an unknown SNI / IP),
ngx.ctx.matched_sslisnil. This causes a runtime crash:and aborts request handling with HTTP 500.
This patch adds nil guards for
matched_sslandmatched_ssl.valuebefore accessingmatched_ssl.value.client.Which issue(s) this PR fixes:
Fixes #14056
Checklist