Skip to content

Support individual mode, multi-line connection info, and stale tokens - #1

Open
SenequeZ wants to merge 1 commit into
28Pollux28:masterfrom
SenequeZ:unitedctf-fixes
Open

SenequeZ wants to merge 1 commit into
28Pollux28:masterfrom
SenequeZ:unitedctf-fixes

Conversation

@SenequeZ

@SenequeZ SenequeZ commented Nov 9, 2026

Copy link
Copy Markdown

Summary

This PR adds the fixes we made to Zync while running it with Galvanize for UnitedCTF. CTFd ran in individual mode (no teams). These changes ran in production during the event.

Companion Galvanize PR: 28Pollux28/galvanize#7

🐛 Fixes

# Symptom Cause Fix
1 In individual mode, deploy, status, extend and terminate all fail, because Galvanize can't tell whose instance it is POST /api/v1/deploy/token signs "team_id": null when the player has no team. Galvanize keys every per-player deployment by team_id. api/deploy.py: team_id falls back to str(user.id) when there is no team. Team mode is unchanged.
2 When an instance has several published ports, connection info shows as one run-together code block, or as one broken link when the first entry is an HTTP URL Galvanize returns one entry per line, joined with \n. view.js only checked whether the whole string started with http and wrapped all of it in a single <a> or <code>. Each non-empty line is rendered separately: lines starting with http become links, the rest become <code>. Lines are joined with <br>.
3 After an admin changes a challenge's category, players get 400 "Invalid challenge" until they clear session storage The JWT, which embeds category, was cached in sessionStorage under jwt_<challengeId> and reused until it expired. It kept the old category. The token is now cached under jwt_<challengeId>_<category>, and ensureToken also fetches a new one when the cached token's category doesn't match the challenge's current one. Decoding the token payload is wrapped in try/catch.
4 The modal spins forever, or a JS error is thrown, when /status returns a 404 with a JSON body The 404 handler only reset the deploy button when the response was not JSON. When it was JSON, it read data404.message.includes(...). That throws if there is no message, and if the message didn't mention "unique" the button was never reset. The deploy button is now hidden only for the "unique" message. Every other 404, JSON or not, resets the button. res.json() failures are caught.

Notes

  • No API or config changes. Team-mode CTFs behave the same, apart from fixes 2–4.
  • Fix 2 also helps with stock Galvanize: it already returns several tcp:///ssh:// lines for instances that only publish ports.

Test plan

  • Ran in production at UnitedCTF (CTFd 3.7.7, core-beta theme, individual mode).
  • node --check assets/view.js and python -m py_compile api/deploy.py
  • Team mode: deploy, extend and terminate still key on team.id

- deploy token: fall back to the user id for team_id when the player
  has no team (CTFd individual mode). Galvanize keys per-player
  deployments by team_id, so null broke deploy/status/extend/terminate.
- view: render connection_info one entry per line, each URL its own
  link. Galvanize joins several published ports with "\n"; they were
  shown as one code block, or as one broken link when the first entry
  was an HTTP URL.
- view: store the JWT per challenge id + category and fetch a new one
  when the cached token's category no longer matches the challenge,
  instead of failing with 400 "Invalid challenge" after a category edit.
- view: on a 404 from /status, reset the deploy button unless the
  message says the challenge is unique. A 404 JSON body without
  "unique" (or without a message) left the modal spinning or threw.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant