Skip to content
Open
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
8 changes: 4 additions & 4 deletions cmd/akash/cmd/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ func authJWTCmd() *cobra.Command {
return err
}

exp = time.Unix(nbfInt, 0)
nbf = time.Unix(nbfInt, 0)
} else {
exp = now.Add(dur)
nbf = now.Add(dur)
Comment on lines +84 to +86
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Flip the nbf/exp validation predicate.

These assignments are correct, but Line 117 still uses !nbf.After(exp), so the command rejects the valid case where nbf < exp. With the default nbf=now and any future exp, auth jwt errors out.

if !exp.After(nbf) {
	return fmt.Errorf("`nbf` value is invalid. expected %d (nbf) < %d (exp)", nbf.Unix(), exp.Unix())
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/akash/cmd/auth.go` around lines 84 - 86, The validation currently uses
the wrong predicate when checking the JWT times: change the condition that
enforces nbf < exp from using !nbf.After(exp) to checking the expiration against
not-after the nbf (e.g., if !exp.After(nbf) { return fmt.Errorf(...)}), so the
check in auth.go (the block that returns the fmt.Errorf about "`nbf` value is
invalid. expected %d (nbf) < %d (exp)") correctly rejects cases where exp is not
after nbf.

}
}

Expand All @@ -100,12 +100,12 @@ func authJWTCmd() *cobra.Command {
var scope ajwt.PermissionScopes

if cmd.Flags().Changed(FlagJWTScope) {
scopeString, err := cmd.Flags().GetString(FlagJWTAccess)
scopeStrings, err := cmd.Flags().GetStringSlice(FlagJWTScope)
if err != nil {
return err
}

if err = scope.UnmarshalCSV(scopeString); err != nil {
if err = scope.UnmarshalCSV(strings.Join(scopeStrings, ",")); err != nil {
Comment on lines 102 to +108
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Reject --scope unless --access=scoped.

This block still accepts --scope when --access is full or granular, even though the flag contract says otherwise. That lets the CLI mint contradictory lease claims.

Suggested guard
 if cmd.Flags().Changed(FlagJWTScope) {
+	if access != ajwt.AccessTypeScoped {
+		return fmt.Errorf("`scope` can only be set when `access=scoped`")
+	}
+
 	scopeStrings, err := cmd.Flags().GetStringSlice(FlagJWTScope)
 	if err != nil {
 		return err
 	}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if cmd.Flags().Changed(FlagJWTScope) {
scopeString, err := cmd.Flags().GetString(FlagJWTAccess)
scopeStrings, err := cmd.Flags().GetStringSlice(FlagJWTScope)
if err != nil {
return err
}
if err = scope.UnmarshalCSV(scopeString); err != nil {
if err = scope.UnmarshalCSV(strings.Join(scopeStrings, ",")); err != nil {
if cmd.Flags().Changed(FlagJWTScope) {
if access != ajwt.AccessTypeScoped {
return fmt.Errorf("`scope` can only be set when `access=scoped`")
}
scopeStrings, err := cmd.Flags().GetStringSlice(FlagJWTScope)
if err != nil {
return err
}
if err = scope.UnmarshalCSV(strings.Join(scopeStrings, ",")); err != nil {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/akash/cmd/auth.go` around lines 102 - 108, The current block accepts
--scope whenever FlagJWTScope is provided; add a guard to reject --scope unless
the JWT access flag equals "scoped" by reading FlagJWTAccess (e.g. via
cmd.Flags().GetString(FlagJWTAccess) or the existing access variable) before
calling scope.UnmarshalCSV: if access != "scoped" return a user-facing error
like "the --scope flag is only valid when --access=scoped", otherwise proceed to
parse scope; update the check located with FlagJWTScope and scope.UnmarshalCSV
to enforce this contract.

return err
}
}
Expand Down