[Bug 43077] New: Add encode_claims/decode_claims to Koha::Token
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43077 Bug ID: 43077 Summary: Add encode_claims/decode_claims to Koha::Token Initiative type: --- Sponsorship --- status: Product: Koha Version: Main Hardware: All OS: All Status: NEW Severity: enhancement Priority: P5 - low Component: Architecture, internals, and plumbing Assignee: koha-bugs@lists.koha-community.org Reporter: tomascohen@gmail.com QA Contact: testopia@bugs.koha-community.org Blocks: 42383 Target Milestone: --- Koha::Token currently only supports JWTs with a single 'id' claim (generate_jwt/check_jwt/decode_jwt). This adds general-purpose encode_claims/decode_claims methods that support arbitrary claim hashes, and refactors the existing id-based methods as thin wrappers on top. This will be used by the upcoming Koha::Module::Policy classes (Bug 42383) which serialize per-module capability hashes as JWTs in API response headers. Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42383 [Bug 42383] Migrate check-in page to Vue -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43077 --- Comment #1 from Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> --- Created attachment 201951 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=201951&action=edit Bug 43077: Add encode_claims/decode_claims to Koha::Token This patch adds two methods to Koha::Token for encoding and decoding arbitrary claims as signed JWTs: - encode_claims($hashref) - encodes any hashref as a signed JWT - decode_claims($token) - decodes a JWT and returns the full claims Unlike the existing generate_jwt/decode_jwt methods (which only support a single 'id' string value), these methods support full claim structures including nested hashes and arrays. Both use the standard Koha secret (database password) for signing, reusing the existing _add_default_jwt_params internal function. This will be used by the upcoming Koha::Module::Policy classes, which will serialize per-module capability hashes as JWTs in API response headers. Test plan: 1. Apply patch 2. Run: $ ktd --shell k$ prove t/Koha/Token.t => SUCCESS: Tests pass 3. Tests cover: - Simple hashref encoding/decoding (string, numeric, boolean) - Complex nested structures (hashes, arrays) - JWT format validation 4. Sign off :-D -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43077 --- Comment #2 from Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> --- Created attachment 201952 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=201952&action=edit Bug 43077: (follow-up) Refactor JWT methods to use encode_claims/decode_claims This patch refactors the existing JWT methods (generate_jwt, check_jwt, decode_jwt) to be thin wrappers around encode_claims/decode_claims, eliminating the private _gen_jwt, _chk_jwt, and _decode_jwt functions. The generate() and check() dispatcher methods are also updated to use the new general methods directly. This makes encode_claims/decode_claims the single source of truth for JWT operations, with the id-based methods as a convenience layer on top. Test plan: 1. Apply patch 2. Run: $ ktd --shell k$ prove t/Token.t t/Koha/Token.t => SUCCESS: Tests pass (both old and new tests) 3. Existing JWT behavior preserved (generate_jwt, check_jwt, decode_jwt all produce identical results) 4. Sign off :-D -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43077 Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|koha-bugs@lists.koha-commun |tomascohen@gmail.com |ity.org | Status|NEW |Needs Signoff CC| |tomascohen@gmail.com -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43077 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Needs Signoff |Signed Off -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43077 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #201951|0 |1 is obsolete| | Attachment #201952|0 |1 is obsolete| | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43077 --- Comment #3 from David Nind <david@davidnind.com> --- Created attachment 202577 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=202577&action=edit Bug 43077: Add encode_claims/decode_claims to Koha::Token This patch adds two methods to Koha::Token for encoding and decoding arbitrary claims as signed JWTs: - encode_claims($hashref) - encodes any hashref as a signed JWT - decode_claims($token) - decodes a JWT and returns the full claims Unlike the existing generate_jwt/decode_jwt methods (which only support a single 'id' string value), these methods support full claim structures including nested hashes and arrays. Both use the standard Koha secret (database password) for signing, reusing the existing _add_default_jwt_params internal function. This will be used by the upcoming Koha::Module::Policy classes, which will serialize per-module capability hashes as JWTs in API response headers. Test plan: 1. Apply patch 2. Run: $ ktd --shell k$ prove t/Koha/Token.t => SUCCESS: Tests pass 3. Tests cover: - Simple hashref encoding/decoding (string, numeric, boolean) - Complex nested structures (hashes, arrays) - JWT format validation 4. Sign off :-D Signed-off-by: David Nind <david@davidnind.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43077 --- Comment #4 from David Nind <david@davidnind.com> --- Created attachment 202578 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=202578&action=edit Bug 43077: (follow-up) Refactor JWT methods to use encode_claims/decode_claims This patch refactors the existing JWT methods (generate_jwt, check_jwt, decode_jwt) to be thin wrappers around encode_claims/decode_claims, eliminating the private _gen_jwt, _chk_jwt, and _decode_jwt functions. The generate() and check() dispatcher methods are also updated to use the new general methods directly. This makes encode_claims/decode_claims the single source of truth for JWT operations, with the id-based methods as a convenience layer on top. Test plan: 1. Apply patch 2. Run: $ ktd --shell k$ prove t/Token.t t/Koha/Token.t => SUCCESS: Tests pass (both old and new tests) 3. Existing JWT behavior preserved (generate_jwt, check_jwt, decode_jwt all produce identical results) 4. Sign off :-D Signed-off-by: David Nind <david@davidnind.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43077 Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Patch complexity|--- |Small patch -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43077 Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #202577|0 |1 is obsolete| | Attachment #202578|0 |1 is obsolete| | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43077 --- Comment #5 from Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> --- Created attachment 205166 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=205166&action=edit Bug 43077: Add encode_claims/decode_claims to Koha::Token This patch adds two methods to Koha::Token for encoding and decoding arbitrary claims as signed JWTs: - encode_claims($hashref) - encodes any hashref as a signed JWT - decode_claims($token) - decodes a JWT and returns the full claims Unlike the existing generate_jwt/decode_jwt methods (which only support a single 'id' string value), these methods support full claim structures including nested hashes and arrays. Both use the standard Koha secret (database password) for signing, reusing the existing _add_default_jwt_params internal function. This will be used by the upcoming Koha::Module::Policy classes, which will serialize per-module capability hashes as JWTs in API response headers. Test plan: 1. Apply patch 2. Run: $ ktd --shell k$ prove t/Koha/Token.t => SUCCESS: Tests pass 3. Tests cover: - Simple hashref encoding/decoding (string, numeric, boolean) - Complex nested structures (hashes, arrays) - JWT format validation 4. Sign off :-D Signed-off-by: David Nind <david@davidnind.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43077 --- Comment #6 from Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> --- Created attachment 205167 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=205167&action=edit Bug 43077: (follow-up) Refactor JWT methods to use encode_claims/decode_claims This patch refactors the existing JWT methods (generate_jwt, check_jwt, decode_jwt) to be thin wrappers around encode_claims/decode_claims, eliminating the private _gen_jwt, _chk_jwt, and _decode_jwt functions. The generate() and check() dispatcher methods are also updated to use the new general methods directly. This makes encode_claims/decode_claims the single source of truth for JWT operations, with the id-based methods as a convenience layer on top. Test plan: 1. Apply patch 2. Run: $ ktd --shell k$ prove t/Token.t t/Koha/Token.t => SUCCESS: Tests pass (both old and new tests) 3. Existing JWT behavior preserved (generate_jwt, check_jwt, decode_jwt all produce identical results) 4. Sign off :-D Signed-off-by: David Nind <david@davidnind.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43077 Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Depends on| |24401 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24401 [Bug 24401] Add POST /checkins endpoint with availability check and confirmation flow -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43077 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- QA Contact|testopia@bugs.koha-communit |martin.renvoize@openfifth.c |y.org |o.uk CC| |martin.renvoize@openfifth.c | |o.uk -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43077 --- Comment #7 from Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> --- Rebased on top of main now that bug 42418 is pushed. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43077 Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #205166|0 |1 is obsolete| | Attachment #205167|0 |1 is obsolete| | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43077 --- Comment #8 from Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> --- Created attachment 209548 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=209548&action=edit Bug 43077: Add encode_claims/decode_claims to Koha::Token This patch adds two methods to Koha::Token for encoding and decoding arbitrary claims as signed JWTs: - encode_claims($hashref) - encodes any hashref as a signed JWT - decode_claims($token) - decodes a JWT and returns the full claims Unlike the existing generate_jwt/decode_jwt methods (which only support a single 'id' string value), these methods support full claim structures including nested hashes and arrays. Both use the standard Koha secret (database password) for signing, reusing the existing _add_default_jwt_params internal function. This will be used by the upcoming Koha::Module::Policy classes, which will serialize per-module capability hashes as JWTs in API response headers. Test plan: 1. Apply patch 2. Run: $ ktd --shell k$ prove t/Koha/Token.t => SUCCESS: Tests pass 3. Tests cover: - Simple hashref encoding/decoding (string, numeric, boolean) - Complex nested structures (hashes, arrays) - JWT format validation 4. Sign off :-D Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Brendan Lawlor <blawlor@clamsnet.org> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43077 --- Comment #9 from Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> --- Created attachment 209549 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=209549&action=edit Bug 43077: (follow-up) Refactor JWT methods to use encode_claims/decode_claims This patch refactors the existing JWT methods (generate_jwt, check_jwt, decode_jwt) to be thin wrappers around encode_claims/decode_claims, eliminating the private _gen_jwt, _chk_jwt, and _decode_jwt functions. The generate() and check() dispatcher methods are also updated to use the new general methods directly. This makes encode_claims/decode_claims the single source of truth for JWT operations, with the id-based methods as a convenience layer on top. Test plan: 1. Apply patch 2. Run: $ ktd --shell k$ prove t/Token.t t/Koha/Token.t => SUCCESS: Tests pass (both old and new tests) 3. Existing JWT behavior preserved (generate_jwt, check_jwt, decode_jwt all produce identical results) 4. Sign off :-D Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Brendan Lawlor <blawlor@clamsnet.org> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43077 --- Comment #10 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- QA review as part of the Bug 42383 dependency chain, applied on current main with 24401 and 42425. Review was done with Claude assistance; items I reproduced are marked, the rest are from reading the code and tests. t/Koha/Token.t and the existing token callers (Checkin, Availability, Checkouts REST, SCO, printslip) pass. I also exercised Mojo::JWT through decode_claims in KTD: expiry is enforced with no leeway (a token that expired 5 seconds ago is rejected), and a tampered payload, alg:none (with and without a signature) and a wrong key are all rejected. That is the behaviour we want. Follow-ups: 1. (reproduced) decode_claims(undef) emits a Perl warning ("Use of uninitialized value $token in split" from Mojo::JWT) before returning undef. A caller that passes a missing cookie to decode_jwt would hit it, and it can trip Test::NoWarnings. Please return early on an undefined or empty token. 2. t/Koha/Token.t only has round trips. Please add negative cases: tampered payload, wrong key, alg:none, garbage input, an expired token and a missing id. 3. encode_claims and decode_claims sign any claims with the single DB-derived key and have no purpose or audience (typ/aud) binding. A validly signed token from one flow (SCO cookie, checkin action tokens, availability tokens) is therefore accepted by decode_jwt in another if the id matches. Please add a typ or aud claim, or document that the id namespace is global. 4. Behaviour changes in the refactor worth documenting in the POD: a caller-supplied secret is now ignored; decode_jwt returns undef and logs a warning instead of dying on a bad token; generate({ type => 'JWT' }) with no id now mints {"id":null}; and encode_claims does not check that the claims are a hashref. 5. Nits: check_jwt and the older check path duplicate the same validation, and _add_default_jwt_params is now only a secret fetcher with a stale POD. Leaving the status at Signed Off; I would move it to Passed QA once 1 and 2 are done. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43077 Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |44080 Attachment #209548|0 |1 is obsolete| | Attachment #209549|0 |1 is obsolete| | Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44080 [Bug 44080] Bind Koha::Token JWTs to their purpose (typ/aud claims) -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43077 --- Comment #11 from Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> --- Created attachment 211509 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=211509&action=edit Bug 43077: Add encode_claims/decode_claims to Koha::Token This patch adds two methods to Koha::Token for encoding and decoding arbitrary claims as signed JWTs: - encode_claims($hashref) - encodes any hashref as a signed JWT - decode_claims($token) - decodes a JWT and returns the full claims Unlike the existing generate_jwt/decode_jwt methods (which only support a single 'id' string value), these methods support full claim structures including nested hashes and arrays. Both use the standard Koha secret (database password) for signing, reusing the existing _add_default_jwt_params internal function. This will be used by the upcoming Koha::Module::Policy classes, which will serialize per-module capability hashes as JWTs in API response headers. Test plan: 1. Apply patch 2. Run: $ ktd --shell k$ prove t/Koha/Token.t => SUCCESS: Tests pass 3. Tests cover: - Simple hashref encoding/decoding (string, numeric, boolean) - Complex nested structures (hashes, arrays) - JWT format validation 4. Sign off :-D Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Brendan Lawlor <blawlor@clamsnet.org> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43077 --- Comment #12 from Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> --- Created attachment 211510 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=211510&action=edit Bug 43077: (follow-up) Refactor JWT methods to use encode_claims/decode_claims This patch refactors the existing JWT methods (generate_jwt, check_jwt, decode_jwt) to be thin wrappers around encode_claims/decode_claims, eliminating the private _gen_jwt, _chk_jwt, and _decode_jwt functions. check_jwt delegates to check(), so the validation lives in one place. This makes encode_claims/decode_claims the single source of truth for JWT operations, with the id-based methods as a convenience layer on top. It also hardens the new methods: - decode_claims returns undef on an undefined or empty token, without warning or logging - decode_claims uses Try::Tiny and logs invalid tokens - encode_claims throws Koha::Exceptions::WrongParameter if the claims are not a hashref - generate({ type => 'JWT' }) without an id returns undef, as before Behaviour changes, documented in the POD: - JWTs are always signed with the Koha secret: a caller-supplied secret is ignored (no caller in Koha passes one) - decode_jwt returns undef and logs a warning on an invalid or expired token, instead of dying Test plan: 1. Apply patch 2. Run: $ ktd --shell k$ prove t/Token.t t/Koha/Token.t => SUCCESS: Tests pass! t/Koha/Token.t covers tampered payloads, a wrong key, alg:none, garbage, expired tokens and tokens without an id 3. Sign off :-D Assisted-by: Opus 5.5 (Anthropic) Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Brendan Lawlor <blawlor@clamsnet.org> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43077 --- Comment #13 from Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> --- Thanks Martin. Addressed in the follow-up patch: 1. decode_claims returns undef on an undefined or empty token, without warning or logging (and uses Try::Tiny instead of eval). 2. Negative tests in t/Koha/Token.t: tampered payload, wrong key, alg:none with and without a signature, garbage, expired token, token without an id, plus generate() and check_jwt() subtests. 3. typ/aud binding: filed as bug 44080, as it affects every caller. 4. Behaviour changes are documented in the POD. Two are reverted instead: generate({ type => 'JWT' }) without an id returns undef again (as on main), and encode_claims throws Koha::Exceptions::WrongParameter when the claims are not a hashref. 5. check_jwt delegates to check(), and the _add_default_jwt_params POD is fixed. The generate() synopsis no longer shows a secret. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43077 --- Comment #14 from Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> --- Thanks Martin. Addressed in the follow-up patch: 1. decode_claims returns undef on an undefined or empty token, without warning or logging (and uses Try::Tiny instead of eval). 2. Negative tests in t/Koha/Token.t: tampered payload, wrong key, alg:none with and without a signature, garbage, expired token, token without an id, plus generate() and check_jwt() subtests. 3. typ/aud binding: filed as bug 44080, as it affects every caller. 4. Behaviour changes are documented in the POD. Two are reverted instead: generate({ type => 'JWT' }) without an id returns undef again (as on main), and encode_claims throws Koha::Exceptions::WrongParameter when the claims are not a hashref. 5. check_jwt delegates to check(), and the _add_default_jwt_params POD is fixed. The generate() synopsis no longer shows a secret. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43077 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks|42383 | Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42383 [Bug 42383] Migrate check-in page to Vue -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43077 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |42383 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42383 [Bug 42383] Migrate check-in page to Vue -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43077 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #211509|0 |1 is obsolete| | Attachment #211510|0 |1 is obsolete| | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43077 --- Comment #15 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 211699 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=211699&action=edit Bug 43077: Add encode_claims/decode_claims to Koha::Token This patch adds two methods to Koha::Token for encoding and decoding arbitrary claims as signed JWTs: - encode_claims($hashref) - encodes any hashref as a signed JWT - decode_claims($token) - decodes a JWT and returns the full claims Unlike the existing generate_jwt/decode_jwt methods (which only support a single 'id' string value), these methods support full claim structures including nested hashes and arrays. Both use the standard Koha secret (database password) for signing, reusing the existing _add_default_jwt_params internal function. This will be used by the upcoming Koha::Module::Policy classes, which will serialize per-module capability hashes as JWTs in API response headers. Test plan: 1. Apply patch 2. Run: $ ktd --shell k$ prove t/Koha/Token.t => SUCCESS: Tests pass 3. Tests cover: - Simple hashref encoding/decoding (string, numeric, boolean) - Complex nested structures (hashes, arrays) - JWT format validation 4. Sign off :-D Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Brendan Lawlor <blawlor@clamsnet.org> Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43077 --- Comment #16 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 211700 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=211700&action=edit Bug 43077: (follow-up) Refactor JWT methods to use encode_claims/decode_claims This patch refactors the existing JWT methods (generate_jwt, check_jwt, decode_jwt) to be thin wrappers around encode_claims/decode_claims, eliminating the private _gen_jwt, _chk_jwt, and _decode_jwt functions. check_jwt delegates to check(), so the validation lives in one place. This makes encode_claims/decode_claims the single source of truth for JWT operations, with the id-based methods as a convenience layer on top. It also hardens the new methods: - decode_claims returns undef on an undefined or empty token, without warning or logging - decode_claims uses Try::Tiny and logs invalid tokens - encode_claims throws Koha::Exceptions::WrongParameter if the claims are not a hashref - generate({ type => 'JWT' }) without an id returns undef, as before Behaviour changes, documented in the POD: - JWTs are always signed with the Koha secret: a caller-supplied secret is ignored (no caller in Koha passes one) - decode_jwt returns undef and logs a warning on an invalid or expired token, instead of dying Test plan: 1. Apply patch 2. Run: $ ktd --shell k$ prove t/Token.t t/Koha/Token.t => SUCCESS: Tests pass! t/Koha/Token.t covers tampered payloads, a wrong key, alg:none, garbage, expired tokens and tokens without an id 3. Sign off :-D Assisted-by: Opus 5.5 (Anthropic) Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Brendan Lawlor <blawlor@clamsnet.org> Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43077 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Signed Off |Passed QA --- Comment #17 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- I have done a final QA run of the whole tree of bugs together (24401, 43077, 43486, 44112 and 42383, applied in order on current main) as a final overall QA review. Setting to Passed QA. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43077 Pedro Amorim (ammopt) <pedro.amorim@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Passed QA |Pushed to main Version(s)| |26.11.00 released in| | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43077 --- Comment #18 from Pedro Amorim (ammopt) <pedro.amorim@openfifth.co.uk> --- Thanks everyone! Pushed to main for 26.11! -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43077 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Text to go in the| |Developers: `Koha::Token` release notes| |gains `encode_claims` and | |`decode_claims`, which sign | |and verify a JWT carrying | |any hashref of claims, | |including nested hashes and | |arrays. `generate_jwt`, | |`check_jwt` and | |`decode_jwt` now wrap these | |methods. | | | |**Upgrade notes** | |- `decode_jwt` now returns | |undef and logs a warning | |for an invalid or expired | |token, instead of dying. | |Callers that relied on the | |exception must check the | |return value. | |- JWTs are always signed | |with the Koha secret. A | |secret passed by the caller | |is ignored. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43077 Lucas Gass (lukeg) <lucas@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Pushed to main |Needs documenting CC| |lucas@bywatersolutions.com --- Comment #19 from Lucas Gass (lukeg) <lucas@bywatersolutions.com> --- Enhancement, no 26.05.x backport. -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org