feat(api): /chat Slack workspace redirect (closes #79)#100
Merged
Conversation
/chat is spec'd in specs/screens/chat.md as a 302 to the Code for Philly Slack workspace, with optional ?channel=foo deep-linking. The route doesn't exist today — every "Open Slack" link across the SPA falls through to the SPA catch-all. Plan covers route, channel validation (reusing Project.chatChannel regex for open-redirect safety), tests. Closes #79. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
GET /chat 302s to https://<SLACK_TEAM_HOST>/ and
GET /chat?channel=<name> 302s to /channels/<name>. Empty or
malformed channels fall back to the workspace root with a warn log
(per spec: degrade quietly rather than 4xx). Cache-Control: no-cache
so the destination can flip without browser caches sticking; 302 (not
301) for the same reason.
Channel validation reuses the Project.chatChannel regex
(/^[a-z0-9][a-z0-9_-]{0,40}$/) — same shape the data already enforces,
and tight enough that the channel can't smuggle a slash, protocol, or
relative-path traversal into the redirect URL. The hardcoded host comes
from fastify.config.SLACK_TEAM_HOST, never the request.
Per specs/screens/chat.md.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
All validation checkboxes ticked. Notes covers the channel-regex hoist trade-off (duplicate literal rather than Zod-internals plumbing), the Fastify querystring typing pattern, and the /api/chat 404 assertion. Follow-ups: typeahead is None (no real ask); per-channel analytics deferred to next observability pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
GET /chat302s tohttps://<SLACK_TEAM_HOST>/GET /chat?channel=<name>302s to/channels/<name>when name matches/^[a-z0-9][a-z0-9_-]{0,40}$/(same regex asProject.chatChannel— protects against open-redirect / path injection)warnlog; no 4xx per spec ("degrade quietly")Cache-Control: no-cache+ 302 (not 301) so the destination can flip later without browser caches stickingCloses #79. Implements specs/screens/chat.md.
Test plan
apps/api/tests/chat-redirect.test.ts— no-channel, valid channel, hyphens/underscores OK, empty channel → root, uppercase → root, slash-injection → root, over-long → root, leading-hyphen → root,/api/chat404snpm run type-check && npm run lintclean🤖 Generated with Claude Code