Skip to content

Fetch a new request token as soon as the browser becomes online#18778

Merged
rullzer merged 1 commit intomasterfrom
fix/fetch-request-token-offline-online
Feb 6, 2020
Merged

Fetch a new request token as soon as the browser becomes online#18778
rullzer merged 1 commit intomasterfrom
fix/fetch-request-token-offline-online

Conversation

@ChristophWurst
Copy link
Copy Markdown
Member

@ChristophWurst ChristophWurst commented Jan 9, 2020

Fixes #16809

Debugging a few Sentry tickets I saw evidence of HTTP 412's -> CSRF check failing. Usually those are unexpected as we periodically fetch the current token, but if the client machine is paused or the browser goes offline, the CSRF token might not be fetched when the connection returns. Thus I added event handlers that can pause the background requests when there is no network connectivity and send off a request for the new token as soon as there is connectivity.

Bildschirmfoto von 2020-01-09 14-14-39

How to test

  • Open Nextcloud
  • Switch browser to offline mode (File -> Work offline on FF, dev tools for Chrome)
  • See detection of offline mode
  • Restart web server (to force new token)
  • Disable offline mode
  • See detection and new token in console

As this is something apps might have interest in, e.g. when to resume operation after offline as you have a dependency on the CSRF token, I added events emitted to the event bus where apps can listen to both the browser going offline as well as coming back online.

Do we want this in 18 already? Then we can backport.

@rullzer
Copy link
Copy Markdown
Member

rullzer commented Jan 9, 2020

O this is very neat. And also very useful for apps indeed!

I guess 19 is good enough for this for now.

@tcitworld
Copy link
Copy Markdown
Member

What about listening to navigator.onLine events instead of polling ?

@kesselb
Copy link
Copy Markdown
Contributor

kesselb commented Jan 16, 2020

Conflicts 😨

@ChristophWurst
Copy link
Copy Markdown
Member Author

What about listening to navigator.onLine events instead of polling ?

We're not polling. We use the online event already to fetch a token when the network state changes. But we need to pool while online as request tokens time out after a certain time.

@ChristophWurst ChristophWurst force-pushed the fix/fetch-request-token-offline-online branch from e4f4ae2 to eb8aa6b Compare January 23, 2020 08:17
console.info('session token successfully updated after resuming network')

// Let apps know we're online and requests will have the new token
emit('networkOnline', {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would be nice to document those somewhere

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Absolutely!

Copy link
Copy Markdown
Member

@juliusknorr juliusknorr left a comment

Choose a reason for hiding this comment

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

Nice 👍

@ChristophWurst ChristophWurst added the pending documentation This pull request needs an associated documentation update label Jan 24, 2020
@rullzer
Copy link
Copy Markdown
Member

rullzer commented Jan 27, 2020

@ChristophWurst can you rebase this? Then we can get this is :)

@ChristophWurst ChristophWurst force-pushed the fix/fetch-request-token-offline-online branch from eb8aa6b to bf2e282 Compare January 27, 2020 09:59
Copy link
Copy Markdown
Member

@gary-kim gary-kim left a comment

Choose a reason for hiding this comment

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

Didn't know about the online event. Cool!

@juliusknorr juliusknorr added 4. to release Ready to be released and/or waiting for tests to finish and removed 3. to review Waiting for reviews labels Feb 4, 2020
@juliusknorr
Copy link
Copy Markdown
Member

needs another rebase 💃

@ChristophWurst ChristophWurst force-pushed the fix/fetch-request-token-offline-online branch from bf2e282 to 9d7f63b Compare February 5, 2020 08:12
@ChristophWurst
Copy link
Copy Markdown
Member Author

Now be quick and merge this :P

@rullzer rullzer force-pushed the fix/fetch-request-token-offline-online branch from 9d7f63b to 4538f08 Compare February 5, 2020 20:23
@rullzer
Copy link
Copy Markdown
Member

rullzer commented Feb 5, 2020

/compile amend /

@npmbuildbot-nextcloud npmbuildbot-nextcloud bot force-pushed the fix/fetch-request-token-offline-online branch from 4538f08 to ca3d6bc Compare February 5, 2020 20:26
@ChristophWurst ChristophWurst force-pushed the fix/fetch-request-token-offline-online branch from ca3d6bc to 6690e3b Compare February 6, 2020 08:13
@ChristophWurst
Copy link
Copy Markdown
Member Author

Rebase cool, rebase fine
Everybody gets a chance
Clap your hands it's party time
Do the rebase dance

@rullzer

This comment has been minimized.

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
@ChristophWurst ChristophWurst force-pushed the fix/fetch-request-token-offline-online branch from 6690e3b to d1886b5 Compare February 6, 2020 13:16
@rullzer rullzer merged commit 368b401 into master Feb 6, 2020
@rullzer rullzer deleted the fix/fetch-request-token-offline-online branch February 6, 2020 20:28
@ChristophWurst ChristophWurst removed the pending documentation This pull request needs an associated documentation update label Apr 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4. to release Ready to be released and/or waiting for tests to finish bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CSRF Check failed after being offline for a while

6 participants