Skip to content

fix(NODE-1935): Rework read state caching#9792

Open
blind-oracle wants to merge 6 commits intomasterfrom
igor/node-1935
Open

fix(NODE-1935): Rework read state caching#9792
blind-oracle wants to merge 6 commits intomasterfrom
igor/node-1935

Conversation

@blind-oracle
Copy link
Copy Markdown
Contributor

@blind-oracle blind-oracle commented Apr 9, 2026

  • Narrow down the cacheable paths to the following form:

    [
      [ "canister_ranges", "aaaaa-aa" ],
      [ "subnet", "aaaaa-aa" ],
    ]
    

    That is, only requests which have 2 paths, each of them has 2 labels, first of which is canister_ranges or subnet (or the other way around) and the second one is a valid Principal (in essence this just means shorter than 30 bytes). All other paths are deemed non-cacheable. This also fixes an issue - before we considered paths with at least one of the canister_ranges or subnet cacheable, where in fact we aim to cache only if we have both.

  • Add an explicit check that the request is a subnet read state

  • Move the logic that decides if paths are cacheable or not to process.rs to avoid storing the whole paths Vec in the request context, which might be large, up to 4MB. This avoids keeping the large context around for the duration of the request - only cacheable paths are stored. It's not ideal from architecture viewpoint, but I don't see other way w/o reworking the code a lot...

  • Add early checks for the request body in preprocess and response body in read state caching middleware to avoid dealing with known-big in advance bodies

  • Fix the weigher to size the paths correctly (not that it matters much anymore since we only cache small ones).

  • Add/fix some tests

@blind-oracle blind-oracle requested a review from a team as a code owner April 9, 2026 13:30
@github-actions github-actions bot added the fix label Apr 9, 2026
@github-actions github-actions bot added the @node label Apr 9, 2026
@r-birkner r-birkner changed the title fix(NODE-1935): Rework read state caching, fix potential DoS fix(NODE-1935): Rework read state caching Apr 9, 2026
pub body: Vec<u8>,
}

/// Paths for a read state call
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Since this is pub and could be constructed directly, can we have a note that the paths should be sorted?

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants