Cabeçalho Access-Control-Allow-Origin ausente de uma resposta

3

Estou tentando depurar um problema.

Em um dos meus sites, os arquivos de fontes não estão sendo carregados corretamente. Alguém relatou esse erro no registro do inspetor:

Font from origin 'http://d1h0r2f9g9fk4d.cloudfront.net' has been 
blocked from loading by Cross-Origin Resource Sharing policy: No
'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'http://bit.ly/1Z4W4JZ' is therefore 
not allowed access.

A pessoa que está dizendo que ele não pode ver os arquivos de fontes também anexou esta captura de tela do site:

Vocêpodeverqueasfontes(quedevemsercaretsnãoestãoaparecendo).

Nessecaso,acreditoqueéincrívelafontequenãoestásendocarregadaparaele.

  • CloudfrontéoCDN
  • nGinxéaorigem(eestáenviandocorretamenteocabeçalhoAccess-Control-Allow-Origin)

Euexecuteiumcurl-v-Ievocêpodeverissocomoaresposta:

Minharespostadetrabalho

curl-v-Ihttp://d1h0r2f9g9fk4d.cloudfront.net/static/release/fonts/fontawesome-webfont.ttf?v=4.3.0*HostnamewasNOTfoundinDNScache*Trying54.230.149.120...*Connectedtod1h0r2f9g9fk4d.cloudfront.net(54.230.149.120)port80(#0)>HEAD/static/release/fonts/fontawesome-webfont.ttf?v=4.3.0HTTP/1.1>User-Agent:curl/7.35.0>Host:d1h0r2f9g9fk4d.cloudfront.net>Accept:*/*><HTTP/1.1200OKHTTP/1.1200OK<Content-Type:application/octet-streamContent-Type:application/octet-stream<Connection:keep-aliveConnection:keep-alive*Servernginx/1.4.6(Ubuntu)isnotblacklisted<Server:nginx/1.4.6(Ubuntu)Server:nginx/1.4.6(Ubuntu)<Date:Wed,06Jan201609:33:59GMTDate:Wed,06Jan201609:33:59GMT<Last-Modified:Tue,09Jun201510:46:31GMTLast-Modified:Tue,09Jun201510:46:31GMT<ETag:"5576c407-1dcec"
ETag: "5576c407-1dcec"
< Expires: Thu, 04 Feb 2016 18:03:03 GMT
Expires: Thu, 04 Feb 2016 18:03:03 GMT
< Cache-Control: max-age=2592000
Cache-Control: max-age=2592000
< X-Varnish: 2146103981 2146009331
X-Varnish: 2146103981 2146009331
< Age: 55857
Age: 55857
< Via: 1.1 varnish, 1.1 f836ea1710367746c54dbe5fbb422013.cloudfront.net (CloudFront)
Via: 1.1 varnish, 1.1 f836ea1710367746c54dbe5fbb422013.cloudfront.net (CloudFront)
< X-Hashed-On: /static/release/fonts/fontawesome-webfont.ttf?v=4.3.0*cdn.rentivo.com
X-Hashed-On: /static/release/fonts/fontawesome-webfont.ttf?v=4.3.0*cdn.rentivo.com
< X-Discovery: not-set
X-Discovery: not-set
< X-Cache-Lookup: lookup
X-Cache-Lookup: lookup
< X-Cachable: 1
X-Cachable: 1
< Access-Control-Allow-Origin: *
Access-Control-Allow-Origin: *
< X-Cache: Miss from cloudfront
X-Cache: Miss from cloudfront
< X-Amz-Cf-Id: UlVhI7Nix19cnSqakrZ3dqVta9ROM8thQ9c0rixacW-dZpC9wCCe4Q==
X-Amz-Cf-Id: UlVhI7Nix19cnSqakrZ3dqVta9ROM8thQ9c0rixacW-dZpC9wCCe4Q==

< 
* Connection #0 to host d1h0r2f9g9fk4d.cloudfront.net left intact

Você pode ver claramente que Access-Control-Allow-Origin: * está presente nos cabeçalhos de fonte.

Eu tentei invalidar a distribuição do Cloudfront, pensando, talvez o servidor de borda tenha uma versão antiga que não tenha esses cabeçalhos, mas a pessoa ainda está dizendo que não conseguiu visualizar os cabeçalhos.

Pedi a ele que fizesse um diário para mim e essa foi a resposta dele.

Sua resposta falhada

curl -v -I http://d1h0r2f9g9fk4d.cloudfront.net/static/release/fonts/fontawesome-webfont.ttf?v=4.3.0
*   Trying 54.230.149.120...
* Connected to d1h0r2f9g9fk4d.cloudfront.net (54.230.149.120) port 80 (#0)
> HEAD /static/release/fonts/fontawesome-webfont.ttf?v=4.3.0 HTTP/1.1
> Host: d1h0r2f9g9fk4d.cloudfront.net
> User-Agent: curl/7.43.0
> Accept: */*
> 
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Content-Encoding: gzip
Content-Encoding: gzip
< Content-Length: 71646
Content-Length: 71646
< Content-Type: application/octet-stream
Content-Type: application/octet-stream
< ETag: "5576c407-1dcec"
ETag: "5576c407-1dcec"
< Server: nginx/1.4.6 (Ubuntu)
Server: nginx/1.4.6 (Ubuntu)
< Expires: Wed, 03 Feb 2016 10:08:00 GMT
Expires: Wed, 03 Feb 2016 10:08:00 GMT
< Last-Modified: Tue, 09 Jun 2015 10:46:31 GMT
Last-Modified: Tue, 09 Jun 2015 10:46:31 GMT
< Connection: keep-alive
Connection: keep-alive
< Date: Wed, 06 Jan 2016 01:04:10 GMT
Date: Wed, 06 Jan 2016 01:04:10 GMT

< 
* Connection #0 to host d1h0r2f9g9fk4d.cloudfront.net left intact

NÃO consigo entender o que está acontecendo. Poderia seu ISP estar realizando alguma ridícula espionagem / otimização nele? Se você notar, as respostas do cabeçalho nem sequer correspondem. Você iria pelo menos esperar ver

< X-Cache: Miss from cloudfront
X-Cache: Miss from cloudfront
< X-Amz-Cf-Id: UlVhI7Nix19cnSqakrZ3dqVta9ROM8thQ9c0rixacW-dZpC9wCCe4Q==
X-Amz-Cf-Id: UlVhI7Nix19cnSqakrZ3dqVta9ROM8thQ9c0rixacW-dZpC9wCCe4Q==

Tudo isso está faltando.

Alguém tem alguma ideia?

    
por Laykes 06.01.2016 / 10:39

1 resposta

2

Resposta tardia, mas tropeçou neste tópico enquanto lutava com o mesmo problema.

Tente adicionar um cabeçalho de origem à sua solicitação de curl; isso resolveu para mim - algo como:

curl -v -I "http://d1h0r2f9g9fk4d.cloudfront.net/static/release/fonts/fontawesome-webfont.ttf?v=4.3.0" -H "Origin: https://example.com"
    
por 27.07.2016 / 18:54