Skip to content
代码片段 群组 项目
未验证 提交 f326916f 编辑于 作者: Stan Hu's avatar Stan Hu
浏览文件

Disable IAT verification by default

https://gitlab.com/gitlab-org/gitlab/-/merge_requests/117468 in GitLab
15.11 updated the ruby-jwt gem to v2.5.0. In v2.2.0, ruby-jwt removed
the `iat_leeway` parameter (https://github.com/jwt/ruby-jwt/pull/274).

As a result, if a gitlab-shell host creates a JWT token with an
issued-at (IAT) claim that is slightly behind the host handling API
the request, users will receive a 401 error.

Disable this IAT verification by default since it's not serving a
useful purpose, since expiration times are already validated. We
already made a similar change in Geo.

Relates to https://gitlab.com/gitlab-org/gitlab/-/issues/417543

Changelog: fixed
上级 df4abd18
No related branches found
No related tags found
无相关合并请求
......@@ -4,7 +4,7 @@
module JSONWebToken
class HMACToken < Token
IAT_LEEWAY = 60
LEEWAY = 60
JWT_ALGORITHM = 'HS256'
def initialize(secret)
......@@ -13,7 +13,7 @@ def initialize(secret)
@secret = secret
end
def self.decode(token, secret, leeway: IAT_LEEWAY, verify_iat: true)
def self.decode(token, secret, leeway: LEEWAY, verify_iat: false)
JWT.decode(token, secret, true, leeway: leeway, verify_iat: verify_iat, algorithm: JWT_ALGORITHM)
end
......
......@@ -25,7 +25,7 @@
end
describe '.decode' do
let(:leeway) { described_class::IAT_LEEWAY }
let(:leeway) { described_class::LEEWAY }
let(:decoded_token) { described_class.decode(encoded_token, secret, leeway: leeway) }
context 'with an invalid token' do
......
......@@ -50,6 +50,17 @@ def perform_request(headers: gitlab_shell_internal_api_request_header)
expect(response).to have_gitlab_http_status(:ok)
end
it 'authenticates using a jwt token with an IAT from 10 seconds in the future' do
headers =
travel_to(Time.now + 10.seconds) do
gitlab_shell_internal_api_request_header
end
perform_request(headers: headers)
expect(response).to have_gitlab_http_status(:ok)
end
it 'returns 401 when jwt token is expired' do
headers = gitlab_shell_internal_api_request_header
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册