You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by "nic-6443 (via GitHub)" <gi...@apache.org> on 2025/06/23 07:13:14 UTC

[PR] fix: added restriction for TLSv1.3 cross-SNI session resumption [apisix]

nic-6443 opened a new pull request, #12366:
URL: https://github.com/apache/apisix/pull/12366

   ### Description
   
   <!-- Please include a summary of the change and which issue is fixed. -->
   <!-- Please also include relevant motivation and context. -->
   
   #### Which issue(s) this PR fixes:
   <!--
   *Automatically closes linked issue when PR is merged.
   Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
   -->
   Fixes #
   
   ### Checklist
   
   - [ ] I have explained the need for this PR and the problem it solves
   - [ ] I have explained the changes or the new features added to this PR
   - [ ] I have added tests corresponding to this change
   - [ ] I have updated the documentation to reflect this change
   - [ ] I have verified that this change is backward compatible (If not, please discuss on the [APISIX mailing list](https://github.com/apache/apisix/tree/master#community) first)
   
   <!--
   
   Note
   
   1. Mark the PR as draft until it's ready to be reviewed.
   2. Always add/update tests for any changes unless you have a good reason.
   3. Always update the documentation to reflect the changes made in the PR.
   4. Make a new commit to resolve conversations instead of `push -f`.
   5. To resolve merge conflicts, merge master instead of rebasing.
   6. Use "request review" to notify the reviewer after making changes.
   7. Only a reviewer can mark a conversation as resolved.
   
   -->
   


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix: added restriction for TLSv1.3 cross-SNI session resumption [apisix]

Posted by "nic-6443 (via GitHub)" <gi...@apache.org>.
nic-6443 commented on code in PR #12366:
URL: https://github.com/apache/apisix/pull/12366#discussion_r2162905018


##########
apisix/init.lua:
##########
@@ -391,6 +400,17 @@ local function verify_https_client(ctx)
                            ", but the host is ", host)
             return false
         end
+
+        local session_hostname, err = apisix_ssl.session_hostname()
+        if err then
+            core.log.error("failed to get session hostname: ", err)
+            return false
+        end
+        if session_hostname and session_hostname ~= ngx.ctx.client_hello_sni then
+            core.log.error("sni in client hello mismatch hostname of ssl session, ",
+                             "sni: ", ngx.ctx.client_hello_sni, ", hostname: ", session_hostname)
+            return false
+        end

Review Comment:
   The HTTP subsystem also has matching verification for the HTTP host and SNI, so the verification logic of these two subsystems is not exactly the same and cannot be fully reused.



-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix: added restriction for TLSv1.3 cross-SNI session resumption [apisix]

Posted by "bzp2010 (via GitHub)" <gi...@apache.org>.
bzp2010 commented on code in PR #12366:
URL: https://github.com/apache/apisix/pull/12366#discussion_r2163099440


##########
apisix/init.lua:
##########
@@ -1022,25 +1046,6 @@ function _M.http_control()
 end
 
 
-function _M.stream_ssl_phase()
-    local ngx_ctx = ngx.ctx
-    local api_ctx = core.tablepool.fetch("api_ctx", 0, 32)
-    ngx_ctx.api_ctx = api_ctx
-
-    local ok, err = router.router_ssl.match_and_set(api_ctx)
-
-    core.tablepool.release("api_ctx", api_ctx)
-    ngx_ctx.api_ctx = nil
-
-    if not ok then
-        if err then
-            core.log.error("failed to fetch ssl config: ", err)
-        end
-        ngx_exit(-1)
-    end
-end

Review Comment:
   The stream ssl phase is merged into a code snippet that is consistent with http. Is this as expected?



-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix: added restriction for TLSv1.3 cross-SNI session resumption [apisix]

Posted by "bzp2010 (via GitHub)" <gi...@apache.org>.
bzp2010 commented on code in PR #12366:
URL: https://github.com/apache/apisix/pull/12366#discussion_r2162851981


##########
apisix/init.lua:
##########
@@ -391,6 +400,17 @@ local function verify_https_client(ctx)
                            ", but the host is ", host)
             return false
         end
+
+        local session_hostname, err = apisix_ssl.session_hostname()
+        if err then
+            core.log.error("failed to get session hostname: ", err)
+            return false
+        end
+        if session_hostname and session_hostname ~= ngx.ctx.client_hello_sni then
+            core.log.error("sni in client hello mismatch hostname of ssl session, ",
+                             "sni: ", ngx.ctx.client_hello_sni, ", hostname: ", session_hostname)
+            return false
+        end

Review Comment:
   What is the difference between this and the other modification that looks the same above?



