Skip to content

Streaming fetch does not enforce maxResponseBytes without Content-Length #982

Closed

Description

What happened?

Network.FetchPolicy.maxResponseBytes is not enforced against actual bytes when streamResponse: true and the response lacks Content-Length. The same limit is enforced in buffered mode.

Expected: the streamed body errors when it exceeds the configured policy limit, regardless of whether a size header was supplied.

Steps to reproduce

Run from tag v2.0.151; this extracts the unchanged transport and error class for a loopback fixture, without changing the production address policy.

Standalone reproduction command
python3 - <<'PY' | bun run -
from pathlib import Path
s=Path('backend/cli/src/settings/network.ts').read_text()
print('import {isIP} from "node:net"; import {request as httpRequest,createServer} from "node:http"; import {request as httpsRequest} from "node:https"; import {Readable} from "node:stream";')
print(s[s.index('  export class ResponseTooLargeError'):s.index('  export const Group')])
print(s[s.index('  async function pinnedFetch('):s.index('  /** Policy-aware fetch.')])
print('''
const server=createServer((req,res)=>{
  res.writeHead(200,{"content-type":"text/plain"});
  res.write("1234");
  setTimeout(()=>res.end("5678"),10);
});
await new Promise(r=>server.listen(0,"127.0.0.1",r));
const url=new URL("http://127.0.0.1:"+server.address().port);
try {
  for(const stream of [false,true]) {
    try {
      const r=await pinnedFetch(url,{signal:AbortSignal.timeout(2000)},"127.0.0.1",5,stream);
      console.log({stream,limit:5,received:(await r.arrayBuffer()).byteLength});
    } catch(e) {console.log({stream,error:e.name});}
  }
} finally {server.closeAllConnections();server.close();}
''')
PY

Logs and screenshots

stream=false: ResponseTooLargeError
stream=true: limit=5, received=8

Code location and scope

network.ts:619 returns the incoming stream before the incremental limit check at line 637. The outer fetch wrapper checks only a declared Content-Length.

Current webfetch, image and remote-instruction readers have additional consumer-side bounds. This report is about the shared transport contract and does not claim a demonstrated unbounded-download exploit in those tools. A counting stream would make the policy consistent and avoid relying on every caller to duplicate it.

How did you install OpenScience?

Official desktop ZIP and npm; isolated reproduction uses tag v2.0.151 source.

OpenScience version

2.0.151 (latest npm at reporting time).

Provider and model

Not applicable; no model calls.

Operating system

macOS 27.0 ARM64; Bun 1.3.13. Not yet tested inside the packaged desktop runtime.

Action approval mode

Not applicable to the isolated fixture.

Activity

  1. aayambansal commented on Oct 18, 2026

    @aayambansal
    Member

    Fixed in #998, squash merged to main. Both buffered and streamed responses now pass through the same byte-counting transform. It enforces maxResponseBytes against actual decoded bytes even when Content-Length is absent. Local HTTP regressions cover both modes, chunked responses without size headers, compressed expansion, and upstream socket cancellation.

    Validation passed on the supported pinned runtime, including the focused network and scientific-connector regressions, plus PR CI. These source fixes are on main; installed 2.0.151 builds need a release containing them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions