fix: require auth for templates API routes - #486
Merged
Conversation
The /api/templates routes sit outside the /ycode tree and were not covered by the middleware auth gate, leaving destructive builder-only operations (apply, export) reachable without authentication. An unauthenticated request to apply a template could wipe and replace site content, an effective denial-of-service. Gate the whole /api/templates prefix in middleware.
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
The
/api/templatesroutes sit outside the/ycodetree, so the middleware auth gate never covered them. This left destructive, builder-only operations reachable without any authentication — most notablyPOST /api/templates/:id/apply, which clears the current site content and replaces it with a template. An unauthenticated attacker could repeatedly apply a template to keep a site in a reset state, an effective denial-of-service (and defacement) against published sites.Changes
/api/templatesprefix in the middleware auth check, alongside the existing/ycode/apiand/ycode/previewprotection.Test plan
GET /api/templatesreturns401POST /api/templates/:id/applyreturns401and does not modify contentPOST /api/templates/exportandPOST /api/templates/export-and-uploadreturn401