Skip to content

[4.x] Request JSON in requestToken() and encode the authorization link - #93

Open
Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-oauth-web-flow
Open

Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-oauth-web-flow

Conversation

@Hackwar

@Hackwar Hackwar commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary of Changes

  • Authorization::requestToken() with the default $format = '' sent no Accept header, so GitHub answered access_token=…&scope=… (form-encoded). processResponse() json-decoded that to null and the token was lost. Without a format it now sends Accept: application/json, so the method returns the decoded object (access_token, scope, token_type). The @return doc block said string; it is an object.
  • Authorization::getAuthorizationLink() urlencoded only redirect_uri. Joomla\Uri\Uri does not encode the query values it renders, so a scope of repo user produced a literal space and an attacker-influenced state containing & could inject parameters (…&scope=repo user&state=st&scope=admin). The link is now built with http_build_query(…, PHP_QUERY_RFC3986). This works with the current joomla/uri.

requestToken($format = 'xml') still json-decodes the XML answer (and returns null); that was not part of the report and is left as is.

Testing Instructions

AuthorizationsTest::testRequestToken now checks the request (data and Accept header) and the decoded token; testGetAuthorizationLinkEncodesValues checks the encoding of redirect_uri, scope and state. Both fail before the change.

Documentation Changes Required

docs/overview.md: new section "OAuth web application flow". #66's packages.md lists getAuthorizationLink/requestToken without details; nothing to adjust there.

🤖 Generated with Claude Code

Without a format, requestToken() sent no Accept header, so GitHub
answered form-encoded and the token was lost when the body was decoded
as JSON. getAuthorizationLink() left scope and state unencoded, because
Joomla\Uri\Uri does not encode the query values it renders: a scope of
"repo user" produced a literal space and a state containing "&" could
add parameters.

Request JSON by default and build the authorization link with
http_build_query(PHP_QUERY_RFC3986).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant