You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by "SkyeYoung (via GitHub)" <gi...@apache.org> on 2025/09/12 00:45:33 UTC
[PR] feat(jwt-auth): when algorithm is not `RS256` or `ES256`, require the user to fill in secret [apisix]
SkyeYoung opened a new pull request, #12611:
URL: https://github.com/apache/apisix/pull/12611
### 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] feat(jwt-auth): when algorithm is not `RS256` or `ES256`, require the user to fill in `secret` [apisix]
Posted by "SkyeYoung (via GitHub)" <gi...@apache.org>.
SkyeYoung commented on code in PR #12611:
URL: https://github.com/apache/apisix/pull/12611#discussion_r2342861298
##########
apisix/plugins/jwt-auth.lua:
##########
@@ -145,7 +143,8 @@ function _M.check_schema(conf, schema_type)
end
if conf.algorithm ~= "RS256" and conf.algorithm ~= "ES256" and not conf.secret then
- conf.secret = ngx_encode_base64(resty_random.bytes(32, true))
+ err = "property \"secret\" is required when \"algorithm\" is not \"RS256\" or \"ES256\""
Review Comment:
<img width="2714" height="2202" alt="CleanShot 2025-09-12 at 11 37 13@2x" src="https://github.com/user-attachments/assets/eed57961-0907-4589-b781-096e6cbd5853" />
https://github.com/apache/apisix/pull/12611/files#diff-9b9604832706062cf84d2e9b7a13754c0f21a9a0b34cf271a4eb059f4bffbdaa TEST 52
After trying to modify it, I found that it would incorrectly pass the test when going through the default `HS256` logic.
The original code should have also been implemented through code for this reason.
--
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] change(jwt-auth): when algorithm is not `RS256` or `ES256`, require the user to fill in `secret` [apisix]
Posted by "SkyeYoung (via GitHub)" <gi...@apache.org>.
SkyeYoung merged PR #12611:
URL: https://github.com/apache/apisix/pull/12611
--
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] feat(jwt-auth): when algorithm is not `RS256` or `ES256`, require the user to fill in `secret` [apisix]
Posted by "SkyeYoung (via GitHub)" <gi...@apache.org>.
SkyeYoung commented on code in PR #12611:
URL: https://github.com/apache/apisix/pull/12611#discussion_r2343252988
##########
apisix/plugins/jwt-auth.lua:
##########
@@ -144,8 +142,9 @@ function _M.check_schema(conf, schema_type)
return false, err
end
- if conf.algorithm ~= "RS256" and conf.algorithm ~= "ES256" and not conf.secret then
- conf.secret = ngx_encode_base64(resty_random.bytes(32, true))
+ if (conf.algorithm == "HS256" or conf.algorithm == "HS512") and not conf.secret then
+ err = "property \"secret\" is required when \"algorithm\" is \"HS256\" or \"HS512\""
Review Comment:
done
##########
t/plugin/jwt-auth.t:
##########
@@ -1222,3 +1222,71 @@ hello world
--- error_code: 400
--- response_body
{"error_msg":"invalid plugins configuration: failed to check the configuration of plugin jwt-auth err: failed to validate dependent schema for \"algorithm\": value should match only one schema, but matches none"}
+
+
+
+=== TEST 52: secret is required when algorithm is not RS256 or ES256
+--- config
+ location /t {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ local plugin = require("apisix.plugins.jwt-auth")
+ -- default algorithm is HS256
+ local ok, err = plugin.check_schema({
+ key = "123",
+ }, core.schema.TYPE_CONSUMER)
+ if not ok then
+ ngx.say(err)
+ else
+ ngx.say("done")
+ end
Review Comment:
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
Re: [PR] feat(jwt-auth): when algorithm is not `RS256` or `ES256`, require the user to fill in `secret` [apisix]
Posted by "bzp2010 (via GitHub)" <gi...@apache.org>.
bzp2010 commented on PR #12611:
URL: https://github.com/apache/apisix/pull/12611#issuecomment-3284642950
If the `change` prefix is not used, special attention must be paid to these changes during release and they must be marked as non-backward-compatible modifications.
This may cause trouble in the next release process.
--
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] feat(jwt-auth): when algorithm is not `RS256` or `ES256`, require the user to fill in `secret` [apisix]
Posted by "SkyeYoung (via GitHub)" <gi...@apache.org>.
SkyeYoung commented on code in PR #12611:
URL: https://github.com/apache/apisix/pull/12611#discussion_r2342861298
##########
apisix/plugins/jwt-auth.lua:
##########
@@ -145,7 +143,8 @@ function _M.check_schema(conf, schema_type)
end
if conf.algorithm ~= "RS256" and conf.algorithm ~= "ES256" and not conf.secret then
- conf.secret = ngx_encode_base64(resty_random.bytes(32, true))
+ err = "property \"secret\" is required when \"algorithm\" is not \"RS256\" or \"ES256\""
Review Comment:
<img width="2714" height="2202" alt="CleanShot 2025-09-12 at 11 37 13@2x" src="https://github.com/user-attachments/assets/eed57961-0907-4589-b781-096e6cbd5853" />
https://github.com/apache/apisix/pull/12611/files#diff-9b9604832706062cf84d2e9b7a13754c0f21a9a0b34cf271a4eb059f4bffbdaa TEST 52
After trying to modify it, I found that it would incorrectly pass the test when going through the default logic.
The original code should have also been implemented through code for this reason.
--
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] feat(jwt-auth): when algorithm is not `RS256` or `ES256`, require the user to fill in `secret` [apisix]
Posted by "nic-6443 (via GitHub)" <gi...@apache.org>.
nic-6443 commented on code in PR #12611:
URL: https://github.com/apache/apisix/pull/12611#discussion_r2342843574
##########
apisix/plugins/jwt-auth.lua:
##########
@@ -145,7 +143,8 @@ function _M.check_schema(conf, schema_type)
end
if conf.algorithm ~= "RS256" and conf.algorithm ~= "ES256" and not conf.secret then
- conf.secret = ngx_encode_base64(resty_random.bytes(32, true))
+ err = "property \"secret\" is required when \"algorithm\" is not \"RS256\" or \"ES256\""
Review Comment:
for this plugin, we already use json schema to define relationship between `algorithm` and `public_key` field, I think better use same way for `secret` too:
https://github.com/apache/apisix/blob/69564959d99e42ec2095eab2c35b3c73bc31b259/apisix/plugins/jwt-auth.lua#L95-L117
--
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] feat(jwt-auth): when algorithm is not `RS256` or `ES256`, require the user to fill in `secret` [apisix]
Posted by "SkyeYoung (via GitHub)" <gi...@apache.org>.
SkyeYoung commented on code in PR #12611:
URL: https://github.com/apache/apisix/pull/12611#discussion_r2342866858
##########
apisix/plugins/jwt-auth.lua:
##########
@@ -144,8 +142,9 @@ function _M.check_schema(conf, schema_type)
return false, err
end
- if conf.algorithm ~= "RS256" and conf.algorithm ~= "ES256" and not conf.secret then
- conf.secret = ngx_encode_base64(resty_random.bytes(32, true))
+ if (conf.algorithm == "HS256" or conf.algorithm == "HS512") and not conf.secret then
Review Comment:
Adjust to be consistent with the document
https://github.com/apache/apisix/pull/12611/files#diff-3cd5fc846614f1e59961d065c6f32dca0b2d6cc3ef549e7a961dd4b3694a74bc
<img width="2242" height="324" alt="Image" src="https://github.com/user-attachments/assets/296643cf-1143-4fcd-ac57-8d343a52bbb7" />
--
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] feat(jwt-auth): when algorithm is not `RS256` or `ES256`, require the user to fill in `secret` [apisix]
Posted by "SkyeYoung (via GitHub)" <gi...@apache.org>.
SkyeYoung commented on code in PR #12611:
URL: https://github.com/apache/apisix/pull/12611#discussion_r2342844480
##########
apisix/plugins/jwt-auth.lua:
##########
@@ -145,7 +143,8 @@ function _M.check_schema(conf, schema_type)
end
if conf.algorithm ~= "RS256" and conf.algorithm ~= "ES256" and not conf.secret then
- conf.secret = ngx_encode_base64(resty_random.bytes(32, true))
+ err = "property \"secret\" is required when \"algorithm\" is not \"RS256\" or \"ES256\""
Review Comment:
Let me check it
--
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] feat(jwt-auth): when algorithm is not `RS256` or `ES256`, require the user to fill in `secret` [apisix]
Posted by "nic-6443 (via GitHub)" <gi...@apache.org>.
nic-6443 commented on code in PR #12611:
URL: https://github.com/apache/apisix/pull/12611#discussion_r2342843574
##########
apisix/plugins/jwt-auth.lua:
##########
@@ -145,7 +143,8 @@ function _M.check_schema(conf, schema_type)
end
if conf.algorithm ~= "RS256" and conf.algorithm ~= "ES256" and not conf.secret then
- conf.secret = ngx_encode_base64(resty_random.bytes(32, true))
+ err = "property \"secret\" is required when \"algorithm\" is not \"RS256\" or \"ES256\""
Review Comment:
for this plugin, we already use json schema to define relationship between `algorithm` and `public_key` field, I think better to use same way for `secret` too:
https://github.com/apache/apisix/blob/69564959d99e42ec2095eab2c35b3c73bc31b259/apisix/plugins/jwt-auth.lua#L95-L117
--
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] feat(jwt-auth): when algorithm is not `RS256` or `ES256`, require the user to fill in `secret` [apisix]
Posted by "SkyeYoung (via GitHub)" <gi...@apache.org>.
SkyeYoung commented on code in PR #12611:
URL: https://github.com/apache/apisix/pull/12611#discussion_r2342861298
##########
apisix/plugins/jwt-auth.lua:
##########
@@ -145,7 +143,8 @@ function _M.check_schema(conf, schema_type)
end
if conf.algorithm ~= "RS256" and conf.algorithm ~= "ES256" and not conf.secret then
- conf.secret = ngx_encode_base64(resty_random.bytes(32, true))
+ err = "property \"secret\" is required when \"algorithm\" is not \"RS256\" or \"ES256\""
Review Comment:
<img width="2714" height="2202" alt="CleanShot 2025-09-12 at 11 37 13@2x" src="https://github.com/user-attachments/assets/eed57961-0907-4589-b781-096e6cbd5853" />
https://github.com/apache/apisix/pull/12611/files#diff-9b9604832706062cf84d2e9b7a13754c0f21a9a0b34cf271a4eb059f4bffbdaa TEST 52
After trying to modify it, I found that it would incorrectly pass the test when going through the default value logic.
The original code should have also been implemented through code for this reason.
--
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] feat(jwt-auth): when algorithm is not `RS256` or `ES256`, require the user to fill in `secret` [apisix]
Posted by "bzp2010 (via GitHub)" <gi...@apache.org>.
bzp2010 commented on code in PR #12611:
URL: https://github.com/apache/apisix/pull/12611#discussion_r2343058255
##########
t/plugin/jwt-auth.t:
##########
@@ -1222,3 +1222,71 @@ hello world
--- error_code: 400
--- response_body
{"error_msg":"invalid plugins configuration: failed to check the configuration of plugin jwt-auth err: failed to validate dependent schema for \"algorithm\": value should match only one schema, but matches none"}
+
+
+
+=== TEST 52: secret is required when algorithm is not RS256 or ES256
+--- config
+ location /t {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ local plugin = require("apisix.plugins.jwt-auth")
+ -- default algorithm is HS256
+ local ok, err = plugin.check_schema({
+ key = "123",
+ }, core.schema.TYPE_CONSUMER)
+ if not ok then
+ ngx.say(err)
+ else
+ ngx.say("done")
+ end
Review Comment:
Just a suggestion: using assert is enough.
```
assert(ok, "HS256 but secret is not required")
```
##########
apisix/plugins/jwt-auth.lua:
##########
@@ -144,8 +142,9 @@ function _M.check_schema(conf, schema_type)
return false, err
end
- if conf.algorithm ~= "RS256" and conf.algorithm ~= "ES256" and not conf.secret then
- conf.secret = ngx_encode_base64(resty_random.bytes(32, true))
+ if (conf.algorithm == "HS256" or conf.algorithm == "HS512") and not conf.secret then
+ err = "property \"secret\" is required when \"algorithm\" is \"HS256\" or \"HS512\""
Review Comment:
There seems to be no point in using a variable to store it; returning the string directly should suffice.
--
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] feat(jwt-auth): when algorithm is not `RS256` or `ES256`, require the user to fill in `secret` [apisix]
Posted by "SkyeYoung (via GitHub)" <gi...@apache.org>.
SkyeYoung commented on PR #12611:
URL: https://github.com/apache/apisix/pull/12611#issuecomment-3284185391
> change
@bzp2010 This is not very common. I usually refer to https://github.com/TrigenSoftware/simple-release/blob/main/GUIDE.md
Since this feature did not exist before, it should be `feat` 🤔
--
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