Skip to content

Releases

RESTHeart 9.14.0

Choose a tag to compare

@github-actions github-actions released this 02 Nov 13:42
494e278

RESTHeart 9.14.0

This release brings an SDK for plugins written in JavaScript and TypeScript, and changes how the brute force guard counts failed logins. The guard change alters existing behaviour: read "Before you upgrade" first.

Before you upgrade

You have bruteForceAttackGuard enabled. Failed logins are now counted per ip and user, with a second, higher threshold per ip. Five wrong passwords for alice from one address block that address for alice only. To keep the behaviour of 9.13, five failures per ip whatever the user, set:

bruteForceAttackGuard:
  max-failed-attempts: 0
  max-failed-attempts-per-ip: 5

The details are in the guard section below.

JavaScript and TypeScript plugins: the restheart:sdk module (#771 to #778)

A plugin written in JavaScript used to be Java in JavaScript syntax: Java.type() for everything, a Deque<String> for a query parameter, JSON.parse(request.getContent()) and setContentTypeAsJson() in every handler. A plugin now imports what it needs from restheart:sdk, a module served by RESTHeart:

import { defineService, mongo, logger, BadRequestError } from "restheart:sdk";

export default defineService({
  name: "usersService",
  description: "lists users",
  uri: "/users",
  contentKind: "json",
  secured: true,

  handle(req, res) {
    const limit = Number(req.query.limit ?? 100);
    if (Number.isNaN(limit)) throw new BadRequestError("wrong limit qparam");

    logger.debug("listing users for {}", req.account?.name);

    res.json(mongo.db("restheart").collection("users")
      .find({}, { limit, sort: { _id: -1 } })
      .toArray());
  },
});

The design was discussed in #756.

Request and response as data. req.query.limit is the first value of the parameter, a string, undefined when absent. req.headers["content-type"] is case-insensitive. req.account is { name, roles } or null. req.content is typed by contentKind. On the response, res.json(x) sets the content, the content type and status 200 in one call, and res.statusCode and res.headers are plain properties. Every decision about what a value is was made once, in Java, in the new org.restheart.polyglot.spi package.

contentKind. string, json, bson and bytes for services and interceptors, mongo and csv for interceptors only. A mongo interceptor reads req.mongo.dbName, collectionName, documentId, filter, isDocument() and the rest of a curated subset of MongoRequest. Services were string-based only; the json, bson and bytes variants are new. contentKind replaces pluginClass, which keeps working.

Errors. BadRequestError, UnauthorizedError, ForbiddenError, NotFoundError, ConflictError and HttpError(status, message) are answered with their status and message. Any other exception is a 500: it is logged with the plugin name and the JavaScript stack trace, and nothing of it reaches the client.

Utilities, always present. GraalJS has no Node built-ins, so the npm packages that would provide these do not run.

  • logger, with {} placeholders and null-safe. LOGGER.debug("x {}", null) threw, because no Java overload could be chosen; logger.debug("x {}", null) logs x null.
  • crypto: SHA digests, HMAC, random bytes, UUID, constant-time compare. A receiver of signed webhooks (Stripe, GitHub, Twilio) can now be written in JavaScript.
  • encode for base64, base64url, hex, UTF-8 and URL encoding; resource to read a file shipped next to the plugin, inside the plugin directory only; bson for { $oid } ids.

Capabilities, from providers. http, mongo, config, mail and providers. mongo takes plain object literals in canonical extended JSON ({ _id: { $oid: id } }) and returns the same: find, findOne, aggregate, insertOne, updateMany, bulkWrite, db.command() and the rest. http calls other services with the shared client of a new provider, see below; a 4xx or a 5xx comes back with ok === false and does not throw. The import is the declaration: a plugin that imports mail where email is not configured is not deployed, and the log names the missing capability.

The execution model. Each request runs in its own virtual thread, so a blocking call is the right way to do I/O. There are no promises and no async/await in a plugin. The contexts are pooled: a variable at module level is not a server-wide cache.

TypeScript. The type declarations are on npm as @restheart/sdk, types only, versioned with RESTHeart and published with provenance from this release workflow. req and res are inferred from contentKind. Compile with tsc before deploying: RESTHeart deploys .mjs files and does not transpile. A plugin's package.json can name the SDK major it was written for in rh:spi, and RESTHeart refuses a plugin written for a later one.

Plugins written before 9.14.0 run unchanged. Their handle receives the Java request and response as before. LOGGER, mclient, pluginArgs and pluginClass are deprecated, with a replacement each in the docs. modulesReplacements is ignored: the GraalJS option it mapped to was removed in GraalVM 25.1.

Docs and examples. The documentation is now five pages: Develop Plugins in JavaScript, services, interceptors, utilities and capabilities. examples/js-plugin is rewritten in TypeScript, one file per part of the SDK. examples/node-plugin, for RESTHeart running on GraalVM Node, stays on the old API: it runs on the Node event loop, outside the contexts the SDK lives in.

Tests. A conformance suite of reference plugins, one per part of the SDK, runs in the integration tests on every build. The scenarios assert HTTP responses only, so a second guest language can reuse them.

bruteForceAttackGuard counts per ip and user (#792)

The guard counted failed logins per source ip: five in ten seconds and the address got 429 Too Many Requests on every request. Behind a carrier-grade NAT, as with several ISPs and every mobile network, or behind a corporate proxy, hundreds of people share one address. Five wrong passwords typed by five unrelated users blocked all of them, and everyone else on that address.

A brute force targets an account. The guard now counts per ip and user:

  • max-failed-attempts, default 5: failures per ip and user in 10 seconds. The address is blocked for that user only. 0 disables this count.
  • max-failed-attempts-per-ip, default 50: failures per ip whatever the user, for a password spray cycling through many usernames. 0 disables this ceiling.

The user is what the request names: the userid of a Basic challenge, the username of a Digest one, the sub of a bearer JWT, a fingerprint of any other bearer token such as an API key. A request with no credentials counts on the ip only. A mechanism whose credentials travel elsewhere can record the user with Metrics.attemptedUser(exchange, user). The log line and the alarm mail name the user when the block is per user.

A shared HTTP client: the http-client provider

A new provider in core, http-client, builds one java.net.http.HttpClient from the http-client section of the configuration: connect timeout, default request timeout, HTTP version, redirect policy, proxy. The http capability of the SDK uses it, and Java plugins get it with @Inject("http-client"). A client built inside a handler, one per request, loses connection pooling and repeats the TLS handshake on every call.

http-client:
  connect-timeout: 10        # seconds
  request-timeout: 30        # seconds
  version: http-2            # http-1.1 or http-2
  follow-redirects: normal   # never, normal, always

Other changes

  • The JavaScript plugin tests had been skipped on every build, CI included: the test runner checked for GraalVM 25.1 or later, and GraalVM 25.x reports the JDK version, 25.0.x. They now run wherever the plugin deployer runs.
  • restheart-polyglot changed its internal Java classes: JSServiceArgs is gone, and JSService and JSInterceptor are built from a PluginDefinition. This only matters to code that extended those classes.
  • The native image reachability metadata covers the new SDK classes.

Full Changelog: 9.13.1...9.14.0

RESTHeart 9.13.1

Choose a tag to compare

@github-actions github-actions released this 31 Oct 16:56
238a310

RESTHeart 9.13.1

A build release, same code as 9.13.0. It brings the Docker image and the native builds onto GraalVM 25.4.4.1.1, the release that matches the Truffle and polyglot libraries RESTHeart 9.13 ships with.

Why

9.13.0 updated the GraalVM polyglot libraries to 25.4.4.1.1 but kept the native build and the Docker base image on GraalVM 25.1.3. The native build failed on the mismatch (ClassNotFoundException: com.oracle.truffle.api.impl.TruffleLocator), so 9.13.0 has no native binaries and no -native Docker image. The JVM image of 9.13.0 works; it runs on GraalVM CE 25.1.3 (JDK 25.0.3).

What changes

  • Docker image softinstigate/restheart:9.13.1 is based on softinstigate/graalvm:25.4.4.1.1-graalce (GraalVM CE 25.4.4.1.1, JDK 25.0.4.1).
  • Native binaries for Linux x64 and Windows x64, built with GraalVM 25.4, and the softinstigate/restheart:9.13.1-native image is back. The macOS Apple Silicon binary is added to this release when its build finishes: on the GitHub-hosted runner it takes over an hour and no longer holds the release.
  • native-maven-plugin 1.1.18.

Nothing changes in the Java code. If you run 9.13.0 from the JVM image or the zip, you can upgrade or not; if you want the native image or the latest JDK 25 update in the container, upgrade.

See the 9.13.0 release notes for MongoDB 9.0 and the security fix of the accounts module (GHSA-m7m7-gjxg-cjmm).

Full Changelog: 9.13.0...9.13.1

RESTHeart 9.13.0

Choose a tag to compare

@github-actions github-actions released this 31 Oct 14:30
3e225be

RESTHeart 9.13.0

Two things in this release: MongoDB 9.0 is supported and tested, and a security fix in the accounts module closes an account takeover through a pre-registered email address. Every deployment that uses the accounts module with self-registration should upgrade.

MongoDB 9.0 (#780)

Every build now runs the test suite against MongoDB 7.0, 8.0, 8.3 and 9.0, and against mongodb-atlas-local. The README has a new "Supported MongoDB versions" section; older servers down to 4.2 should work but are not tested.

MongoDB Java driver 5.14.0. The first driver release with the 9.0 wire version. It also carries the security fixes of 5.9.2 and 5.11.1. The transactions code was adapted to the driver internals that changed since 5.7.1.

Error codes of 9.0 mapped to HTTP statuses. Verified on MongoDB 9.0.4:

  • 400 for the geo key extraction errors (510, 511, and 16755/16756 that they replace; before 9.0 these were a 500), for a $group accumulator with an empty field name (12116300), and for the memory limits (146, 292). MongoDB 9.0 adds a per-operation memory limit and /_aggrs default to allowDiskUse: false: the message now suggests allowDiskUse.
  • 503 for TooManyOpenTransactions (509) and for the SystemOverloadedError category. A 503 is logged as a warning without the stack trace, and the client gets a clean message instead of the raw driver one.

Change streams survive an election. After an election MongoDB 9.0 returns InterruptedDueToReplStateChange (11602) from a change stream's getMore, and the driver resumes by itself. When the driver cannot resume, RESTHeart used to reopen the stream after a second from the token it was created with: the events written in between were lost, or sent again. The change stream worker and the MCP collection watchers now reopen from the last event dispatched, so an SSE or MCP client gets every event exactly once. If the oplog no longer holds that point (286 ChangeStreamHistoryLost, 280 on older servers), a warning is logged, the stream reopens from now and the sessions stay open.

Transactions. The parsing of the transaction errors (225, 251, 256) is verified against the messages MongoDB 9.0.4 returns.

Native image. The reachability metadata is aligned with driver 5.14.0, and the docs explain how to regenerate it with the tracing agent.

Tooling. docker-compose.yml and docker-compose-native.yml start mongo:9.0, with a health check on db.hello(); run-mongo-container.sh uses mongosh; CONTRIBUTING explains how to test on a version without an atlas-local image.

Security: account takeover through a pre-registered email (GHSA-m7m7-gjxg-cjmm)

Anyone could call POST /auth/register with someone else's email address and a password of their choice. The account stayed unverified, but the password was stored. When the real owner later signed in with Google, or asked for a password reset, the account was activated and the attacker's password survived: the attacker could then log in with Basic authentication and the password they had chosen.

The fix, in the accounts module:

  • OAuth activation drops the registration password. When an unverified account is activated through an OAuth provider, the stored password is cleared and the provider is recorded in socialAuths. The account signs in through the provider; a password can be set later with the reset flow.
  • Forgot password always sends the reset link. Before, an unverified account got the verification link again, which activated it with the password the registrant had chosen. Now the owner gets a reset link; the reset sets the password and verifies the address in one step.
  • An empty stored password never authenticates. MongoRealmAuthenticator refuses an account whose stored password is empty, in both the bcrypt and the plaintext mode.
  • The token issued right after an OAuth activation carries the activated roles. It used to carry $unauthenticated, from the document read before the activation.

Affected: 9.4.0, the first release with the accounts module, up to 9.12.3. Thanks to Santoshkumarpuppala for the report. The advisory has the details and the CVSS score.

One behaviour to know: a user who registers with a password and then activates the account with Google ends up without a password, by design. They sign in with Google, or use "Forgot password" to set one.

Note: no native image for 9.13.0

The native build of 9.13.0 failed: the polyglot libraries moved to GraalVM 25.4.4.1.1 while the native build and the Docker base image stayed on 25.1.3. 9.13.0 has no native binaries and no -native Docker image, and its JVM image runs on GraalVM CE 25.1.3 (JDK 25.0.3). 9.13.1 fixes the build with no code change: same Java, GraalVM 25.4.4.1.1 everywhere, native binaries and -native image back.

Other changes

  • The karate tests of the accounts module cover the two recovery paths above.
  • SonarQube local analysis data is ignored by git; update-dependencies.sh comments clarified.

Full Changelog: 9.12.3...9.13.0

RESTHeart 9.12.3

Choose a tag to compare

@github-actions github-actions released this 29 Oct 00:59
e5a6ca5

RESTHeart 9.12.3

A hardening release for servers that many tenants share. It adds caps on what one caller can hold open or make the server compute: MCP sessions and subscriptions, the depth and complexity of a GraphQL query, and the time a count may take. Nothing changes unless you set the new keys; the defaults are off, as before.

MCP: sessions and subscriptions per scope (#781)

Every initialize creates a session in memory, and a session with a resource subscription is never ended by session-idle-timeout-seconds, by design. A client that keeps initializing, or that subscribes and goes away, leaves sessions and subscriptions that grow without bound.

Two keys cap them, per scope (the whole server when there is no scope provider):

/mcpService/max-sessions-per-scope: 0        # 0 = no cap
/mcpService/max-subscriptions-per-scope: 0   # 0 = no cap

One more session than the cap is refused at initialize with 429 and a JSON-RPC error that says how many are alive and how to make room (DELETE /mcp, or wait for an idle one to expire). One more subscription is refused at resources/subscribe with a JSON-RPC error.

A plugin that wants the numbers, to cap them by its own rules, reads them from McpService.instance(): sessions(scope), subscriptions(scope) and scopes().

GraphQL: the shape of a query is bounded (#782)

query-time-limit bounds how long a query runs. It said nothing about its shape: a query nested deep, or selecting very many fields, was stopped only when it had already spent its time on the database. Two keys, wired to graphql-java's MaxQueryDepthInstrumentation and MaxQueryComplexityInstrumentation:

/graphql/max-query-depth: 0        # 0 = no cap; 10 suits a shared server
/graphql/max-query-complexity: 0   # 0 = no cap; 1000 suits a shared server

A query over either cap is refused with 400 and the error of the instrumentation, before any resolver runs.

Mongo: the count honours query-time-limit (#783)

/mongo/query-time-limit applied to the find of a collection read, not to its count: a GET with ?count and a filter no index serves scanned the collection with no bound. The count now runs with the same maxTime.

Other changes

  • The default configuration files and the documentation describe the new keys.

Full Changelog: 9.12.2...9.12.3

9.12.2

Choose a tag to compare

@github-actions github-actions released this 27 Oct 16:34
4c95e84

RESTHeart 9.12.2

This is a security release. It fixes a change stream bug that could deliver one client's events to other clients, and it hardens the
restheart-accounts endpoints that send emails. If you use change streams with notify_when, or restheart-accounts, upgrade. Read "Before you
upgrade" first: some changes alter existing behaviour.

Before you upgrade

  1. Your change streams use notify_when. A client that does not bind the variable named in notify_when is now rejected with 400
    variable not bound. Before, it received every event of the stream.
  2. Your tests or tools send X-Skip-Email: true. The header is now ignored unless you set /accountsEmailPolicy/allow-skip-email-header: true.
    Without it, register, forgot-password, invite and resend-invite send the email.
  3. You call /auth/forgot-password more than once for the same address. It now sends at most one email per address every 300 seconds. The
    response is still 202. Set /accountsEmailPolicy/resend-cooldown-seconds to change the interval, or 0 to turn it off.
  4. Your sign-up form accepts unusual values. /auth/register now answers 400 to anything but a single email address up to 254 characters,
    and to names longer than 100 characters or containing line breaks, control characters, < or >.

Security: change streams delivered events to the wrong clients (#770)

notify_when filters the events of a change stream per client, by comparing a field of the event with a variable the client binds when it
connects. Two bugs combined:

  • The variable was read only from a plain query parameter (?chatId=...). A client that bound it with avars={"chatId": "..."}, as for the
    stream's own stages, was treated as unbound.
  • An unbound variable disabled the filter. The client received the events of every other client of the same stream.

A client that used avars therefore received all the events of the stream, including documents that belonged to other users.

Now:

  • ?tid=... and avars={"tid": "..."} are equivalent. When both are given, avars wins, as for stage variables.
  • A client that does not bind the variable is rejected with 400 variable not bound, and receives nothing.
  • A variable bound in avars to a value that is not a string is rejected with 400, unless the plain query parameter gives a string.

Security: restheart-accounts emails

A new provider, accountsEmailPolicy, decides when restheart-accounts may skip an email and how often it may resend one:

/accountsEmailPolicy:
  # Honour the X-Skip-Email: true header. For integration tests only.
  allow-skip-email-header: false
  # Minimum seconds between two password-reset or verification emails to the same address.
  resend-cooldown-seconds: 300

X-Skip-Email is off by default

Register, forgot-password, invite and resend-invite skipped the email whenever the request carried X-Skip-Email: true. Anyone could create an
account, or a password-reset token, for an address without its owner being told. The header is now honoured only when
allow-skip-email-header is true, and RESTHeart logs a warning at startup when it is.

forgot-password has a cooldown

/auth/forgot-password sent an email every time it was called, so it could be used to flood an address, also one seeded through
/auth/register. It now sends at most one password-reset (or verification, for unverified accounts) email per address per
resend-cooldown-seconds. The response is the same 202 either way, so the cooldown does not reveal whether the account exists.

register validates its input

/auth/register now accepts only one email address, up to 254 characters, and names up to 100 characters without line breaks, control
characters, < or >. Names end up in emails, and these values could add lines or markup to them.

Other changes

  • Compiler deprecation warnings removed.
  • CI: the release workflow runs on ubuntu-22.04, like the branch and pull request workflows. On ubuntu-latest the kernel is 6.19+, on which
    mongod 8.x refuses to start (SERVER-131155).

Full Changelog: 9.12.1...9.12.2

9.12.1

Choose a tag to compare

@github-actions github-actions released this 23 Oct 10:09
7b70648

RESTHeart 9.12.1

This is a security release. It fixes how RESTHeart sends emails on behalf of requests, and how it fills email templates. If you use
restheart-accounts or the emails plugin, upgrade. Read "Before you upgrade" first: some changes alter existing behaviour.

Before you upgrade

  1. You set per-request SMTP overrides (override-emails-*). They now apply only when the request carries a complete SMTP server:
    smtp-hostname, smtp-username and smtp-password. A partial override is ignored as a whole, and the email goes out with the static
    configuration.
  2. You register an EmailGate. restheart-accounts emails (sign-up verification, password reset, invitations) now pass through it. If the
    gate throws, emails sent on behalf of a request are no longer sent.
  3. Your email templates receive HTML through {{variables}}. Variable values are now HTML-escaped in the body. HTML passed in a variable
    shows as text.
  4. You run the Docker images with volumes or a custom securityContext. The images now run as the non-root user with UID 65532.

Security: emails sent on behalf of requests

Partial SMTP overrides no longer reuse the static credentials

Per-request overrides were merged with the static emails configuration field by field. A request that set only some fields still sent through
the deployment's own SMTP server and credentials. Setting only the sender address or name changed the From of an email sent with the deployment's
account. Setting only the hostname sent the deployment's username and password to that host. Any override also counted as "own sender" for the
EmailGate, so the gate did not count those emails.

Now an override applies only with its own hostname, username and password. It never inherits the static server or credentials. The EmailGate is
told ownSender only in that case.

restheart-accounts emails pass through the EmailGate

The sign-up, password-reset, invitation and resend-invitation emails were sent without the request. A registered EmailGate could not tell which
service sent them and treated them as the deployment's own emails. Per-request SMTP overrides did not apply to them either.

These emails now carry the request, so the gate counts them and per-request SMTP overrides apply.

The EmailGate fails closed for request emails

When the gate threw an exception, the email was sent anyway. Now an email sent on behalf of a request through the deployment's own server is not
sent if the gate fails. Emails with no request, such as the deployment's own notices, and emails sent through the requester's own SMTP server
still go out.

Template variables are escaped

EmailRenderer inserted variable values into the template as they were. A value such as a first name typed into a sign-up form could add links
or markup to the email.

Now:

  • In the body, values are HTML-escaped. URLs keep working: a browser reads &amp; in an href as &.
  • In the subject, values keep their text but lose line breaks and control characters, so they cannot add email headers.
  • Placeholders are replaced in one pass, so a value that contains {{other}} is not expanded.

Docker images run as non-root (#768)

Both images now run as UID 65532 (nonroot). The JVM image takes it from its distroless base, and the native image adds a user with the same
UID. Files in the image stay owned by root and readable by everyone, so any UID can run RESTHeart (for example, the arbitrary UID that OpenShift
assigns).

  • If you mount volumes that RESTHeart writes to, make them writable by UID 65532 or by your chosen UID.
  • The GraalVM polyglot resource cache now goes to /tmp/graalvm-cache.
  • Helm chart: runAsUser and fsGroup are now 65532, and an emptyDir is mounted on /tmp, because the root filesystem is read-only.

Other changes

  • A request body larger than MAX_ENTITY_SIZE or MULTIPART_MAX_ENTITY_SIZE is now answered with 413 instead of 500. Chunked bodies are not
    covered: Undertow closes the connection first.
  • bruteForceAttackGuard: the alarm names the instance by /core/name, and the log line carries the request's Host.
  • @rnd() and the generated JWT key use one shared SecureRandom. The workers watchdog writes thread dumps to a private temporary directory.
  • Dependencies: jackson-databind 2.21.8, Apache Tika 3.3.3, native-maven-plugin 1.1.16.
  • js-plugin example: moment 2.31.0 (CVE-2026-17495, Dependabot #42).

Full Changelog: 9.12.0...9.12.1

9.12.0

Choose a tag to compare

@github-actions github-actions released this 18 Oct 14:36
337eadc

RESTHeart 9.12.0

This release changes how RESTHeart picks the ACL permission that applies to a request, and how restheart-accounts stores teams and puts them in tokens. Several changes alter existing behaviour. Read "Before you upgrade" first.

Before you upgrade

Check these points. Each one has a section below with the details.

  1. You use fileAclAuthorizer with more than one permission per role. The highest priority number now wins. Check which permission you want to apply and give it the higher number.
  2. Your users have more than one role. The matching permission with the highest priority now applies, whatever the order of the roles.
  3. Two of your permissions can match the same request with the same priority. Give them different priorities.
  4. You use restheart-accounts. Tokens no longer carry the team claim. In your ACL rules, replace @user.team._id with @team._id and @user.team.role with @team.role.
  5. You use restheart-accounts with its default membership provider. Run the one-off data migration once.

ACL permissions: which one applies

When a request matches more than one permission, RESTHeart applies one of them, together with its mongo options: filters, write modes, projections. Three changes make that choice follow the documented rule.

fileAclAuthorizer evaluates the highest priority first (#764)

The documentation says that higher priority numbers are evaluated first, and mongoAclAuthorizer works that way. fileAclAuthorizer evaluated the lowest number first. Both authorizers now follow the documentation.

A permission without priority is now evaluated last, in both authorizers. Before, it received the largest possible priority, so mongoAclAuthorizer evaluated it first.

If your acl.yml has more than one permission for the same role that can match the same request, the one that applies may change. Check those permissions and give the higher number to the one that must win.

Users with more than one role (#760)

Before, the role listed first on the account decided which permission applied. RESTHeart now compares the matching permissions of all the user's roles and applies the one with the highest priority.

For example, with these two permissions:

{ "_id": "editorsWriteAll", "roles": ["editor"], "predicate": "path-prefix('/articles') and method(PATCH)", "priority": 200, "mongo": { "allowWriteMode": true } }
{ "_id": "authorsWriteOwn", "roles": ["author"], "predicate": "path-prefix('/articles') and method(PATCH)", "priority": 100, "mongo": { "writeFilter": { "author": "@user._id" } } }

a user with both roles now always gets editorsWriteAll and can edit any article. Before, a user whose roles were listed as [author, editor] got authorsWriteOwn and could edit only their own articles.

Contributed by @axmc1 in #760.

Permissions with the same priority (#767)

When two matching permissions have the same priority, a fixed rule now decides:

  • fileAclAuthorizer applies the one that comes first in the configuration. Before, it applied the last one.
  • mongoAclAuthorizer applies the one with the greatest _id. Its query already did this within a role; it now does it across roles too.

The order of the user's roles no longer plays a part. Still, the best practice is to give different priorities to permissions that can match the same request.

restheart-accounts: the active team

The @team variable (#765)

restheart-accounts registers a new ACL variable, @team, named after accountsConfig.team-claim-name. It holds the caller's active team as { _id, role }, read from the membership provider at every request. Use @team._id and @team.role in predicates, readFilter and mergeRequest:

- roles: [user]
  predicate: path-prefix('/orders') and equals(@team.role, "owner")
  mongo:
    readFilter: {"team": "@team._id"}
    mergeRequest: {"team": "@team._id"}

The value comes from the membership provider, never from the token. A token issued before a switch of team reads as the new team, and a custom membership provider gives the same result on every login path.

Tokens no longer carry the team claim (#765, breaking)

The tokens that restheart-accounts issues no longer contain the team claim: activation, email verification, password reset, POST /auth/switch-team, POST /auth/teams and the OAuth callback. The POST /auth/switch-team response body still returns the team.

What to do:

  • In ACL rules, replace @user.team._id with @team._id and @user.team.role with @team.role. @user.team resolves to nothing once tokens carry no claim.
  • Clients that read the team from the JWT can read it from GET /auth/teams or from the POST /auth/switch-team response.
  • To keep the team in the token, add "@team" to jwtConfigProvider.account-properties-claims (next section). The claim then appears in every token, POST /token included.

ACL variables in account-properties-claims (#765)

An entry of jwtConfigProvider.account-properties-claims that starts with @ is an ACL variable. RESTHeart resolves it with the request that issues the token and puts the value in the token under the variable's name. Quote it, since @ is reserved in YAML:

jwtConfigProvider:
  account-properties-claims:
    - email
    - "@team"

A variable that resolves to nothing adds no claim. An entry that names no registered variable is reported in the startup log.

Memberships live on the team (#766, breaking)

The default membership provider now keeps who belongs to a team, and with which role, in one place: the team's members. The user document keeps only the active team, as team: { _id }. The teams array and team.role on the user document are no longer read or written.

Before, the same membership was written in three places with separate updates, and a failure in between left them in disagreement. Now adding a member, removing one or changing a role is a single update of the team document.

To migrate existing data:

  1. Set accountsConfig.migrate-memberships: true and restart once.
  2. Read the log. Every membership listed in a user's teams that the team itself does not confirm is reported as a warning. It is never added to the team.
  3. Set the option back to false.

The migration also removes teams and team.role from the user documents. Running it again finds nothing to do.

Custom membership providers are not affected.

Deleting a user document does not remove the user from the teams that list it. Remove the member first, with DELETE /auth/remove-member.

Other fixes in restheart-accounts (#765)

  • The accounts endpoints now use jwtConfigProvider.account-properties-claims when the deprecated accountsConfig.account-properties-claims is not set. Before, they added no configured claim at all.
  • POST /auth/switch-team, POST /auth/teams and the OAuth callback now select the configured claims from the user document. Before, a claim such as profile was missing from the tokens they issued.

restheart-stripe

The subscription owner and the payer of an order are now resolved through @team, so they keep working with tokens that carry no team claim (#766).

Bug fixes

  • ACL predicates with quoted BSON values (#761). Since 9.0.0, predicates such as bson-request-array-is-subset(key=roles, values={'"user"','"admin"'}) and bson-request-prop-equals(key=status, value='"draft"') did not work: the permission was discarded at startup, or never matched. They work again.

Thanks

Thanks to @axmc1 for #760. The pull request found that a user with more than one role could get a different permission depending on the order of the roles, and fixed it in both ACL authorizers. Its tests also showed that fileAclAuthorizer evaluated priorities in the opposite order, which led to #764.

9.11.1

Choose a tag to compare

@github-actions github-actions released this 15 Oct 07:27
17b4921

Release 9.11.1

Overview

A security release that completes 9.11.0: no request can make MongoDB run JavaScript, from any of the three places where a client writes operators. 9.11.0 covered the filter query parameter. This release covers the other two, the keys query parameter and the aggregation pipeline of a PATCH request. Upgrade recommended for every deployment that serves untrusted clients. No data migration is needed.

Security

keys and PATCH pipelines cannot run JavaScript on the server

$where, $function and $accumulator run JavaScript on the MongoDB server. A client can write operators that MongoDB evaluates in three places:

  • the filter query parameter: checked by filterOperatorsBlacklist since 9.11.0;
  • the keys query parameter: it is a projection, and since MongoDB 4.4 a projection holds aggregation expressions, $function included. filterOperatorsBlacklist now checks it like the filter, on collection and document requests;
  • the aggregation pipeline of a PATCH request: the new updatePipelineSecurityChecker interceptor runs it through the same aggregationSecurity blacklists that guard the aggregations declared on collections. A $set holding $function is refused with 403, and so is a blacklisted stage such as $lookup.

Both run with the default configuration. The defaults are documented in restheart-default-config.yml and restheart-default-config-no-mongodb.yml.

Docs: Security Hardening.

Behavior Changes

  • $function and $accumulator in keys are refused with 403, as they are in filter since 9.11.0. The same filterOperatorsBlacklist configuration applies to both parameters:

    filterOperatorsBlacklist:
      blacklist: ["$where", "$function", "$accumulator"]
      enabled: true
  • PATCH with an aggregation pipeline is checked against aggregationSecurity: a pipeline with $function, $accumulator or a blacklisted stage gets 403. Disable updatePipelineSecurityChecker only where aggregationSecurity is disabled too:

    updatePipelineSecurityChecker:
      enabled: false

9.11.0

Choose a tag to compare

@github-actions github-actions released this 15 Oct 07:23
6934ad5

Release 9.11.0

Overview

A minor release about server-side JavaScript: the filter query parameter can no longer make MongoDB run it. Also in this release: call_api for MCP sessions with no account, and a fix for invitations on a users collection with a JSON Schema. Upgrading from 9.10.0 needs no data migration. It is a minor release, not a patch, because a default changed: filterOperatorsBlacklist now refuses $function and $accumulator too. If your clients use those operators in filter, read Behavior Changes below.

Improvements

filter cannot run JavaScript on the server

$where, $function and $accumulator are the three MongoDB operators that run JavaScript on the server. Until 9.10.0 filterOperatorsBlacklist refused only $where. It now refuses all three by default, nested anywhere in the filter query parameter, with 403.

The default is the same in restheart-default-config.yml, restheart-default-config-no-mongodb.yml and in the Helm chart values.yaml.

Docs: Security Hardening.

MCP: call_api for sessions with no account

  • A session with no account can call call_api. Its actions run as $unauthenticated, and the ACL decides each of them as it decides an anonymous REST request. Until 9.10.0 call_api refused any session with no account, even when the ACL let $unauthenticated into /mcp.
  • A deployment with no permission for $unauthenticated on /mcp is not affected: the MCP handshake is refused, as before.

Docs: MCP.

Bug Fixes

  • Invitations on a users collection with a JSON Schema failed with 500 "the JSON Schema store is not available". Invite, resend and accept now validate the user documents they write against the collection's schema, like the other account endpoints.

Behavior Changes

  • $function and $accumulator in filter are refused with 403. To allow them again, set the blacklist in your configuration:

    filterOperatorsBlacklist:
      blacklist: ["$where"]
      enabled: true
  • MCP sessions with no account. Where the ACL lets $unauthenticated into /mcp, call_api now runs the actions that the ACL allows to an anonymous request, instead of refusing every call. Check your $unauthenticated permissions if you opened /mcp to anonymous clients.

9.10.0

Choose a tag to compare

@github-actions github-actions released this 05 Oct 13:06
d5a0699

Release 9.10.0

Overview

A minor release about what happens before authentication. The brute force guard now counts every failed attempt and refuses a blocked source whatever credentials it sends; no request reads the database before it is authenticated. Upgrading from 9.9.2 needs no data migration and no configuration change. It is a minor release, not a patch, because the order of some interceptors changed: if you write plugins, read For plugin developers below.

Improvements

Brute force guard

  • A blocked source is refused before authentication. It gets 429 Too Many Requests whatever credentials it sends. Until 9.9.2 the answer of a blocked source depended on the credentials: 401 for wrong ones, 429 for the right ones, so the block could be used to test passwords.
  • The block holds while the attack goes on. A blocked request counts as a failed attempt too: the source is released only after it stays quiet for a whole 10 seconds window. Until 9.9.2 the window drained during the block, and max-failed-attempts requests went through every 10 seconds.
  • Every request without an authenticated account counts, whatever its status. Until 9.9.2 only a 401 did, so wrong credentials on a collection that does not exist, answered 404, were never counted.
  • At DEBUG, each counted failure is logged with its source and the count in the window: Failed auth counted: histogram=… count=….

Docs: Brute Force Attack Guard.

Nothing reads the database before authentication

  • The properties of the db and of the collection are now read after authentication. Whether a db or a collection exists is information, and the query that answers it no longer runs for a request without valid credentials.
  • An error set by an interceptor at REQUEST_BEFORE_AUTH is sent at once. Until 9.9.2 it was held back until after authentication.

Bug Fixes

  • The brute force guard lost failed attempts under concurrency: requests arriving together were counted as one. Each failure is now one entry of the sliding window, and none is lost.
  • The brute force guard forgot every source each 100 failed requests overall, so a max-failed-attempts of 100 or more was never reached, and under a distributed attack a lower one could be missed too. Only the sources with an empty window are forgotten now.

Behavior Changes

  • Brute force guard. A blocked source gets 429 also with the right credentials, until it stays quiet for 10 seconds. Requests with wrong or missing credentials are counted on any path, existing or not.
  • 404 and 401. A request without valid credentials for a db or a collection that does not exist gets 401, as before; the difference is that the database is not queried for it.

For plugin developers

Check your interceptors against these changes.

  • dbPropsInjector and collectionPropsInjector moved from REQUEST_BEFORE_AUTH to REQUEST_AFTER_AUTH, with priority Integer.MIN_VALUE and Integer.MIN_VALUE + 1. An interceptor that reads MongoRequest.getDbProps() or getCollectionProps() must run at REQUEST_AFTER_AUTH with a priority value higher than those. At REQUEST_BEFORE_AUTH the properties are no longer there.
  • Each interceptor is resolved right before it is handled, in priority order, so resolve() sees what the interceptors before it attached to the request. Until 9.9.2 every resolve() of an intercept point ran first, then every handle(). An interceptor whose resolve() relied on the request as it was before the others handled it should be checked.
  • vectorScanInterceptor moved from priority Integer.MIN_VALUE to Integer.MIN_VALUE + 10, still at REQUEST_AFTER_AUTH. The priorities from Integer.MIN_VALUE + 2 to + 9 are free for interceptors that declare an aggregation for the request: $vectorScan is recognized in the stages they add.
  • An error set at REQUEST_BEFORE_AUTH ends the request there: authentication does not run, and the interceptors at REQUEST_AFTER_FAILED_AUTH are not called for it.