AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • Início
  • system&network
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • Início
  • system&network
    • Recentes
    • Highest score
    • tags
  • Ubuntu
    • Recentes
    • Highest score
    • tags
  • Unix
    • Recentes
    • tags
  • DBA
    • Recentes
    • tags
  • Computer
    • Recentes
    • tags
  • Coding
    • Recentes
    • tags
Início / server / Perguntas / 1168561
Accepted
Matthias Ronge
Matthias Ronge
Asked: 2024-12-06 00:30:36 +0800 CST2024-12-06 00:30:36 +0800 CST 2024-12-06 00:30:36 +0800 CST

Como impedir que o Apache retorne uma linha errada antes do cabeçalho HTML quebrá-lo

  • 772

Eu uso um site simples habilitado para publicar arquivos no Apache:

Arquivo:/etc/apache2/sites-enabled/contents.conf
<Directory "/mnt/data/contents/">

        Options FollowSymLinks

        Require all granted

        <IfModule mod_expires.c>
                ExpiresActive on
                ExpiresDefault "access plus 7 days"
        </IfModule>
</Directory>

Os arquivos são XML simples, um exemplo começa com estas linhas:

<mets:mets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:xlink="http://www.w3.org/1999/xlink"
           xmlns:kitodo="http://meta.kitodo.org/v1/"

Quando baixo o arquivo localmente, wgetele reclama da falta de cabeçalhos :

user@myhostname:~$ wget http://myhostname/contents/example/example.xml
--2024-12-05 16:14:59--  http://myhostname/contents/example/example.xml
Resolving myhostname (myhostname)... 127.0.1.1
Connecting to myhostname (myhostname)|127.0.1.1|:80... connected.
HTTP request sent, awaiting response... 200 No headers, assuming HTTP/0.9
Length: unspecified
Saving to: ‘example.xml’

example.xml                                        [      <=>                                                                                                                                ]  12,66K  --.-KB/s    in 4,8s

2024-12-05 16:15:04 (2,66 KB/s) - ‘example.xml’ saved [12966]

O arquivo baixado começa assim:

 12:25:45 GMT
Accept-Ranges: bytes
Content-Length: 12563
Cache-Control: max-age=0
Expires: Thu, 05 Dec 2024 09:45:44 GMT
Vary: Accept-Encoding
X-Content-Type-Options: nosniff
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: application/xml; charset=utf-8

<mets:mets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:xlink="http://www.w3.org/1999/xlink"
           xmlns:kitodo="http://meta.kitodo.org/v1/"

Obviamente a primeira linha não pertence ali e impede que os cabeçalhos HTTP sejam reconhecidos corretamente. De onde vem a linha e como posso desligá-la? Não experimento nada parecido com isso em outros sistemas.

Versão do servidor: Apache/2.4.41 (Ubuntu)

Módulos carregados:
core_module (estático)
so_module (estático)
watchdog_module (estático)
http_module (estático)
log_config_module (estático)
logio_module (estático)
version_module (estático)
unixd_module (estático
) access_compat_module (compartilhado
) alias_module (compartilhado)
auth_basic_module (compartilhado
) authn_core_module (compartilhado)
authn_file_module (compartilhado)
authnz_ldap_module
(compartilhado)
authz_core_module (compartilhado) authz_host_module
(compartilhado) authz_user_module (compartilhado)
autoindex_module (compartilhado)
dav_module (compartilhado)
dav_fs_module (compartilhado)
deflate_module (compartilhado)
dir_module (compartilhado)
env_module (compartilhado)
expires_module (compartilhado)
filter_module (compartilhado
) headers_module (
compartilhado) jk_module (
compartilhado) ldap_module (compartilhado
) mime_module (compartilhado
) mpm_prefork_module (compartilhado)
negotiation_module (compartilhado)
php7_module (compartilhado)
reqtimeout_module (compartilhado)
rewrite_module (compartilhado)
setenvif_module (compartilhado)
socache_shmcb_module (compartilhado)
ssl_module (compartilhado)
status_module (compartilhado)

Arquivo: /etc/apache2/sites-enabled/000-default.conf(comentários removidos)
<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/typo3/public

        <Directory /var/www/typo3/public/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        JkMount /kitodo ajp13_worker
        JkMount /kitodo/* ajp13_worker
        <Location /kitodo>
                Order allow,deny
                Allow from all
        </Location>
</VirtualHost>
Arquivo: /etc/apache2/sites-enabled/default-ssl.conf(comentários removidos)
<IfModule mod_ssl.c>
        <VirtualHost _default_:443>
                ServerAdmin webmaster@localhost

                DocumentRoot /var/www/html

                ErrorLog ${APACHE_LOG_DIR}/error.log
                CustomLog ${APACHE_LOG_DIR}/access.log combined

                SSLEngine on
                SSLCertificateFile      /etc/ssl/certs/ssl-cert-snakeoil.pem
                SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key

                <FilesMatch "\.(cgi|shtml|phtml|php)$">
                                SSLOptions +StdEnvVars
                </FilesMatch>
                <Directory /usr/lib/cgi-bin>
                                SSLOptions +StdEnvVars
                </Directory>
        </VirtualHost>
</IfModule>

Editar: Saída de curl -i:

user@myhostname:~# curl -i http://myhostname/contents/example/example.xml
curl: (1) Received HTTP/0.9 when not allowed

Saída dewget -O - -o /dev/null --save-headers

 09:41:43 GMT
Accept-Ranges: bytes
Content-Length: 10971
Cache-Control: max-age=0
Expires: Mon, 09 Dec 2024 08:22:33 GMT
Vary: Accept-Encoding
X-Content-Type-Options: nosniff
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: application/xml; charset=utf-8

(...)
ataTable:11:inputText&quot;,onco:function(xhr,status,args,data){preserveMetadata(); updateTitleMetadata();;}});" /><s

(...)representa o conteúdo do arquivo XML. Também vejo que há conteúdo no final que também não deveria estar ali. Reconheço esse conteúdo como parte do aplicativo da web incluído por meio do JkMount. E o conteúdo na última linha também é diferente a cada solicitação.

Saída de tcpdump -vv -i any -s 0 'tcp port http'(espero ter escrito as falas certas, porque há pessoas trabalhando no servidor enquanto isso):

09:15:05.940645 IP (tos 0x0, ttl 64, id 26047, offset 0, flags [DF], proto TCP (6), length 60)
    localhost.60850 > myhostname.http: Flags [S], cksum 0xff30 (incorrect -> 0x75f8), seq 4023966924, win 65495, options [mss 65495,sackOK,TS val 2467400527 ecr 0,nop,wscale 7], length 0
09:15:05.940660 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto TCP (6), length 60)
    myhostname.http > localhost.60850: Flags [S.], cksum 0xff30 (incorrect -> 0xbe63), seq 1059986559, ack 4023966925, win 65483, options [mss 65495,sackOK,TS val 1084365632 ecr 2467400527,nop,wscale 7], length 0
09:15:05.940673 IP (tos 0x0, ttl 64, id 26048, offset 0, flags [DF], proto TCP (6), length 52)
    localhost.60850 > myhostname.http: Flags [.], cksum 0xff28 (incorrect -> 0xe51f), seq 1, ack 1, win 512, options [nop,nop,TS val 2467400527 ecr 1084365632], length 0
09:15:05.940703 IP (tos 0x0, ttl 64, id 26049, offset 0, flags [DF], proto TCP (6), length 241)
    localhost.60850 > myhostname.http: Flags [P.], cksum 0xffe5 (incorrect -> 0x771f), seq 1:190, ack 1, win 512, options [nop,nop,TS val 2467400527 ecr 1084365632], length 189: HTTP, length: 189
        GET /contents/example/example.xml HTTP/1.1
        User-Agent: Wget/1.20.3 (linux-gnu)
        Accept: */*
        Accept-Encoding: identity
        Host: myhostname
        Connection: Keep-Alive

09:15:05.940721 IP (tos 0x0, ttl 64, id 2993, offset 0, flags [DF], proto TCP (6), length 52)
    myhostname.http > localhost.60850: Flags [.], cksum 0xff28 (incorrect -> 0xe463), seq 1, ack 190, win 511, options [nop,nop,TS val 1084365632 ecr 2467400527], length 0
09:15:05.946161 IP (tos 0x0, ttl 64, id 2994, offset 0, flags [DF], proto TCP (6), length 11426)
    myhostname.http > localhost.60850: Flags [P.], cksum 0x2b97 (incorrect -> 0xe10f), seq 1:11375, ack 190, win 512, options [nop,nop,TS val 1084365637 ecr 2467400527], length 11374: HTTP
09:15:05.946180 IP (tos 0x0, ttl 64, id 26050, offset 0, flags [DF], proto TCP (6), length 52)
    localhost.60850 > myhostname.http: Flags [.], cksum 0xff28 (incorrect -> 0xb81b), seq 190, ack 11375, win 463, options [nop,nop,TS val 2467400532 ecr 1084365637], length 0
09:15:10.951973 IP (tos 0x0, ttl 64, id 2995, offset 0, flags [DF], proto TCP (6), length 52)
    myhostname.http > localhost.60850: Flags [F.], cksum 0xff28 (incorrect -> 0xa45b), seq 11375, ack 190, win 512, options [nop,nop,TS val 1084370643 ecr 2467400532], length 0
