Repository navigation
Fix OctoPrint login loop in the Device tab when an API key is set (#1088) - #1218
Open
alandebortolo wants to merge 1 commit into
Open
alandebortolo wants to merge 1 commit into
alandebortolo wants to merge 1 commit into
Conversation
The API key hook adds X-API-Key to every fetch/XHR of the printer page, including POST /api/login. OctoPrint does not store a session for a request authenticated by API key, so the login succeeds but no session is kept and the next navigation lands on the login page again (Snapmaker#1088).
3 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1088.
What happens
For every non-SimplyPrint host that has an API key set,
Plater.cpppasses the key to the Device tab, andPrinterWebView::SendAPIKey()wrapsfetchandXMLHttpRequestso that every request of the printer page carriesX-API-Key. That includes OctoPrint's ownPOST /api/login.OctoPrint treats a request that arrives with a valid API key as already authenticated by key, and it does not keep a browser session for it. The login call returns 200, the page navigates to
/?, that navigation has no header and no session, and OctoPrint redirects back to/login/?redirect=/?&permissions=STATUS,SETTINGS_READ. This is the loop in the issue. Without an API key in the printer settings the login works, which is why not everybody sees it.Change
The hook leaves
X-API-Keyoff requests to/api/login(fetch and XHR). Everything else still gets the header. 5 lines added, 2 changed, one file.Tested
I did not build the app. I took the hook script out of
PrinterWebView.cppas it is onmainand as it is in this branch, and ran each one in a standaloneWKWebViewthat does what the macOS path does (evaluate the script after each finished load, no user script), against fresh local OctoPrint installs with a real user and a real user API key. The harness types the credentials into the login form and clicks Log in.mainIn all six runs a request to
/api/versionmade from the login page before logging in (no session yet) returned 200 through both XHR and fetch, so the header is still added to the other requests. With no API key configured, login worked on all three versions before the change.Raw output
Not tested
AddUserScript. The script is identical, but I only ran the macOS-style injection./api/loginis OctoPrint's; I did not check whether another supported host uses the same path and expects the key there.