Skip to content

service: resolve relative __next URLs against the service root - #312

Closed
phanak-sap wants to merge 1 commit into
masterfrom
fixNext
Closed

service: resolve relative __next URLs against the service root#312
phanak-sap wants to merge 1 commit into
masterfrom
fixNext

Conversation

@phanak-sap

Copy link
Copy Markdown
Contributor

OData v2 permits relative __next values. Previously these were passed verbatim into the cross-origin check, which compared an empty scheme/netloc against the service origin and always raised PyODataException.

Now _build_request() detects a relative __next (no scheme, no netloc) and resolves it via urljoin(self._url, ...) before the origin check. Protocol- relative URLs (//host/...) are treated as absolute and validated as before.

Tests added:

  • relative __next resolves to the correct absolute URL and dispatches
  • protocol-relative __next pointing to a foreign host is still rejected

OData v2 permits relative __next values. Previously these were passed
verbatim into the cross-origin check, which compared an empty scheme/netloc
against the service origin and always raised PyODataException.

Now _build_request() detects a relative __next (no scheme, no netloc) and
resolves it via urljoin(self._url, ...) before the origin check. Protocol-
relative URLs (//host/...) are treated as absolute and validated as before.

Tests added:
- relative __next resolves to the correct absolute URL and dispatches
- protocol-relative __next pointing to a foreign host is still rejected
@phanak-sap
phanak-sap requested a review from filak-sap July 28, 2026 10:13
@phanak-sap

Copy link
Copy Markdown
Contributor Author

This is a follow-up feature regression fix for #308.

Comment thread pyodata/v2/service.py
Comment on lines +302 to +303
resolved = urljoin(self._url, self._next_url)
parsed_next = urlparse(resolved)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I do not see the reason for not doing this:

url = urljoin(self._url, self._next_url)

the code below just checks the scheme and host and it comes from self._url.

Comment thread pyodata/v2/service.py
if self._next_url:
parsed_next = urlparse(self._next_url)
# OData v2 allows relative __next values; resolve them against the service root.
if not parsed_next.scheme and not parsed_next.netloc:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would make the condition more strict. If the _next_url has scheme or netloc, then treat it as absolute URL and not just path.

@filak-sap

Copy link
Copy Markdown
Contributor

Please provide links to OData V2 specifications of the relative next link.

@phanak-sap

phanak-sap commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

Please provide links to OData V2 specifications of the relative next link.

My current understanding is this:

If we agree on this being valid bugfix, I will address the other review comments.

@filak-sap

Copy link
Copy Markdown
Contributor

Please provide the evidence for your claim OData v2 permits relative __next values. or close this PR as 'not a bug'.

@phanak-sap

Copy link
Copy Markdown
Contributor Author

Please provide the evidence for your claim OData v2 permits relative __next values. or close this PR as 'not a bug'.

OK. No problem here closing directly as for odata v2 it is vague claim.

@phanak-sap phanak-sap closed this Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants