Skip to content

Commit

Permalink
validate invocation token args
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiobozzo committed Dec 2, 2024
1 parent 56eab75 commit 311b942
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/args/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,14 @@ func (a *Args) Clone() *Args {
}
return res
}

// Validate checks that all values in the Args are valid according to UCAN specs
func (a *Args) Validate() error {
for key, value := range a.Values {
if err := limits.ValidateIntegerBoundsIPLD(value); err != nil {
return fmt.Errorf("value for key %q: %w", key, err)
}
}

return nil
}
4 changes: 4 additions & 0 deletions token/invocation/invocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ func tokenFromModel(m tokenPayloadModel) (*Token, error) {
tkn.nonce = m.Nonce

tkn.arguments = m.Args
if err := tkn.arguments.Validate(); err != nil {
return nil, fmt.Errorf("invalid arguments: %w", err)
}

tkn.proof = m.Prf
tkn.meta = m.Meta

Expand Down

0 comments on commit 311b942

Please sign in to comment.