fix: tighten rename and node routing request validation#349
Merged
Conversation
Drop double PathUnescape on rename src; reject unknown :node via NodeGuard. Co-authored-by: Cursor <cursoragent@cursor.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
posix.Renamesrc path: drop the redundanturl.PathUnescapeonsrcName. Hertz already percent-decodes the URL path once; runningnet/url's strict decoder a second time rejects legitimate filenames containing%(e.g. renaming12%3.zipfailed withinvalid URL escape "%3."). The query-sidedstNamedecode is left intact since the existing front-end → back-end contract relies on it.:noderoute segment: introduce a singlebizhandler.NodeGuard()middleware (one shared helper inpkg/hertz/biz/handler/utils.go) and wire it into every:nodeplaceholder inarchive,paste,task,external,videos, anduploadroutes. Requests whose:nodeis neither the localNODE_NAMEnor a node ever seen in the cluster are rejected with400 invalid node. Previously any string was accepted (e.g./api/archive/sdsdsd/entrieswould happily run).Notes
global.GlobalNode.Nodesis an additive set (only-grows, never shrinks within a process), so any node that has ever been listed by the cluster — including the local node and previously-seen peers — continues to pass. There is no impact on legitimate single-node or multi-node traffic.global.CurrentNodeName/GetMasterNode(), both of which satisfy the guard.Test plan
%(e.g.12%3.zip→123.zip) and back; both succeed.%; succeeds (existing query-side path unchanged).GET /api/archive/<NODE_NAME>/entries?source=…→ works as before.GET /api/archive/sdsdsd/entries?source=…→400 {"error":"invalid node"}.--nodeset to a real node name → unchanged behaviour for compress / extract / paste / task / mount / smb_history / videos / upload.--nodeset to an arbitrary string →400 invalid node.Made with Cursor