{"record":{"id":"492cbaf3cbf4d3c1","repo":"ory/kratos","slug":"identity-schema-rejected-body-exceeds-d-bytes","errorCode":null,"errorMessage":"identity schema rejected: body exceeds %d bytes","messagePattern":"identity schema rejected: body exceeds (.+?) bytes","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"schema/loader.go","lineNumber":78,"sourceCode":"// regardless of disallowRefs). See NewCompiler for the semantics of\n// disallowRefs.\nfunc NewCompilerWithURL(ctx context.Context, schemaURL string, disallowRefs bool) (*jsonschema.Compiler, error) {\n\tctx = ensureGuardedHTTPClient(ctx)\n\n\tresource, err := jsonschema.LoadURL(ctx, schemaURL)\n\tif err != nil {\n\t\treturn nil, errors.WithStack(err)\n\t}\n\tdefer func() { _ = resource.Close() }()\n\n\t// Read the body with a hard size cap so a malicious schema URL cannot\n\t// OOM kratos by returning a multi-GB body.\n\tdata, err := io.ReadAll(io.LimitReader(resource, MaxSchemaBodyBytes+1))\n\tif err != nil {\n\t\treturn nil, errors.WithStack(err)\n\t}\n\tif len(data) > MaxSchemaBodyBytes {\n\t\treturn nil, errors.Errorf(\"identity schema rejected: body exceeds %d bytes\", MaxSchemaBodyBytes)\n\t}\n\n\t// Decode once for structural prevalidation. The upstream compiler will\n\t// decode again from the same bytes — accepting a small CPU duplication\n\t// in exchange for the security gate.\n\tvar doc any\n\tif err := json.Unmarshal(data, &doc); err != nil {\n\t\treturn nil, errors.WithStack(err)\n\t}\n\tif err := preValidateSchema(doc); err != nil {\n\t\treturn nil, errors.WithStack(err)\n\t}\n\n\tc := NewCompiler(disallowRefs)\n\tif err := c.AddResource(schemaURL, bytes.NewReader(data)); err != nil {\n\t\treturn nil, errors.WithStack(err)\n\t}\n\treturn c, nil","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/ory/kratos/blob/b86338da04a040247a07f46100a86dcfb3875909/schema/loader.go#L60-L96","documentation":"NewCompilerWithURL streams the schema body from the given URL through a LimitReader capped at MaxSchemaBodyBytes+1 specifically to prevent a malicious URL from OOMing kratos, and the read produced more than MaxSchemaBodyBytes bytes. The remote schema at the faulting input - the configured schema URL - is too large to be accepted.","triggerScenarios":"Thrown at schema/loader.go:78 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Reduce the schema size by removing unused definitions or splitting it","Inline only the needed subschemas instead of serving one giant document","Host the schema somewhere that can serve the trimmed version and update the URL"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b86338da04a040247a07f46100a86dcfb3875909","analyzedAt":"2026-09-07T15:58:15.934Z","contentChangedAt":"2026-09-07T15:58:15.934Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}