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

Use correct /v3 prefix for /refresh #3016

Merged
merged 6 commits into from
Jun 3, 2023

Conversation

davidisaaclee
Copy link
Contributor

@davidisaaclee davidisaaclee commented Jan 2, 2023

Checklist

  • Tests written for new code (and old code if feasible) – I only added tests for the default behavior, not for all configurations of the options I added. Will wait on review to add any more.
  • Linter and other CI checks pass
  • Sign-off given on the changes (see CONTRIBUTING.md)

Synapse v1.71 and below incorrectly exposed /refresh under the /v1 endpoint. This was fixed in matrix-org/synapse#14364, which was released with v1.72.0. This fix causes matrix-js-sdk's MatrixClient#refreshToken to fail when targeting newer Synapse instances (or any server which correctly implements the spec). matrix-js-sdk currently fails refreshToken when targeting the matrix.org homeserver.

I've supplied some alternative levels of fixing in this PR, since I don't know how committed you are to preserving backwards compatibility / matching the spec; my goal was that we could drop or squash commits as maintainers desire to match the expectations of this repo.

  • a8df2a9 simply swaps out the /v1 prefix to instead use /v3. This is correct, but breaks clients targeting older Synapses.
  • 2c85e75 gives an option to refreshToken for library consumers to explicitly ask for /v1; will break things by default, but consumers can individually manage calling the incorrect /v1 prefix.
  • c8aa908 adds an option to first try the correct /v3 prefix, then retry with /v1 on M_UNRECOGNIZED, defaulting to false. Default behavior is correct to spec without extra weight, but breaks users on old Synapses; but users can opt in to an automatic fix by adding the option.
  • 39edcd5 enables the retry option by default, which should work for everyone, but adds complexity by default (e.g. this could be confusing if /refresh raises an M_UNRECOGNIZED which is not relevant to this issue)

I noted that getRoomHierarchy has a similar approach, but for switching between unstable and stable endpoints:

matrix-js-sdk/src/client.ts

Lines 9266 to 9279 in e6bf5eb

return this.http
.authedRequest<IRoomHierarchy>(Method.Get, path, queryParams, undefined, {
prefix: ClientPrefix.V1,
})
.catch((e) => {
if (e.errcode === "M_UNRECOGNIZED") {
// fall back to the prefixed hierarchy API.
return this.http.authedRequest<IRoomHierarchy>(Method.Get, path, queryParams, undefined, {
prefix: "/_matrix/client/unstable/org.matrix.msc2946",
});
}
throw e;
});

Signed-off-by: David Lee david.isaac.lee@gmail.com


Here's what your changelog entry will look like:

✨ Features

@github-actions github-actions bot added the Z-Community-PR Issue is solved by a community member's PR label Jan 2, 2023
@davidisaaclee davidisaaclee marked this pull request as ready for review January 3, 2023 00:17
@davidisaaclee davidisaaclee requested a review from a team as a code owner January 3, 2023 00:17
spec/unit/login.spec.ts Outdated Show resolved Hide resolved
@richvdh richvdh self-requested a review February 14, 2023 16:13
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

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

@davidisaaclee thanks very much for picking this up, and sorry that it appears to have languished rather than getting a prompt review.

In general, I'd say that exposing both forcePrefixV1 and retryWithPrefixV1OnUnrecognizedRequest to the application are unnecessary flexibility. The application should expect the SDK to take care of picking the right endpoint to use.

I think your default behaviour of retrying would be fine.

However, in this particular case, I think there's a strong argument that we shouldn't support /v1/refresh at all. It was never written down in the spec, and I would expect any users trying to use refresh tokens to be doing it with recent versions of Synapse. So personally I would drop all the fancy logic and just use /v3/refresh. YMMV though.

@davidisaaclee
Copy link
Contributor Author

@richvdh Thank you for reviewing. It makes sense that the library should just work, so I'll remove these options.

I think there's a strong argument that we shouldn't support /v1/refresh at all [...] I would expect any users trying to use refresh tokens to be doing it with recent versions of Synapse

My motivation for this PR is that I'm trying to use refresh tokens with an older version of Synapse as well as with the matrix.org server, so the retry logic is directly helping my use case and likely would help others like me (probably what you meant by "YMMV") — so I would selfishly prefer to keep the default behavior of "try /v3/refresh first, then /v1/refresh on M_UNRECOGNIZED." Without that behavior, I would need to manually catch the error and do a raw HTTP request from my application – yuck!

I'll plan to make these code changes soon (requires more than reverts to add retry without exposing configuration param).

@davidisaaclee
Copy link
Contributor Author

I rewrote git history on this branch since the changes were significant. To recap:

@davidisaaclee davidisaaclee requested review from richvdh and removed request for florianduros and SimonBrandner March 11, 2023 02:51
src/client.ts Outdated Show resolved Hide resolved
spec/unit/login.spec.ts Show resolved Hide resolved
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

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

other than my comments on comments, this looks great.

Please could you sign off your contribution by adding a comment to the PR with "Signed-off-by: ...", as per https://github.com/vector-im/element-web/blob/develop/CONTRIBUTING.md#sign-off.

spec/unit/login.spec.ts Outdated Show resolved Hide resolved
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
@davidisaaclee
Copy link
Contributor Author

@richvdh added sign-off to PR description

thanks again for review. I think everything is addressed now, lmk what's next!

Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

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

looks great, thank you!

@davidisaaclee
Copy link
Contributor Author

Hey – is there anything I can do to help merge this?

@richvdh
Copy link
Member

richvdh commented Jun 3, 2023

Thank you for the reminder; I don't know why github hasn't merged it. Hopefully it will work this time; if it hasn't auto-merged in a couple of hours feel free to ping me again

@richvdh richvdh added this pull request to the merge queue Jun 3, 2023
Merged via the queue into matrix-org:develop with commit 258f157 Jun 3, 2023
toger5 pushed a commit that referenced this pull request Jun 7, 2023
* Add tests to ensure /v3/refresh is called + automatic /v1 retry

* Request /refresh with v3 prefix, and quietly fall back to v1

* Add tests checking re-raising errors

* Update spec/unit/login.spec.ts

* Update comment

Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>

---------

Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
toger5 added a commit that referenced this pull request Jun 7, 2023
…ate (#3424)

* send expected peer connections to posthog.
(based on roomState event)

* add tests

* change GroupCallStats initialized

* prettier

* more test and catch for promise

* seperate the participant logic in a summary extend function

Signed-off-by: Timo K <toger5@hotmail.de>

* remove unused

Signed-off-by: Timo K <toger5@hotmail.de>

* rename summaryStatsReportGatherer to "Reporter"
for the summary stats there is only one instance because there is only
one summary. Since we dont have a list of gatherers it this class only reports.
Hence we rename it to be a reporter.

Signed-off-by: Timo K <toger5@hotmail.de>

* review

Signed-off-by: Timo K <toger5@hotmail.de>

* Update src/webrtc/stats/groupCallStats.ts

Co-authored-by: Robin <robin@robin.town>

* revert rename

Signed-off-by: Timo K <toger5@hotmail.de>

* Update all non-major dependencies (#3433)

* Update all non-major dependencies

* Remove name wrap-ansi-cjs

* Remove name string-width-cjs

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>

* Update definitelyTyped (#3430)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>

* Export FALLBACK_ICE_SERVER (#3429)

* Add an integration test for verification (#3436)

* Move existing crypto integ tests into a subdirectory

* Factor out some common bits from `crypto.spec.ts`

* Integration test for device verification

* Ignore generated file in prettier

* Always show a summary after Jest tests (#3440)

... because it is otherwise impossible to see what failed.

* Use correct /v3 prefix for /refresh (#3016)

* Add tests to ensure /v3/refresh is called + automatic /v1 retry

* Request /refresh with v3 prefix, and quietly fall back to v1

* Add tests checking re-raising errors

* Update spec/unit/login.spec.ts

* Update comment

Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>

---------

Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>

* Update Mutual Rooms (MSC2666) support (#3381)

* update mutual rooms support

* clarify docs and switch eslint comment with todo

* please the holy linter

* change query variable names around

* add mock tests and fix issue

* ye holy linter

* GHA: build and cypress-test a copy of element-web after each push (#3412)

* Build a copy of element-web after each push

* Run cypress after each build of element-web

* Fix downstream-artifacts build (#3443)

* Fix downstream-artifacts build

* Update cypress.yml

* Fix edge cases around 2nd order relations and threads (#3437)

* Fix tests oversimplifying threads fixtures

* Check for unsigned thread_id in MatrixEvent::threadRootId

* Fix threads order being racy

* Make Sonar happier

* Iterate

* Make sliding sync linearize processing of sync requests (#3442)

* Make sliding sync linearize processing of sync requests

* Iterate

* Iterate

* Iterate

* Iterate

* Disable downstream artifacts build for develop branch (#3444)

* Export thread-related types from SDK (#3447)

* Export thread-related types from SDK

* address PR feedback

* Integration test for QR code verification (#3439)

* Integration test for QR code verification

Followup to #3436: another
integration test, this time using the QR code flow

* Use Object.defineProperty, and restore afterwards

Apparently global.crypto exists in some environments

* apply ts-ignore

* remove stray comment

* Update spec/integ/crypto/verification.spec.ts

* Add `getShowSasCallbacks`, `getShowQrCodeCallbacks` to VerifierBase (#3422)

* Add `getShowSasCallbacks`, `getShowQrCodeCallbacks` to VerifierBase

... to avoid some type-casting

* Integration test for QR code verification

Followup to #3436: another
integration test, this time using the QR code flow

* Rename method

... it turns out not to be used quite as I thought.

* tests for new methods

* Use Object.defineProperty, and restore afterwards

Apparently global.crypto exists in some environments

* apply ts-ignore

* More test coverage

* fix bad merge

* Fix changelog_head.py script to be Python 3 compatible

* Prepare changelog for v25.2.0-rc.1

* v25.2.0-rc.1

* Fix tsconfig-build.json

* Prepare changelog for v25.2.0-rc.2

* v25.2.0-rc.2

* Fix docs deployment

* Prepare changelog for v25.2.0-rc.3

* v25.2.0-rc.3

* Prepare changelog for v25.2.0-rc.4

* v25.2.0-rc.4

* [Backport staging] Attempt a potential workaround for stuck notifs (#3387)

Co-authored-by: Andy Balaam <andy.balaam@matrix.org>

* Prepare changelog for v25.2.0-rc.5

* v25.2.0-rc.5

* [Backport staging] Fix mark as unread button (#3401)

Co-authored-by: Michael Weimann <michaelw@matrix.org>

* Prepare changelog for v26.0.0-rc.1

* v26.0.0-rc.1

* Prepare changelog for v26.0.0

* v26.0.0

* Resetting package fields for development

* use cli.canSupport to determine intentional mentions support (#3445)

* use cli.canSupport to determine intentional mentions support

* more specific comment

* Update src/client.ts

Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>

---------

Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>

* git fixup

Signed-off-by: Timo K <toger5@hotmail.de>

* import updates

Signed-off-by: Timo K <toger5@hotmail.de>

* dont revert enricos change

Signed-off-by: Timo K <toger5@hotmail.de>

* temp rename for lowercase

* lowercase

---------

Signed-off-by: Timo K <toger5@hotmail.de>
Co-authored-by: Robin <robin@robin.town>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
Co-authored-by: David Lee <david@david-lee.net>
Co-authored-by: Jonathan de Jong <jonathan@automatia.nl>
Co-authored-by: Stanislav Demydiuk <stas-demydiuk@users.noreply.github.com>
Co-authored-by: ElementRobot <releases@riot.im>
Co-authored-by: Andy Balaam <andy.balaam@matrix.org>
Co-authored-by: Michael Weimann <michaelw@matrix.org>
Co-authored-by: Kerry <kerrya@element.io>
su-ex added a commit to SchildiChat/matrix-js-sdk that referenced this pull request Feb 22, 2024
* Introduce a new `Crypto.Verifier` interface, and deprecate direct access to `VerificationBase`, `SAS` and `ReciprocateQRCode` ([\matrix-org#3414](matrix-org#3414)).
* Add `rust-crypto#isCrossSigningReady` implementation ([\matrix-org#3462](matrix-org#3462)). Contributed by @florianduros.
* OIDC: Validate `m.authentication` configuration ([\matrix-org#3419](matrix-org#3419)). Contributed by @kerryarchibald.
* ElementR: Add `CryptoApi.getCrossSigningStatus` ([\matrix-org#3452](matrix-org#3452)). Contributed by @florianduros.
* Extend stats summary with call device and user count based on room state ([\matrix-org#3424](matrix-org#3424)). Contributed by @toger5.
* Update MSC3912 implementation to use `with_rel_type` instead of `with_relations` ([\matrix-org#3420](matrix-org#3420)).
* Export thread-related types from SDK ([\matrix-org#3447](matrix-org#3447)). Contributed by @stas-demydiuk.
* Use correct /v3 prefix for /refresh ([\matrix-org#3016](matrix-org#3016)). Contributed by @davidisaaclee.
* Fix thread list being ordered based on all updates ([\matrix-org#3458](matrix-org#3458)). Fixes element-hq/element-web#25522.
* Fix: handle `baseUrl` with trailing slash in `fetch.getUrl` ([\matrix-org#3455](matrix-org#3455)). Fixes element-hq/element-web#25526. Contributed by @kerryarchibald.
* use cli.canSupport to determine intentional mentions support ([\matrix-org#3445](matrix-org#3445)). Fixes element-hq/element-web#25497. Contributed by @kerryarchibald.
* Make sliding sync linearize processing of sync requests ([\matrix-org#3442](matrix-org#3442)).
* Fix edge cases around 2nd order relations and threads ([\matrix-org#3437](matrix-org#3437)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-Enhancement Z-Community-PR Issue is solved by a community member's PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants