Skip to content

Commit a223367

Browse files
authored
chore(jwt-auth): adjust error log level to warn (#6860)
1 parent 76b44cc commit a223367

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ title: Changelog
6161

6262
- fix: jwt-auth error may leak secret [#6846](https://github.com/apache/apisix/pull/6846)
6363
- chore: upgrade lua-resty-jwt to a new version [#6847](https://github.com/apache/apisix/pull/6847)
64+
- chore(jwt-auth): adjust error log level to warn [#6858](https://github.com/apache/apisix/pull/6858)
6465

6566
## 2.13.0
6667

apisix/plugins/jwt-auth.lua

+3-3
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ function _M.rewrite(conf, ctx)
361361
local jwt_obj = jwt:load_jwt(jwt_token)
362362
core.log.info("jwt object: ", core.json.delay_encode(jwt_obj))
363363
if not jwt_obj.valid then
364-
core.log.error("JWT token invalid: ", jwt_obj.reason)
364+
core.log.warn("JWT token invalid: ", jwt_obj.reason)
365365
return 401, {message = "JWT token invalid"}
366366
end
367367

@@ -393,8 +393,8 @@ function _M.rewrite(conf, ctx)
393393
core.log.info("jwt object: ", core.json.delay_encode(jwt_obj))
394394

395395
if not jwt_obj.verified then
396-
core.log.error("JWT token verify failed: ", jwt_obj.reason)
397-
return 401, {message = "JWT token verify failed"}
396+
core.log.warn("failed to verify jwt: ", jwt_obj.reason)
397+
return 401, {message = "failed to verify jwt"}
398398
end
399399

400400
consumer_mod.attach_consumer(ctx, consumer, consumer_conf)

docs/zh/latest/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ title: CHANGELOG
6161

6262
- 修复 jwt-auth 返回结果里可能暴露 secret 的问题 [#6846](https://github.com/apache/apisix/pull/6846)
6363
- 升级 lua-resty-jwt 到一个新版本 [#6847](https://github.com/apache/apisix/pull/6847)
64+
- 修改 jwt-auth 在响应码为503时 仍使用 error 错误等级 [#6858](https://github.com/apache/apisix/pull/6858)
6465

6566
## 2.13.0
6667

t/plugin/jwt-auth.t

+14-4
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ GET /hello?jwt=invalid-eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJ1c2VyLWtl
217217
{"message":"JWT token invalid"}
218218
--- error_log
219219
JWT token invalid: invalid header: invalid-eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9
220+
--- no_error_log
221+
[error]
220222
221223
222224
@@ -225,9 +227,11 @@ JWT token invalid: invalid header: invalid-eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9
225227
GET /hello?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJ1c2VyLWtleSIsImV4cCI6MTU2Mzg3MDUwMX0.pPNVvh-TQsdDzorRwa-uuiLYiEBODscp9wv0cwD6c68
226228
--- error_code: 401
227229
--- response_body
228-
{"message":"JWT token verify failed"}
230+
{"message":"failed to verify jwt"}
229231
--- error_log
230-
JWT token verify failed: 'exp' claim expired at Tue, 23 Jul 2019 08:28:21 GMT
232+
failed to verify jwt: 'exp' claim expired at Tue, 23 Jul 2019 08:28:21 GMT
233+
--- no_error_log
234+
[error]
231235
232236
233237
@@ -281,6 +285,8 @@ Authorization: bearer invalid-eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJ1c
281285
{"message":"JWT token invalid"}
282286
--- error_log
283287
JWT token invalid: invalid header: invalid-eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9
288+
--- no_error_log
289+
[error]
284290
285291
286292
@@ -434,6 +440,8 @@ GET /hello?jwt=invalid-eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJ1c2VyLWtl
434440
{"message":"JWT token invalid"}
435441
--- error_log
436442
JWT token invalid: invalid header: invalid-eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9
443+
--- no_error_log
444+
[error]
437445
438446
439447
@@ -444,9 +452,11 @@ GET /hello
444452
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJ1c2VyLWtleSIsImV4cCI6MTg3OTMxODU0MX0.fNtFJnNmJgzbiYmGB0Yjvm-l6A6M4jRV1l4mnVFSYjs
445453
--- error_code: 401
446454
--- response_body
447-
{"message":"JWT token verify failed"}
455+
{"message":"failed to verify jwt"}
448456
--- error_log
449-
JWT token verify failed: signature mismatch: fNtFJnNmJgzbiYmGB0Yjvm-l6A6M4jRV1l4mnVFSYjs
457+
failed to verify jwt: signature mismatch: fNtFJnNmJgzbiYmGB0Yjvm-l6A6M4jRV1l4mnVFSYjs
458+
--- no_error_log
459+
[error]
450460
451461
452462

0 commit comments

Comments
 (0)