Skip to content

[fix][core] Refuse internal plugin events requested as URL paths - #8293

Merged
shepardly[bot] merged 3 commits into
masterfrom
fix/refuse-internal-event-paths
Nov 25, 2026
Merged

shepardly[bot] merged 3 commits into
masterfrom
fix/refuse-internal-event-paths

Conversation

@widatama

@widatama widatama commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What was wrong

requestProcessor dispatches a request path it does not know to plugins by name: the fall-through default: dispatches the first two path segments (apiPath), then the full path (added in 7653890, 2016), and each route's own default: dispatches its apiPath.

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 /i and /o, so they are reachable through the default nginx config:

Event Fired by core in Data the hooks expect
/i/device_id api/parts/mgmt/app_users.js (2015, be53656) oldUser, newUser
/i/user_merge api/parts/mgmt/app_users.js, api/jobs/userMerge.js (2017, 5240e7a) oldAppUser, newAppUser
/o/method/total_users api/parts/data/fetch.js (2016, 99aa459) shortcodesForMetrics
/i/event/delete api/utils/requestProcessor.js, when events are deleted appId, event_key
/i/events api/parts/data/events.js, for each incoming event params, currEvent
/o/validate api/utils/rights.js, after an app is validated params, app

Every 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.dispatch counts a rejected promise or any returned value as "handled", so the 400 Invalid path fallback never ran and the request was never answered. Every hook logged an unhandled rejection. Servers have logged these errors, for example from views, crashes, compliance-hub, star-rating, drill, surveys, cohorts, retention_segments, revenue, content, browser, locale and sources. 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 requestProcessor go through dispatchRequestPath(). It refuses:

    • any name outside /i and /o, where no request route lives;
    • the six internal events above, listed in INTERNAL_EVENTS with where core fires each one.

    Anything else goes to plugins.dispatch() as before.

  • A refused request gets the existing 400 Invalid path answer without running any hook.

  • Core's own dispatches of these events are unchanged, and no plugin changes.

  • Separate commit: the /i/events route answered unknown sub-paths with must 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/users message and its tests are unchanged.

Why nothing legitimate is refused

  • Outside /i and /o: every registered event name outside /i and /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/enter is commented out). So none of them answers an HTTP request today.
  • Under /i and /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).
  • Under routes core handles (/i/apps/*, /i/app_users/*, /i/users/*, …): these were never reachable, because those routes' defaults dispatch only the two-segment name.
  • The hooks plugin's dynamic hooks on internal events fall in the groups above, or under /i/remote-config, which remote-config's own endpoint claims first.

A new internal event named under /i or /o has to be added to INTERNAL_EVENTS.

Tests

test/2.api/25.internal.event.paths.js:

  • Refused paths: each of the six paths is requested bare and with request parameters (app_key, app_id, device_id, old_device_id). Each must answer 400 with a result starting Invalid path, within 5000 * testScalingFactor ms.
  • Positive control: the locale plugin's /o/langmap route must still answer 200 through the same fall-through dispatch.

Local runs, on a stack with all CE and EE plugins enabled:

  • 13 of 13 pass.
  • With the list emptied, 10 fail on the timeout.
  • The /i/events tests can only catch a regression where attribution, the only /i/events hook, is loaded; it was not enabled on that stack.
  • In general, a refused-path test catches a regression only where that path's hooks are loaded. Without them the request answers 400 anyway.

The rule refusing names outside /i and /o has no automated test. The tests request through the proxy, which sends only /i and /o to the API, so /sdk/user_properties, /master and the like get the frontend's 404 before 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_properties hung; with it, it answers 400.

Run locally as well:

  • Refused paths: all listed paths, and (on the API port directly) /master, /worker, /session/begin, /sdk/user_properties, /systemlogs, answer 400 in about 1 ms, with no hook errors in the API log.
  • Merges still run the hooks: a real merge through /i?device_id=NEW&old_device_id=OLD sums vc, merges consent, and moves views, crashes and drill events to the new user.
  • Core's other internal dispatches still work: /o?method=total_users&metric=browser|sources|densities groups by each plugin's short code, and /o reads (which fire /o/validate) work.
  • Plugin routes through the fall-through still answer 200: /o/dashboards/all, /o/data-manager/events, /o/langmap and /i/sdk.

Not fixed here: on a merge, compliance-hub's /i/device_id hook matches consent_history by app_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

widatama and others added 3 commits November 25, 2026 18:06
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants