Repository navigation
[fix][core] Refuse internal plugin events requested as URL paths - #8293
Merged
Merged
Conversation
requestProcessor dispatches unknown request paths to plugins by name. Plugin events that core or plugins fire themselves, with their own data, could be requested as URL paths (no credentials needed): /i/device_id, /i/user_merge, /o/method/total_users, /i/event/delete, /i/events and /o/validate under /i and /o, and every event outside them (/master, /sdk/user_properties, /session/begin, /systemlogs, ...) where the API port is reachable directly. Their hooks ran without that data, threw or returned a value, the dispatch counted as handled, and the request was never answered, each hook logging an unhandled rejection. All 18 request-path dispatches in requestProcessor now go through dispatchRequestPath, which refuses names outside /i and /o (request routes live only there) and the internal events listed in INTERNAL_EVENTS, so these requests answer 400 Invalid path without running any hook. Core's own dispatches of these events are unchanged, and no plugin changes. Adds test/2.api/25.internal.event.paths.js: each listed path and /sdk/user_properties, bare and with request parameters, answers 400 Invalid path, and the locale plugin's /o/langmap route still answers through the same fall-through dispatch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The /i/events route answered unknown sub-paths with "must be one of /all or /me", copied from another route. It now names its own sub-paths: change_visibility, delete_events, edit_map and whitelist_segments. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The tests request through the proxy, which sends only /i and /o to the API, so /sdk/user_properties is answered 404 by the frontend before it reaches the API (core CI: expected 400, got 404). requestProcessor's refusal of names outside /i and /o protects API ports exposed without the proxy; it is checked by a local run against the API port, not by these tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
davidecavaliere
approved these changes
Nov 25, 2026
davidecavaliere
added a commit
that referenced
this pull request
Nov 25, 2026
Co-Authored-By: Claude Opus 5.5 <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.
What was wrong
requestProcessordispatches a request path it does not know to plugins by name: the fall-throughdefault:dispatches the first two path segments (apiPath), then the full path (added in 7653890, 2016), and each route's owndefault:dispatches itsapiPath.Plugin events that core or plugins fire themselves, with their own data instead of a request, can be named like request paths. A literal request to one (no credentials needed) ran their hooks without that data. Six are named under
/iand/o, so they are reachable through the default nginx config:/i/device_idapi/parts/mgmt/app_users.js(2015, be53656)oldUser,newUser/i/user_mergeapi/parts/mgmt/app_users.js,api/jobs/userMerge.js(2017, 5240e7a)oldAppUser,newAppUser/o/method/total_usersapi/parts/data/fetch.js(2016, 99aa459)shortcodesForMetrics/i/event/deleteapi/utils/requestProcessor.js, when events are deletedappId,event_key/i/eventsapi/parts/data/events.js, for each incoming eventparams,currEvent/o/validateapi/utils/rights.js, after an app is validatedparams,appEvery other event (
/master,/worker,/sdk/user_properties,/session/begin,/systemlogs, …) was reachable the same way wherever the API port is exposed directly./master, for example, runs the content plugin's job scheduling.The hooks threw (
Cannot read properties of undefined (reading 'uid'),'vc','chr', …) or returned a value.pluginManager.dispatchcounts a rejected promise or any returned value as "handled", so the400 Invalid pathfallback never ran and the request was never answered. Every hook logged an unhandled rejection. Servers have logged these errors, for example fromviews,crashes,compliance-hub,star-rating,drill,surveys,cohorts,retention_segments,revenue,content,browser,localeandsources. For the six above, no hook wrote data: each one throws, or returns, before any database call.None of these were meant to be endpoints: no dashboard, SDK or test code requests these paths, and the SDK changes device IDs through
/i?device_id=…&old_device_id=….What the code now does
All 18 request-path dispatches in
requestProcessorgo throughdispatchRequestPath(). It refuses:/iand/o, where no request route lives;INTERNAL_EVENTSwith where core fires each one.Anything else goes to
plugins.dispatch()as before.A refused request gets the existing
400 Invalid pathanswer without running any hook.Core's own dispatches of these events are unchanged, and no plugin changes.
Separate commit: the
/i/eventsroute answered unknown sub-paths withmust be one of /all or /me, copied from/o/users. It now names its own sub-paths (/change_visibility, /delete_events, /edit_map or /whitelist_segments). The/o/usersmessage and its tests are unchanged.Why nothing legitimate is refused
/iand/o: every registered event name outside/iand/o(70) is either fired by code by name, or reads its data from the event object rather than from a request (/journey/updateData,/journey-engine/updatestats,/cohorts/enteris commented out). So none of them answers an HTTP request today./iand/o: of 215 registered names a request can reach, only these six are fired by core with their own data. The rest are plugin routes, some also re-fired with a full request object (/i/crash_symbols,/i/crashes-jira,/o/feedback/*,/i/sdk,/o/sdk)./i/apps/*,/i/app_users/*,/i/users/*, …): these were never reachable, because those routes' defaults dispatch only the two-segment name./i/remote-config, which remote-config's own endpoint claims first.A new internal event named under
/ior/ohas to be added toINTERNAL_EVENTS.Tests
test/2.api/25.internal.event.paths.js:app_key,app_id,device_id,old_device_id). Each must answer400with aresultstartingInvalid path, within5000 * testScalingFactorms./o/langmaproute must still answer200through the same fall-through dispatch.Local runs, on a stack with all CE and EE plugins enabled:
/i/eventstests can only catch a regression where attribution, the only/i/eventshook, is loaded; it was not enabled on that stack.The rule refusing names outside
/iand/ohas no automated test. The tests request through the proxy, which sends only/iand/oto the API, so/sdk/user_properties,/masterand the like get the frontend's404before reaching the API (the first CI run showed exactly that). The rule protects API ports exposed without the proxy. It was checked by a local run against port 3001: with the rule removed,/sdk/user_propertieshung; with it, it answers400.Run locally as well:
/master,/worker,/session/begin,/sdk/user_properties,/systemlogs, answer400in about 1 ms, with no hook errors in the API log./i?device_id=NEW&old_device_id=OLDsumsvc, merges consent, and moves views, crashes and drill events to the new user./o?method=total_users&metric=browser|sources|densitiesgroups by each plugin's short code, and/oreads (which fire/o/validate) work.200:/o/dashboards/all,/o/data-manager/events,/o/langmapand/i/sdk.Not fixed here: on a merge, compliance-hub's
/i/device_idhook matchesconsent_historybyapp_id: ob.app_id. That is an ObjectId on this path, while the collection stores a string, so consent history stays on the old uid. It is unrelated to this change.🤖 Generated with Claude Code