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

feat: Remove nonce from jwt encode payload #17

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions lib/keypair.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,7 @@ def jwt_encode(payload, headers = {})

# Expiration time on or after which the tool MUST NOT accept the ID Token for
# processing (epoch). This is mostly used to allow some clock skew.
exp: Time.now.to_i + 5.minutes.to_i,

# String value used to associate a tool session with an ID Token, and to mitigate replay
# attacks. The nonce value is a case-sensitive string.
nonce: SecureRandom.uuid
exp: Time.now.to_i + 5.minutes.to_i
)

# Add additional info into the headers
Expand Down
10 changes: 2 additions & 8 deletions spec/models/keypair_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -312,18 +312,14 @@
expect(decoded).to include payload
end
it 'adds security payloads' do
expect(decoded.keys).to match_array %i[hex nested iat exp nonce]
expect(decoded.keys).to match_array %i[hex nested iat exp]
end
it 'sets iat to now', timecop: :freeze do
expect(decoded[:iat]).to eq Time.current.to_i
end
it 'sets exp to 5 minutes from now', timecop: :freeze do
expect(decoded[:exp]).to eq 5.minutes.from_now.to_i
end
it 'sets a generated nonce' do
allow(SecureRandom).to receive(:uuid).and_return 'my-nonce'
expect(decoded[:nonce]).to eq 'my-nonce'
end
it 'is encoded with the keypair and correct algorithm' do
expect do
JWT.decode(subject, keypair.public_key, true, algorithm: described_class::ALGORITHM)
Expand All @@ -340,12 +336,10 @@
let(:payload) { { foo: 'bar', exp: 1.minute.ago.to_i } }

it 'returns a JWT with the correct payload' do
allow(SecureRandom).to receive(:uuid).and_return 'my-nonce'
expect(decoded).to eq(
foo: 'bar',
iat: Time.current.to_i,
exp: 1.minute.ago.to_i,
nonce: 'my-nonce'
exp: 1.minute.ago.to_i
)
end
it 'is cannot be decoded' do
Expand Down
Loading