Repository navigation
Send login cookies from a browser extension - #15
Merged
Merged
Conversation
A Chrome extension (extension/) sends the cookies of Instagram and Facebook to Sharewerk after a login there, only for the account confirmed once in its menu, with the browser's login at Sharewerk. The server keeps them per platform in the data volume (PUT, GET and DELETE /api/cookies), each download gets only the cookies of its own platform, and /healthz adds cookie_states per platform. The release workflow builds the extension zip with checksum and build provenance.
CodeQL read the substring checks for a domain as URL sanitization.
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.
Summary
Sharewerk needed the cookies of a logged-in account as a file put on the server by hand, and every download got the whole file. Now a Chrome extension sends them whenever you log in, per platform.
Server
app/cookies.py: the platforms with their login cookies (Instagramsessionid, Facebookc_userandxs). Sent cookies are kept in/data/cookies/<platform>.txt(mode 600, folder 700, written atomically).PUT /api/cookies/<platform>takes the cookies aschrome.cookiesreturns them. It refuses cookies of another domain (cookie_domain), a set without the login cookies (cookie_session_missing), fields with anything but printable ASCII or longer than 4 KB, expiry dates that are not a finite time up to the year 9999, JSON it cannot read (cookies_invalid), more than 100 cookies and bodies over 512 KB. It needs the app's login (or the proxy's) and the headerX-Sharewerk-Client: extension, which a web page cannot send to another site without a CORS preflight. Cookie values never reach a log or an answer.GET /api/cookies(state, source and time per platform) andDELETE /api/cookies/<platform>.SHAREWERK_COOKIES_FILE. Before, a Facebook download got the Instagram cookies too./healthzaddscookie_statesper platform.cookiesstays the Instagram state, so monitors on"cookies":"expired"keep working.missingnow also covers a cookie file without cookies of that platform; a cookie file that exists but cannot be read is logged once (without its content).unknowninstead of being markedexpiredby a job that still had the old ones.Extension (
extension/, Chrome, Manifest V3)ds_user_id); a login without an account ID is never confirmed or sent, and a click confirms only the account the menu showed.cookies,storage,alarms, the hosts instagram.com and facebook.com. The Sharewerk address is an optional host permission, granted on the settings page. No content scripts, no remote code.app/static/azentrius/,theme.jsandicons.jsunchanged. Texts in English and German. The icons come fromscripts/app-icon-sharewerk.py(new sizes 16 to 128).tools/build-extension.pybuildsdist/sharewerk-extension-VERSION/and a reproducible zip, with the version ofapp/__init__.py. The release workflow attaches the zip with its checksum and build provenance, and now also runs the JavaScript tests.Docs: README sections "Browser extension (Chrome)" and "Cookie file by hand", health check, security notes and troubleshooting; NOTICE.
Test
tests/test_cookie_upload.py(36): upload, host-only and session cookies, foreign and lookalike domains, missing login cookies, fields that could break the file (also U+2028 and U+0085), infinite, huge or negative expiry dates and deeply nested JSON (422, not 500), malformed requests, missing header, token login, no values in answers or logs, delete, unwritable volume, cookies per platform for downloads, state per platform, cookies that arrive while a job runs, an unreadable cookie file.tests/test_extension_build.py(5): version, unchanged copies, every referenced file present, reproducible zip.tests/js/extension.test.mjs(21): the sending logic against a fake chrome API (confirmation of the shown account only, a login without account ID, the account from the session cookie, no second send of the same login, another account, a new address and lost cookies, missing Sharewerk login, errors, offline, no address or permission, delete), address validation, texts in both languages, manifest permissions, platforms in step with the server.cookie_statesand for cookie files with (fake) cookie lines.git diff --checkclean, gitleaks hook passed.