Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API.HTTPHeaders.Access-Control-Allow-Headers cannot be modified #9586

Open
3 tasks done
estebanabaroa opened this issue Jan 24, 2023 · 1 comment
Open
3 tasks done
Labels
kind/bug A bug in existing code (including security flaws) P3 Low: Not priority right now topic/rpc-api Issues related to Kubo RPC API at /api/v0

Comments

@estebanabaroa
Copy link

estebanabaroa commented Jan 24, 2023

Checklist

Installation method

ipfs-desktop

Version

ubo version: 0.18.0
Repo version: 13
System version: amd64/linux
Golang version: go1.19.1

Config

{
  "API": {
    "HTTPHeaders": {
      "Access-Control-Allow-Headers": [
        "Authorization"
      ],
      "Access-Control-Allow-Origin": [
        "*"
      ],
      "Access-Control-Expose-Headers": [
        "Authorization"
      ]
    }
  },
  "Addresses": {
    "API": "/ip4/127.0.0.1/tcp/5001",
    "Announce": [],
    "AppendAnnounce": [],
    "Gateway": "/ip4/127.0.0.1/tcp/8080",
    "NoAnnounce": [],
    "Swarm": [
      "/ip4/0.0.0.0/tcp/4001",
      "/ip6/::/tcp/4001",
      "/ip4/0.0.0.0/udp/4001/quic",
      "/ip4/0.0.0.0/udp/4001/quic-v1",
      "/ip4/0.0.0.0/udp/4001/quic-v1/webtransport",
      "/ip6/::/udp/4001/quic",
      "/ip6/::/udp/4001/quic-v1",
      "/ip6/::/udp/4001/quic-v1/webtransport"
    ]
  },
  "AutoNAT": {},
  "Bootstrap": [
    "/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN",
    "/dnsaddr/bootstrap.libp2p.io/p2p/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa",
    "/dnsaddr/bootstrap.libp2p.io/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb",
    "/dnsaddr/bootstrap.libp2p.io/p2p/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt",
    "/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
    "/ip4/104.131.131.82/udp/4001/quic/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ"
  ],
  "DNS": {
    "Resolvers": {}
  },
  "Datastore": {
    "BloomFilterSize": 0,
    "GCPeriod": "1h",
    "HashOnRead": false,
    "Spec": {
      "mounts": [
        {
          "child": {
            "path": "blocks",
            "shardFunc": "/repo/flatfs/shard/v1/next-to-last/2",
            "sync": true,
            "type": "flatfs"
          },
          "mountpoint": "/blocks",
          "prefix": "flatfs.datastore",
          "type": "measure"
        },
        {
          "child": {
            "compression": "none",
            "path": "datastore",
            "type": "levelds"
          },
          "mountpoint": "/",
          "prefix": "leveldb.datastore",
          "type": "measure"
        }
      ],
      "type": "mount"
    },
    "StorageGCWatermark": 90,
    "StorageMax": "10GB"
  },
  "Discovery": {
    "MDNS": {
      "Enabled": true
    }
  },
  "Experimental": {
    "AcceleratedDHTClient": false,
    "FilestoreEnabled": false,
    "GraphsyncEnabled": false,
    "Libp2pStreamMounting": false,
    "P2pHttpProxy": false,
    "StrategicProviding": false,
    "UrlstoreEnabled": false
  },
  "Gateway": {
    "APICommands": [],
    "HTTPHeaders": {
      "Access-Control-Allow-Headers": [
        "X-Requested-With",
        "Range",
        "User-Agent"
      ],
      "Access-Control-Allow-Methods": [
        "GET"
      ],
      "Access-Control-Allow-Origin": [
        "*"
      ]
    },
    "NoDNSLink": false,
    "NoFetch": false,
    "PathPrefixes": [],
    "PublicGateways": null,
    "RootRedirect": "",
    "Writable": false
  },
  "Identity": {
    "PeerID": "12D3KooWKoXDZHg3yi8emjRpRoHYicDoPMSXXwA4u3NW6ntZVgSx"
  },
  "Internal": {},
  "Ipns": {
    "RecordLifetime": "",
    "RepublishPeriod": "",
    "ResolveCacheSize": 128
  },
  "Migration": {
    "DownloadSources": [],
    "Keep": ""
  },
  "Mounts": {
    "FuseAllowOther": false,
    "IPFS": "/ipfs",
    "IPNS": "/ipns"
  },
  "Peering": {
    "Peers": null
  },
  "Pinning": {
    "RemoteServices": {}
  },
  "Plugins": {
    "Plugins": null
  },
  "Provider": {
    "Strategy": ""
  },
  "Pubsub": {
    "DisableSigning": false,
    "Router": ""
  },
  "Reprovider": {},
  "Routing": {
    "Methods": null,
    "Routers": null
  },
  "Swarm": {
    "AddrFilters": null,
    "ConnMgr": {},
    "DisableBandwidthMetrics": false,
    "DisableNatPortMap": false,
    "RelayClient": {},
    "RelayService": {},
    "ResourceMgr": {},
    "Transports": {
      "Multiplexers": {},
      "Network": {},
      "Security": {}
    }
  }
}

Description

the header in the API responses is always:

Access-Control-Allow-Headers: X-Stream-Output, X-Chunked-Output, X-Content-Length

even though I've set:

ipfs config --json API.HTTPHeaders.Access-Control-Allow-Headers '["Authorization"]'

and even though it appears in ipfs config show:

  "API": {
    "HTTPHeaders": {
      "Access-Control-Allow-Headers": [
        "Authorization"
      ],
      "Access-Control-Allow-Origin": [
        "*"
      ],
      "Access-Control-Expose-Headers": [
        "Authorization"
      ]
    }
  },

My goal is to make a browser request with different origin that has the "Authorization" header, like doing this in the browser console:

 window.fetch('http://localhost:5001/api/v0/config?arg=Addresses.Gateway', {
  method: 'POST', 
  headers: {Authorization: 'Basic: ' + btoa('user:pass')}
})

I know I could use a proxy to strip the Authorization header, but I don't think it should be necessary.

@estebanabaroa estebanabaroa added kind/bug A bug in existing code (including security flaws) need/triage Needs initial labeling and prioritization labels Jan 24, 2023
@lidel lidel added the topic/rpc-api Issues related to Kubo RPC API at /api/v0 label Jan 30, 2023
@lidel
Copy link
Member

lidel commented Jan 30, 2023

Kubo RPC is designed to be private, does not support Basic Auth HTTP,
you need to set it up on a reverse proxy that sits in front of it.
Since that is where Authorization header is processed, you should also set/strip CORS headers there.

That being said, setting custom CORS for RPC (API.Access-Control-Allow-Headers) should be possible.

I believe Gateway already applies user override via AddAccessControlHeaders, seems RPC port is missing similar logic.

Note: low priority, if someone wants to submit PR, please wait until #8524 is complete.

@lidel lidel added P3 Low: Not priority right now and removed need/triage Needs initial labeling and prioritization labels Jan 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug A bug in existing code (including security flaws) P3 Low: Not priority right now topic/rpc-api Issues related to Kubo RPC API at /api/v0
Projects
None yet
Development

No branches or pull requests

2 participants