Skip to content

fix(parse-server-mongo): master key for local calls; check every call - #110

Merged
slayerjain merged 4 commits into
mainfrom
chore/parse-server-master-key-ips
Nov 21, 2026
Merged

slayerjain merged 4 commits into
mainfrom
chore/parse-server-master-key-ips

Conversation

@slayerjain

@slayerjain slayerjain commented Oct 11, 2026 •

Copy link
Copy Markdown
Member

Merge order

  1. keploy/enterprise pins its parse-server lane to a samples-typescript commit (PARSE_SAMPLE_PIN, on enterprise main), so merging this PR does not change what every enterprise PR's lane runs.
  2. Then this PR.
  3. Then keploy/enterprise#2821, which moves the lane to this flow and re-pins it to this PR's merged commit, and the keploy/integrations PR that moves its parse-server-mongo lane to this sample's main.

Problem

flow.sh record-traffic made 51 calls (53 with bootstrap's signup and login), and 46 of them sent the master key. On main parse-server refuses all 46 with a 403:

error: Request using master key rejected as the request IP address '::ffff:127.0.0.1' is not set in Parse Server option 'masterKeyIps'.

keploy/enterprise pipeline 10621 logged that line 92 times in parse-server-linux, 46 in record and 46 in replay. flow.sh threw every status away, so the lane recorded 46 refusals, replayed 46 refusals, and passed. Classes, users, roles, files, schemas, hooks, aggregate and GraphQL were never recorded.

Root cause

  1. Every client is IPv6 to parse-server. app.listen(port) binds Node's dual-stack :: socket, so an IPv4 client arrives as an IPv4-mapped address: ::ffff:127.0.0.1 behind keploy in the lane, and ::ffff:<bridge gateway> through docker's port mapping. parse-server decides the family with net.isIPv4(ip), false for those, so 0.0.0.0/0 never applies.
  2. ::0 is one address in parse-server 8. getBlockList in lib/middlewares.js treats only '::/0' and '::' as "any IPv6" (8.2.3, and 8.6.105, the newest 8.x). '::0' goes into a net.BlockList as the single address ::. parse-server's own option help says ['0.0.0.0/0', '::0'] allows any address; that holds from 9.5.0, not for the 8.2.3 this sample pins.

The sample's default, in both docker-compose.yml and index.js, was 0.0.0.0/0,::0: meant to admit everyone, it refused everyone.

Change

The master key: the docker host only, by construction

  • docker-compose.yml publishes the app's port on the host's 127.0.0.1 only. No other host can reach the app at all, over IPv4 or IPv6. Not on [::1] as well: docker cannot bind [::1] on a host with IPv6 off, so docker compose up would fail there (failed to bind host port [::1]:6100/tcp: cannot assign requested address), while 127.0.0.1 binds on every host. So call the app at 127.0.0.1, not localhost: nothing listens on [::1]. flow.sh now does.
  • That is what keeps the LAN out, not the list below. Docker relays a client of a published port from the compose network's gateway, an address in the network's subnet, whenever it relays rather than NATs the connection, as it does for the IPv6 binding ([::]) on this IPv4-only network. So an allowlist cannot tell the docker host from another host once the port is published wider than 127.0.0.1.
  • The master-key list is parse-server's own default, 127.0.0.1,::1, in index.js, and docker-compose.yml adds the compose network's subnet (${PARSE_NETWORK_SUBNET}, default 172.30.0.0/24): the docker host's own calls through the 127.0.0.1-published port arrive from the gateway. flow.sh and the keploy lanes call from the docker host, so their master-key calls go through.
  • The list is not 0.0.0.0/0,::/0: the master key is a published default, and it gives full access, hooks included (a hook can make the server call any URL).
  • An IPv4 entry matches its IPv4-mapped client (::ffff:127.0.0.1 against 127.0.0.1), so no /0 entry is needed for the dual-stack socket. The README's env table says all this.
  • Who gets the master key: any process on the docker host, a container with host networking included. Nothing else reaches the port.

express 5.1.0, so a refused master-key GraphQL call is a 403, not a crash

  • index.js mounts parse-server's GraphQL on the sample's own express app (below). That runs parse-server's async header middleware there, which refuses a master key from an unlisted address by rejecting.
  • On express 4.21.2, the version this sample pinned, the rejection is dropped and node exits: one such request ended the app. parse-server 8.2.3's own REST app runs on express 5.1.0, which hands it to parse-server's error handler. package.json now pins express 5.1.0; app.use(mountPath, parseServer.app) works unchanged.
  • express 5 hands a listen error (EADDRINUSE, EACCES) to the app.listen callback instead of throwing it, so index.js now exits 1 on one; it would otherwise say it listens and stay up serving nothing.
  • The workflow's build job runs check-parse-master-key-ips.sh after the coverage run:
    • index.js's fallback list is 127.0.0.1,::1, and compose's default list is loopback plus the network's subnet;
    • docker publishes the port on 127.0.0.1 only, and the master key through 127.0.0.1 gets 200;
    • at the host's IPv4 address and its IPv6 link-local and global addresses (each first shown to take connections, on a listener of the script's own), master-key calls to /serverInfo, /graphql and /schemas are refused at the connection: the port is closed there, and any answer, a 403 included, fails the check;
    • with its port already taken, the app exits 1;
    • then, with the list 127.0.0.1,::1, the docker host's own master-key REST and GraphQL calls are the refused ones: 403 and 403, and the app still answers /health and its container still runs.