-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix: added restriction for TLSv1.3 cross-SNI session resumption [apisix]

Posted by "nic-6443 (via GitHub)" <gi...@apache.org>.
nic-6443 merged PR #12366:
URL: https://github.com/apache/apisix/pull/12366


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix: added restriction for TLSv1.3 cross-SNI session resumption [apisix]

Posted by "nic-6443 (via GitHub)" <gi...@apache.org>.
nic-6443 commented on code in PR #12366:
URL: https://github.com/apache/apisix/pull/12366#discussion_r2163111074


##########
apisix/init.lua:
##########
@@ -1022,25 +1046,6 @@ function _M.http_control()
 end
 
 
-function _M.stream_ssl_phase()
-    local ngx_ctx = ngx.ctx
-    local api_ctx = core.tablepool.fetch("api_ctx", 0, 32)
-    ngx_ctx.api_ctx = api_ctx
-
-    local ok, err = router.router_ssl.match_and_set(api_ctx)
-
-    core.tablepool.release("api_ctx", api_ctx)
-    ngx_ctx.api_ctx = nil
-
-    if not ok then
-        if err then
-            core.log.error("failed to fetch ssl config: ", err)
-        end
-        ngx_exit(-1)
-    end
-end

Review Comment:
   Yes, previously the stream subsystem did not use the `client_hello_by_lua` phase. But in this fix, it is necessary to use this phase. 
   After comparing the code of the http and stream subsystems, I confirmed that the code for both `client_hello_by_lua` and `certificate_by_lua` phases can be reused in these two subsystems, making it unnecessary to maintain a separate `stream_ssl_phase`.



-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix: added restriction for TLSv1.3 cross-SNI session resumption [apisix]

Posted by "nic-6443 (via GitHub)" <gi...@apache.org>.
nic-6443 commented on code in PR #12366:
URL: https://github.com/apache/apisix/pull/12366#discussion_r2162904116


##########
apisix/init.lua:
##########
@@ -391,6 +400,17 @@ local function verify_https_client(ctx)
                            ", but the host is ", host)
             return false
         end
+
+        local session_hostname, err = apisix_ssl.session_hostname()
+        if err then
+            core.log.error("failed to get session hostname: ", err)
+            return false
+        end
+        if session_hostname and session_hostname ~= ngx.ctx.client_hello_sni then
+            core.log.error("sni in client hello mismatch hostname of ssl session, ",
+                             "sni: ", ngx.ctx.client_hello_sni, ", hostname: ", session_hostname)
+            return false
+        end

Review Comment:
   The above is the http subsystem, and this is the stream subsystem.



-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix: added restriction for TLSv1.3 cross-SNI session resumption [apisix]

Posted by "bzp2010 (via GitHub)" <gi...@apache.org>.
bzp2010 commented on code in PR #12366:
URL: https://github.com/apache/apisix/pull/12366#discussion_r2162854234


##########
apisix/init.lua:
##########
@@ -391,6 +400,17 @@ local function verify_https_client(ctx)
                            ", but the host is ", host)
             return false
         end
+
+        local session_hostname, err = apisix_ssl.session_hostname()
+        if err then
+            core.log.error("failed to get session hostname: ", err)
+            return false
+        end
+        if session_hostname and session_hostname ~= ngx.ctx.client_hello_sni then
+            core.log.error("sni in client hello mismatch hostname of ssl session, ",
+                             "sni: ", ngx.ctx.client_hello_sni, ", hostname: ", session_hostname)
+            return false
+        end

Review Comment:
   Maybe they could be moved to a new function with some comments explaining why this verification is done "to fix a security issue".



-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix: added restriction for TLSv1.3 cross-SNI session resumption [apisix]

Posted by "nic-6443 (via GitHub)" <gi...@apache.org>.
nic-6443 commented on code in PR #12366:
URL: https://github.com/apache/apisix/pull/12366#discussion_r2162918558


##########
apisix/init.lua:
##########
@@ -391,6 +400,17 @@ local function verify_https_client(ctx)
                            ", but the host is ", host)
             return false
         end
+
+        local session_hostname, err = apisix_ssl.session_hostname()
+        if err then
+            core.log.error("failed to get session hostname: ", err)
+            return false
+        end
+        if session_hostname and session_hostname ~= ngx.ctx.client_hello_sni then
+            core.log.error("sni in client hello mismatch hostname of ssl session, ",
+                             "sni: ", ngx.ctx.client_hello_sni, ", hostname: ", session_hostname)
+            return false
+        end

Review Comment:
   > Maybe they could be moved to a new function with some comments explaining why this verification is done "to fix a security issue".
   
   done



-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org