PRINTDECKDOCS

Architecture · Chapter 4

Why it is secure

Each row names one threat, the control that stops it, and the place in the code. Section 4.2 gives the limits.

4.1 The controls

ThreatControlWhere
A phishing site gets a sign-inA passkey works only for the RP ID printdeck.beetlebug.org. The browser puts the true origin in the signed client data. The API refuses another origin. A site at another domain cannot get a valid assertion.auth.go webAuthn(): RPID, RPOrigins
A leak of the stored credentialsThe bucket keeps public keys of passkeys and decks. It keeps no password, no email address and no private key of a person or a deck. A public key cannot sign in.Passkey, Deck
A guessed or reused codeEnrollment codes work for 1 hour, owner codes for 10 minutes, invites for 7 days. Each works once: the API deletes it at use. Codes have about 59 bits, invites 128 bits.useCode, join, joinWith, CodeTTL, OwnerCodeTTL, InviteTTL
A read of the code filesThe bucket keeps only the SHA-256 of each code and invite, as the name of its file. Lifecycle rules delete codes/ after 1 day and invites/ after 8 days as a second guard.codeKey, inviteHash, template.yaml
A changed ceremony stateThe state has an HMAC with the purpose "ceremony", an expiry of 5 minutes, and the purpose of the flow. The state of an invite has the hash of its code.sealCeremony, openCeremony
A forged sessionThe token has an HMAC with the purpose "session" and a key that only the API reads. A ceremony state does not open as a session.seal, open, session
A long-lived sessionA session works for 14 days. The page keeps it in localStorage, so it stays after the tab closes. Sign out and a 401 remove it. A member session fails at once on a project when the owner removes the member from it.SessionTTL, whoFor, sessionSet
Cross-site requestsThe token goes in the Authorization header. The API reads no cookies, so a form on another site sends no session. The file cookies open only the files of one project under /x/, and they are HttpOnly and SameSite=Lax.session, app.go, filecookie.go
A copied authenticatorThe API stores the signature counter after each sign-in. The library marks a clone warning when the counter does not go up.login/finish
A member reads too muchA member session has the projects of the passkey. For each request on a project, the API finds the member in that project and checks that the project still has the member. Owner actions need an owner. A member removes only their own photos.whoFor, lookupName, ownerOnly, deletePhoto
Script injection on the pagesThe CSP allows scripts only from the site and WebAssembly. Pages cannot be framed. The headers add HSTS (1 year), nosniff, DENY frames and no referrer.template.yaml Headers
A large or wrong uploadGrants limit the key prefix, the size and the time. The API body limit is 64 KB. Photos are decoded and written again with no metadata: no EXIF, no GPS position and no comment. A test checks it.S3Granter.Grant, maxBody, CleanPhoto, TestCleanPhotoStripsMetadata
A forged deck requestEach request has an Ed25519 signature of the method, path, time, request ID and body hash. The time must be within 5 minutes.cloud.Verify, Server.deck
A guessed addressShare and project IDs have 13 random bytes. A missing share or file shows the same "not found" page.newID, CustomErrorResponses
A person reads the files of another projectCloudFront serves /x/* only with a valid signed cookie. The policy of a cookie names one project, and the cookie path is that project. The API signs cookies only for projects that the session can see. The files have the same origin as the pages, so reads need no CORS, and CloudFront can keep them in its edge cache.filecookie.go, template.yaml /x/*
A forged token of an ActionThe API checks the RS256 signature with the keys of GitHub (JWKS), the issuer https://token.actions.githubusercontent.com, the audience (the host name of the service) and the expiry, with 1 minute of leeway. The token must have the claim repository.GitHubOIDC.Verify, buildClaims
A token used twiceThe API writes oidc/<sha256> of the jti with a conditional write. A second use gets 401. The Action asks for a new token for each request.useToken, tokenKey, template.yaml oidc-tokens
A repository writes to another projectThe repository of the token selects the project through repos/<owner>/<name>.json, and the project must still name it. Only the owner sets the link. A plan or a build of another repository gets 403.projectOfRepo, setRepo, actionBuild, planDone
A changed workflow fills a buildEach request on /api/v1/builds/ needs job_workflow_ref of .github/workflows/printdeck.yml on main or master. A copy on a branch or in a pull request gets 403. It can only send a plan.sliceRun, SliceWorkflow
A fork sends a planThe token of a fork names the fork. The owner of the fork must be a member who joined, with the GitHub username that the owner set. This check needs no call to GitHub. Then the App must find an open pull request into the repository of the project, from that branch, with the commit of the token as its head. A fork never fills a build.forkProject, OpenPull, planDone
A profile runs code in the slice runcuraslice.py parses each formula of a profile, and checks each node of its syntax tree against a list. A formula can use only constants, names, operators, the functions of Cura and math, and index or count on a list of constants. A name or a string with __ fails. The formula then runs with no built-ins.check_formula, safe_attribute
A large upload of the ActionThe grant of a plan or a build has one folder, 200 MB for each file, and 1 hour. Done checks that each named file is in the folder. Each file of a build has its size and SHA-256 in the record.MaxBuildFile, newPlan, buildFiles, buildDone
A member slices or approvesOnly the owner makes a build, and approves or rejects a plate. A member sees the plans and the builds with no keys.newBuild, decidePlate, ownerOnly
A leak of the token of the AppEach installation token works for one repository, with only the permissions of its call: Actions (write) to start a slice run, Pull requests (read) to find a pull request or read its state, or Pull requests (write) to write the comment of Printdeck. Each also has Metadata (read). The App JWT ends after 9 minutes. The private key is in Secrets Manager.installationToken, Dispatch, OpenPull, PullState, Comment
A bad link to a sourceThe source of a print must be an http or https address with a host, of at most 500 characters. Only the owner sets it.editPrint
A public bucketThe bucket blocks public access and encrypts at rest. CloudFront reads only the listed keys with OAC. It reads the print files, the photo pictures, the live pictures, the plan models and the build files under x/ only when the stack has the key of the file cookies, and never the JSON records. It also reads gh/, the public pictures of the comments on pull requests. The function has get, put, delete and list on this bucket only. It can also invoke itself, for the jobs after a request.template.yaml
The app or the queue starts a resin printThe API of the resin deck refuses uploads, each start and each resume with 409. Its printer for the API does nothing on PrintFile and Resume. A start from ChiTuBox during a print goes to the queue, and with files in the queue the deck asks on its screen. Only a press on the touch screen sends M6030 or a resume.octoapi.Server.Resin, resinAPIPrinter, ChiTu.RequestStart
A project sees another project's printsThe service keeps the queued files of each project in the project (x/<project>/queue/). The state of each printer (printers/<id>-live.json) goes only to GET printers, which only the owner and the decks get.setQueue, projectQueued, routePrinters
A changed file of a plateThe deck checks the size and the SHA-256 of a plate file against the build record before it adds the file to its queue.downloadTo
A deck writes for another deckThe queue, the removals from the queue, the state and the plates of a printer need a request of the deck of that printer.deckPrinter, setQueue, queueRemoves, removesDone
A changed update fileA deck installs only a bundle with an Ed25519 signature of SHA256SUMS by the release key. The debug image also accepts an unsigned bundle.deck/internal/system/sign.go

The CSP of the pages

default-src 'self'; script-src 'self' 'wasm-unsafe-eval'; style-src 'self' https://fonts.googleapis.com; font-src https://fonts.gstatic.com; img-src 'self' data: blob: https://<bucket>; connect-src 'self' https://<bucket>; frame-ancestors 'none'; base-uri 'none'; form-action 'self'

The pages have no inline scripts. wasm-unsafe-eval lets the page compile its own WebAssembly. connect-src allows the bucket, for the upload grants, and for the signed S3 links of a stack with no cookie key. The files of the projects come from 'self'.

4.2 The limits

These limits come from the code as it is. Each one has a reason or a way to act.

  • A stolen session token works until it expires. The API keeps no list of sessions. A token works for up to 14 days. The browser keeps it in localStorage after the tab closes, so a person who can use that browser profile can use the session. Sign out clears the token only on the page. To end all sessions, replace keys/session. A running instance of the function keeps the old key in memory until it stops.
  • The device of the owner holds the owner passkey. A person who can unlock that device, or the account that syncs its passkeys, can sign in as the owner. User verification is "preferred", so an authenticator with no PIN or biometric can also sign in.
  • An owner passkey has no remove action in the API. To remove one, the operator deletes its file in owners/.
  • A deck holds owner rights. A signed deck request has the rights of the owner in the project API. A deck can also ask for an owner code. A person with the SD card of a deck has its key. A person who can use the touch screen, or the remote screen of the deck, can make an owner code. Use pwf decks remove after the loss of a card.
  • The counter is a signal. The API stores the counter and the clone warning of the library, but it does not refuse a sign-in with the warning. Synced passkeys often report a counter of 0, and then the check does not apply.
  • A ceremony state can be sent again. The API keeps no list of used challenges. The same state and assertion can give a second session within the 5 minutes of the state. TLS protects both.
  • The replay check of deck requests is partial. Each function instance keeps its own list of request IDs. The signature, the 5-minute window and TLS remain.
  • Links are bearer secrets. A person with a share link sees the print until the share ends. A person with an invite link can join in place of the friend, until somebody uses it or it expires. A person with an invite link and their own member passkey can join with that passkey. The owner can remove a member that joined in that way.
  • A member passkey opens all its projects. A person who can unlock the device of a friend sees each project that the friend joined. To end that access, the owner removes the member from each project.
  • The AWS credentials of the owner are above all other keys. pwf uses them on the computer of the owner. A person with them can make enrollment codes, read keys/session and change the stack. Keep that computer and its AWS profile safe.
  • A file cookie works for up to one hour. A member that the owner removes keeps the cookies of the project until they expire. The API refuses the member at once, but CloudFront checks only the signature and the time.
  • Fixed: a file cookie opened the JSON records. Before commit 71fae88, the bucket policy let CloudFront read all of x/*. A member with the cookie of a project could read project.json, with the names of the open invites and the SHA-256 of their codes. Now CloudFront reads only the print files, the photo pictures, the live pictures, the plan files and the build files. The JSON records stay with the API.
  • The key of the file cookies is in Secrets Manager. The role of the function and the AWS credentials of the owner can read it. A person with it can sign cookies for any project.
  • Share links are public. Section 2.5 explains this choice and its protections.
  • The bucket is the root of trust. keys/session is in the bucket. A person who can read the bucket can make session tokens. Only the operator and the function have access.
  • The function URL has no AWS auth. A request can go to the Lambda URL past CloudFront. The API checks the auth of each request in the same way. The CloudFront headers do not apply there, and the API replies only JSON.
  • The remote screen of a deck uses plain HTTP. Its password protects it on the home network only.
  • A deck holds owner rights for the builds too. A signed deck request can link a repository, slice a plan, and approve or reject a plate.
  • The slice run reads the files of the plan commit. A plan can come from the head commit of a pull request, also from a fork. The slice run checks out that commit and reads its printdeck.yml and profiles/. Each formula of a profile passes the check of its syntax tree (section 4.1), and then runs with Python eval and no built-ins. The check is a list of the parts of Python that Cura uses. It is not a sandbox of the process. Look at the changes to profiles/ before a slice of a pull request.
  • The comments on pull requests make pictures public. The comment of Printdeck shows the changes of the models, the plates and the first photo of each print of a plate. The service copies these pictures to gh/ in the bucket, with names of 16 random bytes, and anybody can read them. The comment also has the links to the plan and the build pages. On a public repository, anybody can see the comment.
  • The models of a fork come from the run of the fork. The generate step of a fork runs in the fork, so its STL files are not proof of the CAD source. Look at each part in the 3D view of the plan page, and at each plate in the preview of the build page, before an approval.
  • A member's GitHub username is the key of a fork. The owner types it. A wrong username lets that GitHub user send the plans of their open pull requests. Check each username.
  • A slice token works for each build of its repository. The API checks the repository of a build only. The spec also asks for a check of the commit.
  • The workflow rule names main and master. sliceRun accepts only these two branches. The App starts the workflow on the default branch of the repository. A repository with another default branch gets 403 on each request of its slice run.
  • Each workflow of the repository can send a plan. A copy of the workflow on any branch, with id-token: write, can send a plan. The plan page shows its parts and models to the owner and the members. A fork can send a plan only for an open pull request of a member.
  • The slice run needs the GitHub App. When the stack has no secret <stack>-github-app, the service cannot start a slice run. The build page then shows the owner a gh workflow run command to run by hand.
  • The estimates of the queue are rough. A start time is the time left of the print now, the print times of the slicer of the files before it, and 10 minutes for each change of a part.
  • The Apple team ID is public. The association file of the app and each signed app have it. It is not a key.
  • Plans and builds have no expiry. They stay until the owner deletes the project. The spec gives 30 days for test builds and 1 GB for a build, and the code has neither.

Back: 3 Passkey flowsContentsNext: 5 The data of a print