cosmo icon indicating copy to clipboard operation
cosmo copied to clipboard

Don't compute sha256 of empty persisted operation bodies

Open robmyersrobmyers opened this issue 4 months ago • 3 comments

Component(s)

router

Component version

[email protected]

wgc version

latest

controlplane version

n/a

router version

[email protected]

What happened?

Description

The router computes sha256 hashes of operations with empty bodies, even if the persisted operation hash is already present. This breaks fetching the operation body from the cache because it is looking for the e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 hash in the cache, which does not match the supplied hash.

According to the documentation, persisted operations without the body should be supported.

Here is a link to a fix I'm testing.

Steps to Reproduce

  1. Configure router for persisted operations
  2. Configure persisted query manifest
  3. Follow documentation to execute a persisted operation with a hash but without a query body

Expected Result

Persisted operations without query bodies execute without issue.

Actual Result

An "Unknown persisted operation" error is thrown with this hash: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855

That hash is the hash of ""

Environment information

Environment

Compiler(if manually compiled): go version go1.25.1 darwin/arm64

Router configuration


Router execution config


Log output


Additional context

No response

robmyersrobmyers avatar Sep 25 '25 16:09 robmyersrobmyers

WunderGraph commits fully to Open Source and we want to make sure that we can help you as fast as possible. The roadmap is driven by our customers and we have to prioritize issues that are important to them. You can influence the priority by becoming a customer. Please contact us here.

github-actions[bot] avatar Sep 25 '25 16:09 github-actions[bot]

Hi @robmyersrobmyers, thank you for raising an issue. Would it be possible for you to help us reproduce it and provide the exact query and a router config?

Thanks in advance

Noroth avatar Sep 30 '25 09:09 Noroth

Any request without a query body like this one directly from the docs exhibits the same behavior.

curl 'http://127.0.0.1:3002/graphql' \
    -H 'graphql-client-name: curl' \
    --json '{"extensions":{"persistedQuery":{"version":1,"sha256Hash":"2d9df67f96ce804da7a9107d33373132a53bf56aec29ef4b4e06569a43a16935"}}}'

Here are persisted operations relevant configurations

engine:
  debug:
    enable_persisted_operations_cache_response_header: false
  enable_persisted_operations_cache: true
security:
  block_non_persisted_operations:
    enabled: false
  complexity_limits:
    depth:
      enabled: true
      ignore_persisted_operations: true
      limit: 15
    root_field_aliases:
      enabled: false
      ignore_persisted_operations: true
      limit: 3
    root_fields:
      enabled: true
      ignore_persisted_operations: true
      limit: 3
    total_fields:
      enabled: true
      ignore_persisted_operations: true
      limit: 128
persisted_operations:
  cache:
    size: '10MB'
  log_unknown: true
  safelist:
    enabled: false
  storage:
    object_prefix: 'persisted-ops'
    provider_id: 'local-fs'
automatic_persisted_queries:
  cache:
    size: '10MB'
    ttl: 900
  enabled: true
  storage:
    object_prefix: 'apq-ops'
    provider_id: 'local-fs'

robmyersrobmyers avatar Sep 30 '25 12:09 robmyersrobmyers