stalwartlabs/stalwart · error · ScimError

The size of the request payload exceeds the maximum of {max_

Error message

The size of the request payload exceeds the maximum of {max_size} bytes.

What it means

A SCIM 413 error thrown by the `fetch` helper in crates/scim/src/request.rs when `fetch_body` returns None because the incoming HTTP request body exceeds the configured `max_size` bytes. The detail message states the configured byte limit, mirroring RFC 7644's maxPayloadSize behavior for regular (non-bulk) requests.

Source

Thrown at crates/scim/src/request.rs:266

        access_token: Option<&'x AccessToken>,
    ) -> Result<ScimContext<'x>> {
        Ok(ScimContext {
            server: self,
            access_token: req.scim_access_token(access_token)?,
            session_id: session.session_id,
        })
    }
}

async fn fetch(
    req: &mut HttpRequest,
    session: &HttpSessionData,
    max_size: usize,
) -> Result<Vec<u8>> {
    fetch_body(req, max_size, session.session_id)
        .await
        .ok_or_else(|| {
            ScimResponseError::Scim(Error::new(413).with_detail(format!(
                "The size of the request payload exceeds the maximum of {max_size} bytes."
            )))
        })
}

pub fn search_request(query: Option<&str>) -> Result<SearchRequest<'_>> {
    match query {
        Some(query) => SearchRequest::from_query(query).map_err(Into::into),
        None => Ok(SearchRequest::default()),
    }
}

pub fn method_not_allowed(allow: &'static str) -> ScimResponseError {
    ScimResponseError::Allow(
        Error::new(405).with_detail(format!(
            "The HTTP method is not supported by this endpoint, allowed methods are {allow}."
        )),
        allow,

View on GitHub (pinned to e962003857)

Solutions

  1. Reduce the request payload size (drop or externalize large attributes such as base64 photos).
  2. Raise the server's max_size configuration for SCIM request bodies if the limit is too strict for your workload.
  3. Send large data via multiple smaller requests where the schema allows it.

Example fix

// before
user["photos"] = json!([{"value": base64_huge_image}]);
// after
user["photos"] = json!([{"value": "https://cdn.example/img.jpg"}]);
Defensive patterns

Strategy: validation

Validate before calling

let body = serde_json::to_vec(&payload)?;
if body.len() > MAX_BODY_SIZE { /* shrink payload: remove photos/large attrs */ }

Prevention

When it happens

Trigger: `fetch` is called during `dispatch_scim_request` to read a request body; the body is larger than `max_size`, so `fetch_body` yields None and this error is raised.

Common situations: A client uploads a user with very large attributes/photos against a server with a tight body limit; a proxy or gateway lowers allowed body sizes; an integration was moved to a server with a smaller max_size configuration.

Understand the failure class

Background: payload too large / request exceeds maximum size: why libraries cap bytes and how to fix oversize payloads — this error's family across 50 libraries.

Related errors


AI-assisted analysis of stalwartlabs/stalwart@e962003857 (2026-09-06). Data as JSON: /api/errors/36bf8a75c9da4eb7. Report an issue: GitHub.