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

proxy auth broken again #1028

Open
gardiol opened this issue Aug 7, 2024 · 19 comments
Open

proxy auth broken again #1028

gardiol opened this issue Aug 7, 2024 · 19 comments
Labels
bug Something isn't working

Comments

@gardiol
Copy link

gardiol commented Aug 7, 2024

My website is broken again using proxy auth on subdomain.

All i get is a permanent page reload and no browser authentication popup from silberbullet

I have just upgraded from ad old, but working, build to latest release on github.

Its a regression, sorry ;)

Previously it was this ticket: #804

And it was fixed.

Some more context:

  • I host sb on "notes.mydomain.net"
  • I have a nginx reverse proxy that redirect and authenticate, to sb socket
  • sb runs on my server as its dedicated user for proper filesystem permissions
  • sb downloaded from github releases page
  • Firefox just reload the page indefinitely if not already authenticated
  • before, after issue 804 was fixed, it would popup a browser authentication dialog and then would work

Currently I am forced to stop using sb at least while outside home, where the proxy auth is not used.

@zefhemel
Copy link
Collaborator

zefhemel commented Aug 7, 2024

Do you happen to remember what the mat version was that you ran? And now you're on 0.9? I don't think anything has changed here for a very long time.

@gardiol
Copy link
Author

gardiol commented Aug 8, 2024

I am currently using 0.9.0, and i was previously on 0.7.6 (IIRC).

I have to say that the issue seems to be present only on mobile browsers (tested latest Firefox on Android). Both Chrome and Firefox on Linux instead do a single page reload and then the auth popup is displayed.

@gorootde
Copy link
Contributor

gorootde commented Aug 10, 2024

Same issue on MacOS & iOS using Safari or in PWA. Also Firefox on MacOS shows the issue.

I was able to interrupt the endless reload loop and capture some information from the browser's console. Hope that helps.

Got error fetching, throwing offline "<url>/index.json" - TypeError: Load Failed - client.js:18:16709
Error: Offline - client.js:17
Booting SilverBullet client - "in Online Mode"
Service worker registered...
Rebuilding editor state
Failed to load resource: the server responded with a status of 401 - <url>/.ping
Failed to load resource: the server responded with a status of 503 - <url>/index.json
Could not reach remote server, we're offline or the server is down - Error: Not authenticated, got 403 - client.js:18:16563
Loading plugs
(Re)loading plugs
alreadyFetching is on, skipping even triggering for fetchFileList - client.js:18
Error: Offline - client.js:18
Failed to load resource: the server responded with a status of 503 - <url>/index.json
Error: Offline - client.js:18
...

I am running 0.9.0 as well.

@zefhemel zefhemel added the bug Something isn't working label Aug 11, 2024
@zefhemel
Copy link
Collaborator

Ok, pushed some tweaks to default, should be on edge soon. Could you check if this fixes or at least gives some more info?

@gardiol
Copy link
Author

gardiol commented Aug 26, 2024

I have just tried build 0.9.2 and i can report that now not even Firefox on linux works, the page just keep reloading forever. what's annoying is that i can see the entire content of the page even before the authentication (but this might be cached in the browser).

I need to test edge but unclear how to do it

@gardiol
Copy link
Author

gardiol commented Aug 26, 2024

The website now keeps popping up "You are not authenticated, going to reload and hope that that kicks off authentication" forever. Tried on Chrome and Firefox for Linux.

This is from firefox javascript console while stopped at popup:

Loading plugs [client.js:2528:21166](https://notes.mydomain.com/.client/client.js)
(Re)loading plugs [client.js:2528:21225](https://notes.mydomain.com/.client/client.js)
Activated plug editor [client.js:2247:22110](https://notes.mydomain.com/.client/client.js)
Activated plug emoji [client.js:2247:22110](https://notes.mydomain.com/.client/client.js)
Activated plug federation [client.js:2247:22110](https://notes.mydomain.com/.client/client.js)
Activated plug index [client.js:2247:22110](https://notes.mydomain.com/.client/client.js)
Activated plug markdown [client.js:2247:22110](https://notes.mydomain.com/.client/client.js)
Booting up worker for markdown [client.js:2247:17012](https://notes.mydomain.com/.client/client.js)
Activated plug plug-manager [client.js:2247:22110](https://notes.mydomain.com/.client/client.js)
Activated plug query [client.js:2247:22110](https://notes.mydomain.com/.client/client.js)
Activated plug search [client.js:2247:22110](https://notes.mydomain.com/.client/client.js)
Activated plug share [client.js:2247:22110](https://notes.mydomain.com/.client/client.js)
Activated plug sync [client.js:2247:22110](https://notes.mydomain.com/.client/client.js)
Activated plug tasks [client.js:2247:22110](https://notes.mydomain.com/.client/client.js)
Activated plug template [client.js:2247:22110](https://notes.mydomain.com/.client/client.js)
GET
https://notes.mydomain.com/_plug/markdown.plug.js
NS_ERROR_CORRUPTED_CONTENT

Booting SilverBullet client in Sync Mode [client.js:2547:1577](https://notes.mydomain.com/.client/client.js)
Service worker registered... [client.js:2547:1985](https://notes.mydomain.com/.client/client.js)
Index plug not loaded yet, falling back to default config [client.js:2544:366](https://notes.mydomain.com/.client/client.js)
Rebuilding editor state [client.js:2545:5610](https://notes.mydomain.com/.client/client.js)
XHRGET
https://notes.mydomain.com/.ping
[HTTP/1.1 401 Unauthorized 0ms]

Errore nella mappatura delle origini: Error: request failed with status 401
URL risorsa: https://notes.mydomain.com/.client/client.js
URL mappa delle origini: client.js.map

This is all i get in my NGINX logs (error log is empty) when i click on the popup button:

127.0.0.1 - - [26/Aug/2024:14:25:37 +0200] "GET /.ping HTTP/1.1" 401 375 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0" "-"
127.0.0.1 - - [26/Aug/2024:14:25:37 +0200] "GET /.client/client.js.map HTTP/1.1" 401 375 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0" "-"
127.0.0.1 - - [26/Aug/2024:14:25:37 +0200] "GET /service_worker.js HTTP/1.1" 401 375 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0" "-"

to complete the picture, here is my NGINX configuration for Silverbullet:

server {
        server_name notes.mydomain.com;
        listen 443 ssl;
        auth_pam "MyAuth";
        auth_pam_service_name "myPamServiceName";
        location / {
                client_max_body_size 512M;
                proxy_pass http://127.0.0.1:8001$uri;
        }
}

(only relevant parts, some lines omitted like Let's Encrypt lines and such)

(edit: edited to reflect new discoveries)

@zefhemel
Copy link
Collaborator

The question is: what should SilverBullet do when it starts to get 401s? The assumption is a redirect is in place to send the user to a login page, but if that's not there... what should it do?

@gardiol
Copy link
Author

gardiol commented Aug 26, 2024

I have no idea, usually any web page i use that require a login does get the login, when using the Proxy Auth, the browser automatically pops up the login form before even showing anything. For some reason, which i don't know, when the web page contains Silverbuller there is no login popup., whatever SB is doing, is preventing the browser from showing that popup.

@gardiol
Copy link
Author

gardiol commented Aug 26, 2024

Does Silverbullet support any kind of auth otherwise? I need auth because i host on a public subdomain, but i don't need to use Proxy Auth is there is another option.

@zefhemel
Copy link
Collaborator

@gardiol
Copy link
Author

gardiol commented Aug 26, 2024

Ok, better than being unable to use it, but still I hope the proxy auth can be fixed!

@ruibinx
Copy link
Contributor

ruibinx commented Aug 27, 2024

Does Silverbullet support any kind of auth otherwise? I need auth because i host on a public subdomain, but i don't need to use Proxy Auth is there is another option.

I'm setting up Silverbullet behind Cloudflare Access. It's easy to setup, and works as expected most of the time right now.

@gardiol
Copy link
Author

gardiol commented Aug 27, 2024

Sorry, not using cloudflare at all, and there is no reason to. Proxy Auth works fine for all services, except SB at the moment.

Would be possible to totally disable any managing of auth or 401 errors within SB and see if that fix it? Maybe with a command line option?

@gardiol
Copy link
Author

gardiol commented Aug 27, 2024

I think something is really broken with SB authentication. I have done some more experimenting trying to connect SB with my authelia instance.

If i login with authelia, then open the SB subdomain, SB will work just fine.

If i logout from authelia then try to open SB subdomain, the expected behaviour is that the browser opens the authelia login page ( login.mydomain.com) which, in turn, will redirect to SB subdomain (notes.mydomain.com). This is configured in the reverse proxy and just works for the other subdomains i am using it on.

Instead, the SB page will reload indefinitely saying it's offline and cannot access. This is an extract of the firefox console log:

error General sync error: Offline [client.js:18:6946](https://notes.mydomain.com/.client/client.js)
Sync error Offline [client.js:18:13480](https://notes.mydomain.com/.client/client.js)
Errore nella mappatura delle origini: Error: NetworkError when attempting to fetch resource.
URL risorsa: https://notes.mydomain.com/.client/client.js
URL mappa delle origini: client.js.map

Flushed widget cache to store [client.js:2547:1301](https://notes.mydomain.com/.client/client.js)
Syncing file index.md [client.js:18:13742](https://notes.mydomain.com/.client/client.js)
XHRGET
https://notes.mydomain.com/index.md
[HTTP/1.1 503  0ms]

Sync error Error: Offline
    authenticatedFetch https://notes.mydomain.com/.client/client.js:18
    getFileMeta https://notes.mydomain.com/.client/client.js:18
    getFileMeta https://notes.mydomain.com/.client/client.js:18
    syncFile https://notes.mydomain.com/.client/client.js:18
    init https://notes.mydomain.com/.client/client.js:2544
[client.js:18:14473](https://notes.mydomain.com/.client/client.js)
Syncing file index.md [client.js:18:13742](https://notes.mydomain.com/.client/client.js)
XHRGET
https://notes.mydomain.com/index.md
[HTTP/1.1 503  0ms]

There is also that CORS error (Errore nella mappatura delle origini), which baffles me because there is no reason for it at all to be there, everything is on the same domain.

And the last worrying bit is that i can see the content of the page even if i am not authenticated.

@zefhemel
Copy link
Collaborator

zefhemel commented Sep 9, 2024

Just pushed some more changes to try to address this. If you could try this on edge again that'd be great.

zefhemel added a commit that referenced this issue Sep 11, 2024
@zefhemel
Copy link
Collaborator

Had to revert the change. Broke other stuff.

@gardiol
Copy link
Author

gardiol commented Sep 12, 2024

For another stupid web page I have, I just added a JavaScript reload line on any ajax failed promise, and that works, but SB it's much more complex.

@josephembrey
Copy link

josephembrey commented Sep 22, 2024

Clearing the cache on the client browser fixes this. Following this, forcing a cache clear also fixes this:

http_space_primitives.ts

if (result.status === 401 || result.status === 403) {
    alert(
        "You are not authenticated, going to reload and try to clear the cache, hopefully that kicks off authentication"
    );
    try {
        const cacheNames = await caches.keys();
        await Promise.all(cacheNames.map((name) => caches.delete(name)));
    } catch (err) {
        console.error("Failed to clear cache:", err);
    }
    location.reload();
    throw new Error("Not authenticated, got 401");
}

But I have no idea if this is an appropriate thing to do here, or would have downstream consequences. Hope this helps though.

@zefhemel
Copy link
Collaborator

Right, I was thinking of solving it similarly not with caches but by unregistering the service worker when an auth problem happens. Doing that and reloading should also solve this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Backlog
Development

No branches or pull requests

5 participants