So a refused or broken call cannot pass silently again

  • flow.sh record-traffic now checks every call.
    • fire records each status. It must be any 2xx, or, for the three calls that probe an error path, the one code they name with --expect: DELETE /sessions/no-such-session-id 404, POST /functions/no-such-fn 400, POST /jobs/no-such-job 400.
    • The three GraphQL calls (fire --graphql) must also answer a GraphQL result, a JSON object with a data object and no errors: GraphQL reports a failed query or mutation in a 200.
    • Without a session token it notes the four session calls it cannot send (GET /users/me, the session PUT /users/{id}, GET /sessions/me, POST /logout).
    • Every call is still sent. At the end, record-traffic exits 1 and lists each problem, with the first 200 printable bytes of the answer and curl's own error.
    • Each call is bounded by --max-time (PARSE_CURL_MAX_TIME, default 60 s), so a call whose answer never comes is listed with curl's (28) instead of hanging the flow.
    • bootstrap's health wait is a wall-clock bound: each try waits at most 5 s and is cut at the deadline. check-parse-flow-health-wait.sh, run in the build job, checks that bootstrap 2 against a server that never answers exits 1 within 4.5 s.
  • flow.sh bootstrap exits 1 when parse-server does not come up, when the signup fails for any reason but a re-run's (400, code 137: the fixed objectId is taken), and when the login gives no session for the user with PARSE_FIXED_USER_ID. It used to take any 4xx signup as "already exists" and exit 0 with no token.
  • Those exits fail the keploy lanes' record phase, and this repo's build-coverage job (run-and-measure-parse-server.sh runs under set -e).

Calls that never worked, found by the check once the master key got through

  • GraphQL. All three POST /parse/graphql calls returned 404: a ParseServer used as express middleware serves REST only. index.js now mounts a ParseGraphQLServer at <mount>/graphql, before the REST app. The GraphQL schema loads on the first GraphQL request, not at boot, so the boot-phase _SCHEMA sequence this sample exists for is unchanged.
  • Hook delete. DELETE /hooks/functions/covFn returned 404: parse-server has no such route. A hook is deleted with PUT /hooks/functions/{name} and {"__op":"Delete"}, which flow.sh now sends.

What a replay needs, now that the calls do something

  • Roles. POST /roles pins its objectId to PARSE_FIXED_ROLE_ID, keploy-role-id, as the class objects already do. A random id changed the Location and Etag headers on every replay.
  • Files. preserveFileName: true: parse-server prefixes an uploaded file's name with 32 random hex characters otherwise.
  • header.Etag is added to keploy.yml.template's noise. It is a hash of the body, so it changes whenever a noised field does. The body is still compared field by field.
  • Cleanup. record-traffic deletes the role with the other objects with fixed ids, so another bootstrap and record-traffic run against the same database. It is one more call: record-traffic sends 52 and bootstrap 2, 54 in all.

README: names both keploy lanes that use the sample (keploy/enterprise's parse-server-linux.sh and keploy/integrations' parse-server-mongo-linux.sh), and its allowlist, express and port rows match the code: the app is published on 127.0.0.1 only, so call it there, from the docker host.

Verification

This head, amd64, docker compose on a test host, default settings:

