Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fail use jwt_parser:base64_decode to decode when upgrade kong 3.4.2 to 3.6.0 #12676

Closed
1 task done
lubw7 opened this issue Mar 1, 2024 · 6 comments
Closed
1 task done
Assignees
Labels
pending author feedback Waiting for the issue author to get back to a maintainer with findings, more details, etc... plugins/jwt

Comments

@lubw7
Copy link

lubw7 commented Mar 1, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Kong version ($ kong version)

kong 3.6

Current Behavior

In Kong 3.6.0
When I use kong.plugins.jwt.jwt_parser:base64_decode, it will meet exception : nil,invalid input.
2024/03/01 16:14:10 [debug] 1277#0: *1286 [lua] sso.lua:119: jwt_decoder:base64_decode(key) = nilinvalid input

Expected Behavior

In Kong 3.4.2
When I use kong.plugins.jwt.jwt_parser:base64_decode, it will decode successfully.

☺☺☺♣♥�☺0�☺H��:18:34 [debug] 1259#0: *150 [lua] sso.lua:119: jwt_decoder:base64_decode(key) = 0�☺"0
☻�☺☺�y¶@�K♠��%/{���▲(�Ԕ��/�♥[�73Ql9�I� H���♣��I‼1       �o��:��g�߹�ZU�'2�d`��J�H3�)
�▲ؿ
鷂rO��L������ ��g▲��P���Ô�#�����v!���6TL�z26^��xq��     �v4����M∟4:{♣���tξ(����↕�[܋�t����[e�r�d��g�e=♠y��T�hs▼�6I�yN7�����→}‼^����↔¶�ǽx��s1���4��f�E�→,F��.��►e1���n���r_☻♥☺☺

Steps To Reproduce

  1. Require jwt_parser
local jwt_decoder = require "kong.plugins.jwt.jwt_parser"
local DEBUG, ERR, INFO, log = ngx.DEBUG, ngx.ERR, ngx.INFO, ngx.log
  1. use jwt_parser:base64_decode
local test_key = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsbxk6rmBw/+8b2qwQnxKcK8VRRJcSQGCHjwzCzYmMa+XuRL0iaDmOIpXvXmqSMDGM/CdjoQhGfyotnnw3fROjBnOpnNeiX6UPYsJSLzozx1pv7gvRkyfv6hpp9pMn6UWt4IkFsHpeM/V1Spxvgbr+S9clXn+0saM529fK9BFPxjyHk2Jv+SHy9fnjre/5sFVyGxeAM36RVcw3u/D7v7gKigCjhR1Qc3FMJKDrZE5AQQOJELYMrWvaBUxVYjRwQpuEGt/OHbvJZEpABhIYd2lbby1BNtq96loup/SBxJ3jam0MUsf8aB87+vB4QiaX5gwTTLRw2IcnEal+DuZgnNaQQIDAQAB"
log(DEBUG, "jwt_decoder:base64_decode(key) = ", jwt_decoder:base64_decode(test_key))
  1. check the log, you can see:
    2024/03/01 16:14:10 [debug] 1277#0: *1286 [lua] sso.lua:119: jwt_decoder:base64_decode(key) = nilinvalid input

Anything else?

#11569 refactor the code about jwt_parser:base64_decode, so is it expected that such an error will occur?

@chobits
Copy link
Contributor

chobits commented Mar 4, 2024

Not sure whether if #11569 affectted it, we need to check

@chronolaw
Copy link
Contributor

We have created a ticket to track this issue (KAG-3952), thanks for your report.

@chronolaw
Copy link
Contributor

jwt token should be encoded with Base64URL algorithm, which means that we should replace '+' to '-' and '/' to '-'.

The variable test_key includes invalid char /, so kong think it is a wrong base64url string.

@chronolaw
Copy link
Contributor

You can change the code like this:

local input = "..."
input = input:gsub("+", "-"):gsub("/", "_")
print(jwt_decoder:base64_decode(input))

@chronolaw chronolaw self-assigned this Mar 5, 2024
@chronolaw chronolaw added the pending author feedback Waiting for the issue author to get back to a maintainer with findings, more details, etc... label Mar 5, 2024
@lubw7
Copy link
Author

lubw7 commented Mar 11, 2024

Thanks, the problem has already been solved.

You can change the code like this:

local input = "..."
input = input:gsub("+", "-"):gsub("/", "_")
print(jwt_decoder:base64_decode(input))

ebarped pushed a commit to OptareSolutions/kong-plugin-jwt-keycloak that referenced this issue Mar 18, 2024
ebarped pushed a commit to OptareSolutions/kong-plugin-jwt-keycloak that referenced this issue Mar 18, 2024
@lubw7
Copy link
Author

lubw7 commented May 13, 2024

@chronolaw Will this change be added to the source code?

You can change the code like this:

local input = "..."
input = input:gsub("+", "-"):gsub("/", "_")
print(jwt_decoder:base64_decode(input))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending author feedback Waiting for the issue author to get back to a maintainer with findings, more details, etc... plugins/jwt
Projects
None yet
Development

No branches or pull requests

3 participants