09:15:10.952765 IP (tos 0x0, ttl 64, id 26051, offset 0, flags [DF], proto TCP (6), length 52)
    localhost.60850 > myhostname.http: Flags [F.], cksum 0xff28 (incorrect -> 0x90cb), seq 190, ack 11376, win 512, options [nop,nop,TS val 2467405539 ecr 1084370643], length 0
09:15:10.952792 IP (tos 0x0, ttl 64, id 2996, offset 0, flags [DF], proto TCP (6), length 52)
    myhostname.http > localhost.60850: Flags [.], cksum 0xff28 (incorrect -> 0x90ca), seq 11376, ack 191, win 512, options [nop,nop,TS val 1084370644 ecr 2467405539], length 0

Você pode ver que as três últimas entradas aparecem exatamente 5 segundos depois, o que é o material não relacionado na parte inferior.


Descobertas adicionais importantes:

  • Pasta da Web completamente esvaziada, nenhum arquivo .htaccess pode ser reproduzido nela.

  • O comportamento não ocorre se o arquivo XML for recuperado por meio de uma consulta compactada (Accept-Encoding gzip)

  • Se eu remover 'security.conf' de 'conf-enabled', obtenho uma primeira linha de saída ligeiramente diferente (mas ainda errada): st-Modified: Thu, 28 Nov 2024 09:41:43 GMT[sic!]

  • O comportamento só ocorre se o arquivo XML for baixado por meio de um link simbólico na pasta da web que aponta para um ponto de montagem CIFS, não se ele estiver localizado diretamente na pasta

apache-2.4
  • 1 1 respostas
  • 94 Views

1 respostas

  • Voted
  1. Best Answer
    Matthias Ronge
    2024-12-10T15:04:33+08:002024-12-10T15:04:33+08:00

    Não conseguimos encontrar o verdadeiro motivo e consertá-lo. Atualizamos o bom e velho Ubuntu 20 para o Ubuntu 22 agora, e agora o problema desapareceu. É triste dizer que não posso dar uma resposta melhor.

    • 0

relate perguntas

  • O que significa %{REQUEST_FILENAME}.ext? Por que o final .ext extra?

  • Por que meu Apache é capaz de servir 200 arquivos .php que incluem uma barra final?

Sidebar

Stats

  • Perguntas 205573
  • respostas 270741
  • best respostas 135370
  • utilizador 68524
  • Highest score
  • respostas
  • Marko Smith

    Você pode passar usuário/passar para autenticação básica HTTP em parâmetros de URL?

    • 5 respostas
  • Marko Smith

    Ping uma porta específica

    • 18 respostas
  • Marko Smith

    Verifique se a porta está aberta ou fechada em um servidor Linux?

    • 7 respostas
  • Marko Smith

    Como automatizar o login SSH com senha?

    • 10 respostas
  • Marko Smith

    Como posso dizer ao Git para Windows onde encontrar minha chave RSA privada?

    • 30 respostas
  • Marko Smith

    Qual é o nome de usuário/senha de superusuário padrão para postgres após uma nova instalação?

    • 5 respostas
  • Marko Smith

    Qual porta o SFTP usa?

    • 6 respostas
  • Marko Smith

    Linha de comando para listar usuários em um grupo do Windows Active Directory?

    • 9 respostas
  • Marko Smith

    O que é um arquivo Pem e como ele difere de outros formatos de arquivo de chave gerada pelo OpenSSL?

    • 3 respostas
  • Marko Smith

    Como determinar se uma variável bash está vazia?

    • 15 respostas
  • Martin Hope
    Davie Ping uma porta específica 2009-10-09 01:57:50 +0800 CST
  • Martin Hope
    kernel O scp pode copiar diretórios recursivamente? 2011-04-29 20:24:45 +0800 CST
  • Martin Hope
    Robert ssh retorna "Proprietário incorreto ou permissões em ~/.ssh/config" 2011-03-30 10:15:48 +0800 CST
  • Martin Hope
    Eonil Como automatizar o login SSH com senha? 2011-03-02 03:07:12 +0800 CST
  • Martin Hope
    gunwin Como lidar com um servidor comprometido? 2011-01-03 13:31:27 +0800 CST
  • Martin Hope
    Tom Feiner Como posso classificar a saída du -h por tamanho 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich O que é um arquivo Pem e como ele difere de outros formatos de arquivo de chave gerada pelo OpenSSL? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent Como determinar se uma variável bash está vazia? 2009-05-13 09:54:48 +0800 CST

Hot tag

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • Início
  • Perguntas
    • Recentes
    • Highest score
  • tag
  • help

Footer

AskOverflow.Dev

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve