feat(notifications): handle feedback.submitted from Room TBA - #8
Open
smmariquit wants to merge 2 commits into
Open
feat(notifications): handle feedback.submitted from Room TBA#8smmariquit wants to merge 2 commits into
smmariquit wants to merge 2 commits into
Conversation
Room TBA emits `feedback.submitted` from its in-app feedback box (uplbtools/room-tba#888). The envelope enum did not list the type, so the gateway answered 400 and the submission only reached the server log. - Add `feedbackSubmittedPayloadSchema` matching the emit site exactly: feedbackId, message, contact, screen, appVersion, wasOnline. - Post to #development: message body, contact when given, and the context Room TBA attaches. The handler parses the payload rather than casting it, since `/api/feedback` is public and unauthenticated. - Render untrusted text through `safeUserText`: markdown and masked links escaped, every `@` broken with a zero-width space so no submission can ping @everyone/@here/a role, and truncation with an ellipsis instead of letting Discord reject the message. Raw text is cut before escaping because `escapeMarkdown` is quadratic (22k chars is ~7s of blocked event loop). - Deny mentions on every Discord send, not just this path. Closes #7
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.
Closes #7.
Room TBA's in-app feedback box (uplbtools/room-tba#888) emits
feedback.submittedthrough the existing notification gateway. The envelope enum did not list the type, so/notificationsanswered 400 and the submission only ever reached the server log. Nothing was lost — thefeedbacktable in Room TBA is the system of record — but nobody was told a student wrote in.Payload
Matched to the emit site on
origin/feat/in-app-feedback(src/lib/notifications/types.ts,src/pages/api/feedback.ts), no invented fields:feedbackIdmessagecontactscreenappVersionwasOnlineRoutes to
#developmentrather than#contributors:#contributorsis documented as map edit proposals, and a submission can carry a contact address. Easy to move if the team wants it elsewhere.Rendering untrusted text
/api/feedbackis public and unauthenticated, so the body is attacker-controlled. Room TBA validates and rate limits; this PR only renders safely.feedbackSubmittedPayloadSchema.parse, unlike the proposal handlers which cast.[totally the admin panel](https://evil.example)into the channel.@—@everyone,@here,<@&role>all stop resolving while the text stays readable. Belt and braces:allowedMentions: { parse: [] }now applies to every Discord send in this bot, not just this path.escapeMarkdownis quadratic: 22k chars measured at ~7s of blocked event loop (20s for plain text). Bounding the input at Room TBA's own 2000-char cap keeps it at ~55ms. There is a test asserting this stays under 1s.Short context values (screen, app version) take a lighter path: whitespace is collapsed so no line start remains for heading/list markdown, which also avoids rendering an app version as
2026\.08.01.Verification
bun run check— biome,tsc --noEmit,bun test,tscbuild. 65 pass, 0 fail. The one biome warning (github-repo.tsoptional chain) is pre-existing and untouched.New tests cover: schema accepts the real payload and both null-context and malformed variants, mention text is neutralised, over-long bodies truncate rather than throw, the quadratic path stays fast, and
POST /notificationsnow accepts afeedback.submittedenvelope end to end.Not merged, not deployed — Heroku still needs
git push heroku mainafter merge.