run result
bootstrap, fresh database signup 201, exit 0
record-traffic exit 0; 54 calls fired; 0 master-key refusals
docker port 127.0.0.1:<port> only
the master key through [::1] refused at the connection (curl exit 7): nothing is published there
from a second host on the LAN, with the master key: /serverInfo, /graphql and /schemas at the docker host's IPv4 address and at its IPv6 link-local address all 6 refused at the connection (curl exit 7), while that host reaches the docker host's ssh port at both addresses
right after: /health 200; the app container still running
a docker host with IPv6 off (docker in docker, disable_ipv6=1 on all interfaces, no ::1 on lo) docker compose up exit 0; published on 127.0.0.1:6100 only; the master key through 127.0.0.1: 200. With [::1] published as well, compose up fails: failed to bind host port [::1]:6100/tcp: cannot assign requested address
check-parse-master-key-ips.sh exit 0: both lists right; published on 127.0.0.1 only; 200 through 127.0.0.1; the host's IPv4 and IPv6 link-local addresses take connections on the script's own listener and refuse all 6 master-key calls at the connection; with its port taken the app exits 1; with 127.0.0.1,::1, the host's own REST and GraphQL calls get 403 and 403, then health 200, running
the same check with the port published on every interface, as on main exit 1: published on 0.0.0.0 and [::]; at the host's IPv6 link-local address /serverInfo, /graphql and /schemas answer 200 to the master key, and at its IPv4 address 403 (an answer, so a failure too)
the same check with [::] published as well as 127.0.0.1 exit 1: published beyond 127.0.0.1, and the same three 200s over IPv6
the same check with [::1] published as well as 127.0.0.1 exit 1: published beyond 127.0.0.1
the same check with express 4.21.2 exit 1: GraphQL HTTP 000 (curl: (52) Empty reply from server), then health (7) Failed to connect, container not running
the same check without the listen-error exit exit 1: with its port taken the app keeps running
the same check with index.js's fallback, or compose's default list, set to 0.0.0.0/0,::/0 exit 1, each
check-parse-flow-health-wait.sh exit 0: bootstrap 2 exits 1 after 3.0 s, bootstrap 6 after 6.0 s
the same check on the wait before this change exit 1: bootstrap 2 took 12.0 s
the same check with each try's --max-time left at 5 s exit 1: bootstrap 2 took 6.2 s
the same check with a try at no time left (-ge 0), or with no deadline check exit 1: still waiting after 30 s
record-traffic against a port that accepts and never answers, PARSE_CURL_MAX_TIME=1 exit 1 in 76 s, all 52 calls listed with curl: (28)

The flow checks (one stack, run in this order; arm64):

run result
bootstrap, fresh database signup 201, token persisted, exit 0
record-traffic exit 0
bootstrap again signup 400 (code 137), the login gives the fixed user's session, exit 0
record-traffic again exit 0
bootstrap with a wrong password exit 1: login gave no session for keploy-user-id: {"code":101,"error":"Invalid username/password."}
bootstrap for another fixed objectId with the same username exit 1: signup failed: HTTP 400: {"code":202,…}
bootstrap against a dead port exit 1, token file emptied
record-traffic again without bootstrap exit 1: the four session calls, code 209 (its session was logged out)
record-traffic against a closed port exit 1: HTTP 000, want 2xx: (curl: (7) Failed to connect …)
record-traffic with no token file exit 1, naming the four session calls not sent
a GraphQL query of a missing object exit 1: HTTP 200, but the answer is not a GraphQL result with data and no errors: {"errors":[…
the same, with --graphql taken off exit 0, so the GraphQL check is what catches it

shellcheck 0.11.0: check-parse-master-key-ips.sh and check-parse-flow-health-wait.sh clean; flow.sh has the same findings as main (2 × SC2016, 1 × SC2034).

Not changed

  • The sample still pins parse-server 8.2.3.

@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

parse-server-mongo sample coverage

ref coverage
base (main) 38.7%
this PR 46.4%

Threshold: PR may not drop coverage by more than 1.0pp. Override per-repo via the PARSE_COVERAGE_THRESHOLD actions variable.

… on calls that do not work

flow.sh record-traffic sent the master key on 46 of its calls, and
parse-server refused every one with a 403. The default masterKeyIps,
`0.0.0.0/0,::0`, admits no client parse-server 8 sees: each arrives as
an IPv4-mapped IPv6 address (`::ffff:127.0.0.1` behind keploy), and
parse-server 8 reads `::0` as the single address `::`. flow.sh threw the
statuses away, so keploy lanes on this sample recorded and replayed 46
refusals and passed (keploy/enterprise pipeline 10621).

The fix: masterKeyIps defaults to `0.0.0.0/0,::/0` in docker-compose.yml
and index.js, the "any IPv6" both parse-server 8 and 9 read.

So it cannot silently come back:
- record-traffic checks every call: any 2xx, or the one code an error
  probe names with --expect; the GraphQL calls must answer a result with
  `data` and no `errors` (GraphQL reports failures in a 200). Without a
  session token it notes the four session calls it cannot send. It
  sends every call, then exits 1 listing each problem with the start of
  the answer and curl's own error.
- bootstrap exits 1 unless the login gives a session for the user with
  PARSE_FIXED_USER_ID. A failed signup is accepted only as a re-run's
  (400, code 137: the fixed objectId is taken); it used to take any 4xx
  as "already exists" and exit 0 with no token, after which
  record-traffic skipped its session calls.

Calls the check found broken: GraphQL was never mounted (a ParseServer
used as middleware serves REST only), so index.js mounts a
ParseGraphQLServer at <mount>/graphql; a hook is deleted with a PUT of
{"__op":"Delete"}, as parse-server has no DELETE route for it.

For replay, now that the calls do something: the role's objectId is
pinned (PARSE_FIXED_ROLE_ID), files keep their names (preserveFileName),
header.Etag is noise (a hash of a body with noised fields), and
record-traffic deletes the role, so another bootstrap and record-traffic
run on the same database.

README, usage and comments say what the script does; the `list-routes`
subcommand that never existed is no longer advertised, `--help` exits 0,
and the health-timeout message goes to stderr.

Signed-off-by: slayerjain <shubhamkjain@outlook.com>
@slayerjain
slayerjain force-pushed the chore/parse-server-master-key-ips branch from 2c0f74e to 37b495a Compare October 13, 2026 03:55
The sample's default masterKeyIps was 0.0.0.0/0,::/0, and compose
publishes the port on every host interface, so any host that could reach
the port had the master key, a published default. The default is now
parse-server's own, 127.0.0.1,::1, and compose adds the compose
network's subnet, the address a client on the docker host arrives from
through the published port. flow.sh and the keploy lanes call from
there, so their master-key calls still go through. Any other host gets a
403.

With a restricted list, one master-key GraphQL call from a refused
address ended the app: the GraphQL mount runs parse-server's async header
middleware on the sample's express 4 app, the middleware refuses by
rejecting, and express 4 drops the rejection, so node exits on it. The
sample now runs express 5.1.0, parse-server 8.2.3's own, which hands the
rejection to parse-server's error handler: a 403, and the app stays up.

The workflow's build job now runs check-parse-master-key-ips.sh: from
localhost the master key gets 200; from the host's own non-loopback
address a REST call and a GraphQL call with it get 403; the app still
answers /health and its container still runs.

flow.sh bounds each call with --max-time (PARSE_CURL_MAX_TIME, default
60 s; each health-wait try 5 s), so a call whose answer never comes is
listed as one that did not work instead of hanging the flow. The README
names both keploy lanes that use the sample, and its allowlist and
express rows match the code.

Signed-off-by: slayerjain <shubhamkjain@outlook.com>
@slayerjain slayerjain changed the title fix(parse-server-mongo): let flow.sh's master-key calls through; fail on calls that do not work fix(parse-server-mongo): master key for local calls; check every call Nov 21, 2026
The master-key allowlist admits the compose network's subnet, so that the
docker host's own calls get through: docker relays them from the
network's gateway. But compose published the port on every host
interface, and docker relays the IPv6 binding ([::]) for every client,
also from the gateway. So any host that reached the docker host over
IPv6, link-local included, had the master key, a published default.

The port is now published on the host's loopback only, 127.0.0.1 and
[::1], so no other host can reach the app at all, whatever docker relays.
The allowlist stays loopback plus the compose subnet.

check-parse-master-key-ips.sh now checks, besides 200 for the host's own
call through loopback: the port is published on loopback only; compose's
default list and index.js's fallback are what they should be; the host's
IPv4 address and its IPv6 link-local and global addresses (each first shown
to take connections, on a listener of the script's own) refuse the
connection or answer 403 to master-key calls to /serverInfo, /graphql and
/schemas. The refused-call crash check now runs against the app restarted
with the list 127.0.0.1,::1, so that the host's own calls are the refused
ones: 403, and the app keeps serving.

express 5 hands a listen error to the app.listen callback instead of
throwing it, so the app said it listened and stayed up serving nothing:
it now exits 1, with a row that takes the port first.

flow.sh's health wait is now a wall-clock bound: each try is cut at the
deadline, so a server that takes connections and never answers ends the
wait on time, with a row (check-parse-flow-health-wait.sh) run in CI.

Signed-off-by: slayerjain <shubhamkjain@outlook.com>
Publishing the port on [::1] as well as 127.0.0.1 broke `docker compose
up` on a docker host with IPv6 off: docker cannot bind [::1] there
("failed to bind host port [::1]:6100/tcp: cannot assign requested
address"), while the sample's earlier all-interfaces publish worked.
127.0.0.1 alone binds on every host and is still loopback only, so no
other host can reach the app.

- docker-compose.yml publishes 127.0.0.1:PORT:PORT only.
- flow.sh calls the app at 127.0.0.1, not localhost, since nothing
  listens on [::1]; the README says the same.
- check-parse-master-key-ips.sh: the port must be published on 127.0.0.1
  only, the [::1] master-key call is gone, and each address another host
  reaches this host at (IPv4, IPv6 link-local and global) must refuse
  the connection: a 403 there now fails, since any answer means the app
  is published beyond 127.0.0.1. Its in-container serverURL uses the
  container port.

Signed-off-by: slayerjain <shubhamkjain@outlook.com>
@slayerjain
slayerjain marked this pull request as ready for review November 21, 2026 23:17
@slayerjain
slayerjain merged commit 0e78d3b into main Nov 21, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant