Skip to content
Draft
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
7 changes: 3 additions & 4 deletions okta/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from datetime import datetime as dt
from enum import Enum
from typing import Any
from urllib.parse import urlsplit, urlunsplit, urlparse, urlunparse
from urllib.parse import urlsplit, urlunsplit

from okta.constants import DATETIME_FORMAT, EPOCH_DAY, EPOCH_MONTH, EPOCH_YEAR

Expand Down Expand Up @@ -48,7 +48,7 @@ def normalize_dpop_url(url: str) -> str:
>>> normalize_dpop_url('https://example.com/api/users?limit=10#section1')
'https://example.com/api/users'
"""
parsed = urlparse(url)
parsed = urlsplit(url)

# Validate that URL has required components for DPoP htu claim
if not parsed.scheme or not parsed.netloc:
Expand All @@ -57,11 +57,10 @@ def normalize_dpop_url(url: str) -> str:
"URL must include scheme (https) and netloc (domain)."
)

return urlunparse((
return urlunsplit((
parsed.scheme, # scheme (http/https)
parsed.netloc, # network location (host:port)
parsed.path, # path
'', # params (deprecated, kept for compatibility)
'', # query (empty per RFC 9449)
'' # fragment (empty per RFC 9449)
))
Expand Down
21 changes: 21 additions & 0 deletions tests/test_dpop.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,27 @@ def test_url_parsing_strips_query_and_fragment(self):
# htu should be clean
self.assertEqual(decoded['htu'], 'https://example.okta.com/api/v1/users')

def test_url_parsing_preserves_path_parameters(self):
"""Signed proofs retain the complete path while excluding query/fragment."""
paths = (
'/api/v1/users;view=full',
'/api/v1/users;',
'/api/v1/users;x=1;y=2',
'/api/v1/users%3Bview=full',
'/api/v1/teams;view=full/users',
)
for path in paths:
with self.subTest(path=path):
expected = 'https://example.okta.com' + path
proof = self.generator.generate_proof_jwt(
'GET', expected + '?limit=10#section'
)
public_key = jwt.PyJWK.from_dict(
jwt.get_unverified_header(proof)['jwk']
).key
claims = jwt.decode(proof, public_key, algorithms=['RS256'])
self.assertEqual(claims['htu'], expected)

def test_generate_proof_with_nonce(self):
"""Test DPoP proof generation with nonce."""
proof = self.generator.generate_proof_jwt(
Expand Down