Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: https://github.com/AxisCommunications/go-dpop/issues/9 #10

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"math/big"
"net/url"
"strings"
Expand Down Expand Up @@ -89,7 +90,10 @@ func Parse(

// Check that `htm` and `htu` claims match the HTTP method and URL of the current request.
// This satisfies point 8 and 9 in https://datatracker.ietf.org/doc/html/draft-ietf-oauth-dpop#section-4.3
if httpMethod != claims.Method || httpURL.String() != claims.URL {

// Addresses https://github.com/AxisCommunications/go-dpop/issues/9
httpUrlParsed := fmt.Sprintf("%s://%s%s", httpURL.Scheme, httpURL.Hostname(), httpURL.Path)
if httpMethod != claims.Method || httpUrlParsed != claims.URL {
return nil, errors.Join(ErrInvalidProof, ErrIncorrectHTTPTarget)
}

Expand Down
29 changes: 29 additions & 0 deletions parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,35 @@ func TestParse_IncorrectHtu(t *testing.T) {
}
}

// Test that an htu claim with query or fragments is properly parsed
// and passes validation according to DPoP spec
func TestParse_CorrectHttpURLWithQueryFragments(t *testing.T) {
// Arrange
httpUrl := url.URL{
Scheme: "https",
Host: "server.example.com",
Path: "/token",
Fragment: "#fragment",
RawQuery: "foo=bar",
}
duration := time.Duration(438000) * time.Hour
opts := dpop.ParseOptions{
Nonce: "",
TimeWindow: &duration,
}

// Act
proof, err := dpop.Parse(validES256_proof, dpop.POST, &httpUrl, opts)

// Assert
if err != nil {
t.Errorf("wanted nil, got %e", err)
}
if proof == nil || proof.Valid != true {
t.Errorf("Expected token to be valid")
}
}

// Test that expired proof is rejected
func TestParse_ExpiredProof(t *testing.T) {
// Arrange
Expand Down