CodeSampleX

Exemplo

github.com/go-chi/chi/v5 5.3.1: Extract client IP from X-Forwarded-For with go-chi middleware without assuming unconfigured trusted prefixes extract the leftmost IP or mutate RemoteAddr

Amostra verificada para golang github.com/go-chi/chi/v5 5.3.1: Extract client IP from X-Forwarded-For with go-chi middleware without assuming unconfigured…

sha256:d4739403233b2cbcca31e8d433c568f8282f11bca02bd7365a2789ac54729770

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
2
Chaves de assinatura que o compilaram
2
Ambiente declarado go linux x64 go go gomod

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
go 1.26 · linux alpine/x64 · docker ed25519:d91480838ac982c9 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1
2026-08-16
go 1.26 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1
2026-08-18

Caso

HOW
Objetivo
Extract client IP from X-Forwarded-For with go-chi middleware without assuming unconfigured trusted prefixes extract the leftmost IP or mutate RemoteAddr
Pacotes
Símbolos
  • middleware.ClientIPFromXFF
  • middleware.GetClientIP
  • middleware.GetClientIPAddr
Ambiente
go
Criado
2026-08-16T13:25:20Z

Contrato

  1. assert ClientIPFromXFF with unset trusted prefixes returns the rightmost XFF hop rather than the leftmost client IP
  2. assert ClientIPFromXFF leaves RemoteAddr unmodified and stores the resolved IP in context
  3. assert ClientIPFromXFF with explicit trusted CIDR prefixes skips trusted hops to extract the originating client IP
  4. assert ClientIPFromXFF fails closed returning an empty IP when encountering an invalid hop in the chain
  5. assert ClientIPFromXFF merges multiple X-Forwarded-For headers and evaluates hops right to left

Arquivos

  • NOTES.md
  • clientip.go
  • clientip_test.go
  • csx.json
  • go.mod
  • go.sum

Baixar o artefato de código-fonte (tar.gz)

Seeder de origem

csx-seed