From 48e593472af9f8410c468ae15cf7ca4286ea679d Mon Sep 17 00:00:00 2001 From: Dimitrij Drus Date: Thu, 5 Nov 2026 02:37:18 +0100 Subject: [PATCH 1/2] fix: Comparing complete covered component identifiers --- signature_input.go | 18 ++++++++-- signature_input_test.go | 71 +++++++++++++++++++++++++------------ verification_policy_test.go | 25 +++++++++++++ 3 files changed, 89 insertions(+), 25 deletions(-) diff --git a/signature_input.go b/signature_input.go index 030a9db..b5e744d 100644 --- a/signature_input.go +++ b/signature_input.go @@ -2,7 +2,6 @@ package httpsig import ( "fmt" - "slices" "time" "github.com/dunglas/httpsfv" @@ -38,7 +37,22 @@ func newSignatureInput( func (si *signatureInput) hasIdentifier(id *componentIdentifier) bool { for _, identifier := range si.identifiers { - if identifier.Value == id.Value && slices.Equal(identifier.Params.Names(), id.Params.Names()) { + if identifier.Value != id.Value || len(identifier.Params.Names()) != len(id.Params.Names()) { + continue + } + + matches := true + for _, name := range id.Params.Names() { + actual, present := identifier.Params.Get(name) + expected, _ := id.Params.Get(name) + if !present || actual != expected { + matches = false + + break + } + } + + if matches { return true } } diff --git a/signature_input_test.go b/signature_input_test.go index befbd86..6a66d34 100644 --- a/signature_input_test.go +++ b/signature_input_test.go @@ -781,41 +781,66 @@ func TestSignatureInputHasIdentifier(t *testing.T) { t.Parallel() for uc, tc := range map[string]struct { - given []*componentIdentifier - identifier *componentIdentifier + given []string + identifier string expected bool }{ "no identifiers": { - identifier: &componentIdentifier{ - Item: httpsfv.Item{Value: "@method", Params: httpsfv.NewParams()}, - }, - expected: false, + identifier: "@method", }, "matching identifier": { - given: []*componentIdentifier{{ - Item: httpsfv.Item{Value: "@method", Params: httpsfv.NewParams()}, - }}, - identifier: &componentIdentifier{ - Item: httpsfv.Item{Value: "@method", Params: httpsfv.NewParams()}, - }, - expected: true, + given: []string{"@method"}, + identifier: "@method", + expected: true, }, "different identifier name": { - given: []*componentIdentifier{{ - Item: httpsfv.Item{Value: "@method", Params: httpsfv.NewParams()}, - }}, - identifier: &componentIdentifier{ - Item: httpsfv.Item{Value: "@authority", Params: httpsfv.NewParams()}, - }, - expected: false, + given: []string{"@method"}, + identifier: "@authority", + }, + "matching parameter value": { + given: []string{`@query-param;name="foo"`}, + identifier: `@query-param;name="foo"`, + expected: true, + }, + "different parameter value": { + given: []string{`@query-param;name="bar"`}, + identifier: `@query-param;name="foo"`, + }, + "different parameter type": { + given: []string{`x-test;value=1`}, + identifier: `x-test;value="1"`, + }, + "different flag value": { + given: []string{`x-test;sf=?0`}, + identifier: `x-test;sf`, + }, + "different parameter name": { + given: []string{`x-test;sf`}, + identifier: `x-test;req`, + }, + "additional parameter": { + given: []string{`x-test;sf;req`}, + identifier: `x-test;sf`, + }, + "missing parameter": { + given: []string{`x-test;sf`}, + identifier: `x-test;sf;req`, + }, + "different parameter order": { + given: []string{`x-test;key="foo";req`}, + identifier: `x-test;req;key="foo"`, + expected: true, }, } { t.Run(uc, func(t *testing.T) { - input := &signatureInput{identifiers: tc.given} + given, err := toComponentIdentifiers(tc.given) + require.NoError(t, err) - found := input.hasIdentifier(tc.identifier) + ids, err := toComponentIdentifiers([]string{tc.identifier}) + require.NoError(t, err) - require.Equal(t, tc.expected, found) + input := &signatureInput{identifiers: given} + assert.Equal(t, tc.expected, input.hasIdentifier(ids[0])) }) } } diff --git a/verification_policy_test.go b/verification_policy_test.go index 869b4cf..e28ac53 100644 --- a/verification_policy_test.go +++ b/verification_policy_test.go @@ -290,6 +290,31 @@ func TestVerificationPolicyAssertMetadata(t *testing.T) { require.ErrorContains(t, err, "too old") }, }, + "expected component identifier has different parameter value": { + params: httpsfv.InnerList{ + Items: []httpsfv.Item{{ + Value: "@query-param", + Params: func() *httpsfv.Params { + params := httpsfv.NewParams() + params.Add("name", "bar") + + return params + }(), + }}, + }, + exp: func() verificationPolicy { + ids, err := toComponentIdentifiers([]string{`@query-param;name="foo"`}) + require.NoError(t, err) + + return verificationPolicy{identifiers: ids, reqCreatedTS: &falseVal, reqExpiresTS: &falseVal} + }(), + assert: func(t *testing.T, err error) { + t.Helper() + + require.ErrorIs(t, err, ErrMissingParameter) + require.ErrorContains(t, err, `"@query-param";name="foo"`) + }, + }, "expected component identifier missing": { params: httpsfv.InnerList{Params: httpsfv.NewParams()}, exp: func() verificationPolicy { From 2897cc440460c3bb2c70bc6f68ecad2248341d81 Mon Sep 17 00:00:00 2001 From: Dimitrij Drus Date: Thu, 5 Nov 2026 02:39:46 +0100 Subject: [PATCH 2/2] linter warnings resolved --- signature_input.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/signature_input.go b/signature_input.go index b5e744d..ab044a2 100644 --- a/signature_input.go +++ b/signature_input.go @@ -42,8 +42,10 @@ func (si *signatureInput) hasIdentifier(id *componentIdentifier) bool { } matches := true + for _, name := range id.Params.Names() { actual, present := identifier.Params.Get(name) + expected, _ := id.Params.Get(name) if !present || actual != expected { matches = false