Feat: support downscoping for ID-JAG assertions#3225
Feat: support downscoping for ID-JAG assertions#3225havetisyan merged 19 commits intoAthenZ:masterfrom
ID-JAG assertions#3225Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a crucial security enhancement by enforcing scope subsetting for JWT-bearer requests. It ensures that any requested scope is a valid, narrower version of the scope granted in the original assertion, thereby preventing privilege escalation and adhering to standard security practices for token exchange. Highlights
Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
The pull request adds support for down-scoping JWT-bearer tokens by providing a scope parameter, as per RFC7523. The implementation is mostly correct, but there's a potential issue with how scope strings are parsed, specifically when they contain only whitespace. This could lead to incorrect behavior in edge cases. I've provided a suggestion to make the scope parsing more robust.
servers/zts/src/main/java/com/yahoo/athenz/zts/token/AccessTokenRequest.java
Outdated
Show resolved
Hide resolved
|
/gemini review |
Signed-off-by: Jeongwoo Kim - jekim <jekim@lycorp.co.jp>
There was a problem hiding this comment.
Code Review
This pull request adds scope subset validation for ID-JAG token requests. However, the current implementation has a potential NullPointerException if the assertion token lacks a scope claim, which could lead to a minor Denial of Service (DoS) attack. A fix for this medium-severity issue has been suggested. Additionally, a medium-severity suggestion is provided to improve robustness by handling duplicate scopes in the request.
servers/zts/src/main/java/com/yahoo/athenz/zts/token/AccessTokenRequest.java
Outdated
Show resolved
Hide resolved
servers/zts/src/main/java/com/yahoo/athenz/zts/token/AccessTokenRequest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Code Review
The pull request adds scope validation for ID-JAG tokens, ensuring that a requested scope is a subset of the scope in the assertion token. My review identifies a potential NullPointerException if the assertion token does not contain a scope, which is a high-severity issue. I've provided a fix to handle this case gracefully. Additionally, I've suggested an improvement to handle duplicate scopes in the request, ensuring the resulting token has a normalized, unique set of scopes, which aligns better with OAuth 2.0 specifications.
servers/zts/src/main/java/com/yahoo/athenz/zts/token/AccessTokenRequest.java
Outdated
Show resolved
Hide resolved
servers/zts/src/main/java/com/yahoo/athenz/zts/token/AccessTokenRequest.java
Outdated
Show resolved
Hide resolved
…enRequest.java Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Signed-off-by: Aaron Jeongwoo Kim <53258958+mlajkim@users.noreply.github.com>
…enRequest.java Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Signed-off-by: Aaron Jeongwoo Kim <53258958+mlajkim@users.noreply.github.com>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request adds support for scope subsetting for ID-JAG tokens as per RFC 7521. When a scope is provided in a JWT Bearer Grant request, the code now validates that the requested scope is a subset of the scope in the original assertion token. My review includes a suggestion to use LinkedHashSet instead of HashSet to preserve the order of scopes, ensuring deterministic behavior.
servers/zts/src/main/java/com/yahoo/athenz/zts/token/AccessTokenRequest.java
Outdated
Show resolved
Hide resolved
ID-JAG => AccessToken
…enRequest.java Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Signed-off-by: Aaron Jeongwoo Kim <53258958+mlajkim@users.noreply.github.com>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a critical security enhancement by validating that the requested scope in a JWT Bearer Grant flow is a subset of the scope granted in the original assertion token, preventing a client from escalating its privileges. The implementation correctly parses the space-delimited scopes and performs the subset check. No specific security issues or vulnerabilities were identified in the provided code changes, and the potential edge case regarding trimmedScope was evaluated and determined to be handled correctly. There are a couple of suggestions to improve code style and maintainability.
servers/zts/src/main/java/com/yahoo/athenz/zts/token/AccessTokenRequest.java
Outdated
Show resolved
Hide resolved
servers/zts/src/main/java/com/yahoo/athenz/zts/token/AccessTokenRequest.java
Outdated
Show resolved
Hide resolved
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a critical security enhancement for JWT Bearer grant type requests. It adds validation to ensure that if a scope is requested, it must be a subset of or equal to the scope present in the assertion token (ID-JAG). This prevents a client from escalating privileges by requesting a token with a broader scope than originally granted. The implementation appears correct, and the accompanying review comment correctly identifies the crucial need for unit tests to verify the new logic and prevent regressions. Overall, the changes are a significant improvement to the security of the token exchange flow.
servers/zts/src/main/java/com/yahoo/athenz/zts/token/AccessTokenRequest.java
Outdated
Show resolved
Hide resolved
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request implements scope validation and downscoping for JAG token exchanges, aligning with RFC 7521. My review includes a suggestion for code simplification and a note about adding unit tests for this new security-critical logic.
Note: Security Review did not run due to the size of the PR.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a critical security enhancement by enforcing that the requested scope for an access token is a subset of the scope in the JWT Assertion for Grant (JAG) token. This prevents scope escalation. The implementation correctly validates the scopes and down-scopes the token if a valid subset is requested. The accompanying tests are comprehensive and cover various scenarios using a data provider, which is a great improvement. I have one suggestion to improve the robustness of the scope validation.
Note: Security Review did not run due to the size of the PR.
|
/gemini summary |
Summary of ChangesThis pull request significantly strengthens the security posture of the Athenz Token Service (ZTS) by introducing critical validation for ID-JAG token exchanges. It mandates the presence of a scope in ID-JAG assertions and enforces strict downscoping rules, ensuring that any requested Access Token scope is a valid subset of the originally asserted scope. This prevents potential privilege escalation and aligns the system with established OAuth 2.0 security best practices. Highlights
Changelog
Activity
|
Signed-off-by: Jeongwoo Kim - jekim <jekim@lycorp.co.jp>
ID-JAG => AccessTokenID-JAG assertions
ID-JAG assertionsID-JAG assertions
|
@havetisyan, let me know what you think when you get a chance. |
Description
The Athenz ZTS server currently requires an ID-JAG with a mandatory
scope; otherwise, it will return the following error:This PR changes the
scopehandling so that instead of strictly enforcing the mandatoryscopefrom the assertion, it now uses the requester's requestedscope, originally granted to the authorized accessor. This allows a requester (e.g., an AI Agent) to voluntarily downscope its own permissions for safer access, aligning with the RFC 7521 standard, which states the following:What's done
Related Issue: #3100
Contribution Checklist: