Repository navigation
fix(security): restrict translation tooling to contributors and admins - #2019
Merged
Merged
Conversation
The REST translation routes (uploads, start/retry, jobs, text-to-speech, proofread copies, PNG generation, editor downloads, PNG viewer) only required a session, so any student could delete and replace a course's source files, start paid translations or generate audio with a professor's voice. Upload and job routes now require the admin role, the slide editing routes the contributor role (createExpressRoleMiddleware: 401 without session, 403 when the role is not enough). The translated PNG viewer turned the client-supplied ppt_resource_path into an S3 key, so any object of the bucket could be read. The key builders now refuse anything but contribute/.../pptx/<name>.pptx.
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.
Vulnerability
Translation tooling open to every account. The REST routes of the translation tool were guarded by
expressAuthMiddlewareonly, which checks that a session exists. Any student account could:POST /api/upload-translation-files,/start-translation/:uploadId,/retry-translation/:courseId: delete the source files of a course undercontribute/<courseId>/…, replace them, and start paid ConvertAPI / Language Toolkit jobs;POST /api/translation-audio/generate: generate text-to-speech audio of any text with a professor's voice, stored in S3;The matching tRPC procedures already use
contributorProcedure/adminProcedure, and the academy's translation panel is admin-only.Arbitrary S3 read through the PNG viewer.
GET /api/png-viewer/translated/…/:fileName/:slideNumbertakesfileNameas the slide'sppt_resource_path, URL-decoded, and builds the S3 key with tworeplacecalls. A value without/pptx/and.pptxcame out unchanged, so any key of the bucket (CVs, submitted assignments, certificates…) was streamed to the caller.Fix
createExpressRoleMiddleware(role)inapps/api/src/middlewares/auth.ts, built oncanAccesslike the tRPC procedures:401without a session,403when the role is not enough. NewForbiddenerror.translation-uploads.ts).translation-audio/*, the editor routes oftranslation-downloads.tsthat required a session (pptx-forcesave,pptx-create-proofread-copy,generate-png,pptx-token,audio/…,pptx/…,pptx-callback-token) and the fourpng-viewerroutes. Routes fetched by the OnlyOffice server, which has no session, are unchanged.buildTranslatedPngKey/buildTranslatedProofreadPngKeyrefuse (400) any path that is notcontribute/…/pptx/<name>.pptxwith no empty,.or..segment.Tests
apps/apigets a mocha setup likesharedandservice-user.apps/api/src/routers/rest/translation-access.test.ts(express on127.0.0.1:0, fake database/S3, outboundfetchrecorded). Ondevevery one fails, with the status shown; here all pass:refuses translation uploads from a student(202 == 403)refuses translation retries from a contributor(202 == 403)refuses text-to-speech generation from a student(200 == 403)refuses proofread copies from a student(400 == 403)refuses the PNG viewer to a student(404 == 403)does not let the translated PNG viewer read objects outside slides(cvs/profile-1was read)apps/api/src/utils/png-path.test.ts:refuse paths that are not slide presentations: fails ondev(Missing expected exception: cvs/1234), passes here;build the keys of slide PNGs: passes on both.translation-callback.test.tsfrom fix(security): authenticate the OnlyOffice save callback #2016 now runs with a contributor session and still passes.turbo run type-check --filter=@blms/apipasses andbiome checkis clean on the changed files.Behaviour changes and deploy notes
403. Check the roles of active translators before deploying.createCheckUserTranslationAssignment) on each route is a follow-up.