<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Content-Length &#8211; SMsoft &#8211; informatica e dintorni</title>
	<atom:link href="https://blog.smsoft.it/tag/content-length/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.smsoft.it</link>
	<description>consigli settimanali su MacOS, GNU/Linux ed Open Source</description>
	<lastBuildDate>Thu, 28 Aug 2025 20:29:48 +0000</lastBuildDate>
	<language>it-IT</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=67377</generator>
	<item>
		<title>Apache/PHP e l&#8217;header Content-Length sparito</title>
		<link>https://blog.smsoft.it/2025/03/25/apache-php-e-lheader-content-length-sparito/</link>
					<comments>https://blog.smsoft.it/2025/03/25/apache-php-e-lheader-content-length-sparito/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Tue, 25 Mar 2025 09:30:00 +0000</pubDate>
				<category><![CDATA[Html e PHP]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[Content-Length]]></category>
		<category><![CDATA[header]]></category>
		<category><![CDATA[php]]></category>
		<guid isPermaLink="false">https://blog.smsoft.it/?p=6684</guid>

					<description><![CDATA[Facendo alcuni test su degli script PHP è risultato che l&#8217;header Content-Length, seppur impostato, non veniva restituito da Apache. Dopo alcune ricerche è emerso che dalla versione 2.4.59, per gli script CGI-like (come PHP) non possono più restituire l&#8217;header Content-Length per motivi di sicurezza (rif CVE-2024-24795). Per ambienti sicuri è possibile ripristinare il precedente funzionamento ... <a title="Apache/PHP e l&#8217;header Content-Length sparito" class="read-more" href="https://blog.smsoft.it/2025/03/25/apache-php-e-lheader-content-length-sparito/" aria-label="Per saperne di più su Apache/PHP e l&#8217;header Content-Length sparito">Leggi tutto</a>]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">Facendo alcuni test su degli script <strong>PHP</strong> è risultato che l&#8217;header <strong>Content-Length</strong>, seppur impostato, non veniva restituito da <strong>Apache</strong>.</p>



<p class="wp-block-paragraph">Dopo alcune ricerche è emerso che dalla versione 2.4.59, per gli script CGI-like (come PHP) non possono più restituire l&#8217;header <strong>Content-Length</strong> per motivi di sicurezza (rif <a href="https://www.cve.org/CVERecord?id=CVE-2024-24795" target="_blank" rel="noreferrer noopener">CVE-2024-24795</a>).</p>



<p class="wp-block-paragraph">Per ambienti sicuri è possibile ripristinare il precedente funzionamento tramite una nuova direttiva di apache chiamata <a href="https://httpd.apache.org/docs/current/env.html#cgilike" target="_blank" rel="noreferrer noopener">ap_trust_cgilike_cl</a>.</p>



<p class="wp-block-paragraph">Per impostarla, creiamo un file chiamato <strong>/etc/apache2/conf-available/fix-cgi.conf</strong> con all&#8217;interno:</p>



<pre class="wp-block-code"><code>SetEnv ap_trust_cgilike_cl 1</code></pre>



<p class="wp-block-paragraph">e poi abilitiamolo con:</p>



<pre class="wp-block-code"><code>a2enconf fix-cgi
systemctl reload apache2</code></pre>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">enjoy!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.smsoft.it/2025/03/25/apache-php-e-lheader-content-length-sparito/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Apache+PHP: Content-Length header mancante</title>
		<link>https://blog.smsoft.it/2024/08/13/apachephp-content-length-header-mancante/</link>
					<comments>https://blog.smsoft.it/2024/08/13/apachephp-content-length-header-mancante/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Tue, 13 Aug 2024 08:30:00 +0000</pubDate>
				<category><![CDATA[Varie]]></category>
		<category><![CDATA[Accept-Ranges]]></category>
		<category><![CDATA[ap_trust_cgilike_cl]]></category>
		<category><![CDATA[Content-Length]]></category>
		<category><![CDATA[lazy loading]]></category>
		<category><![CDATA[pdfjs]]></category>
		<guid isPermaLink="false">https://blog.smsoft.it/?p=6390</guid>

					<description><![CDATA[Stavo lavorando su un File Manager PHP/JS che utilziza pdfjs per mostrare l&#8217;anteprima dei pdf. Inizialmente abbiamo caricato file molto grandi e funzionava tutto regolarmente, ma da qualche mese ci siamo trovati in difficoltà nel visualizzare i contenuti, perché il browser tentava di scaricare tutto il pdf prima di mostrarlo. Ho fatto una serie di ... <a title="Apache+PHP: Content-Length header mancante" class="read-more" href="https://blog.smsoft.it/2024/08/13/apachephp-content-length-header-mancante/" aria-label="Per saperne di più su Apache+PHP: Content-Length header mancante">Leggi tutto</a>]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">Stavo lavorando su un File Manager PHP/JS che utilziza <strong>pdfjs</strong> per mostrare l&#8217;anteprima dei pdf. Inizialmente abbiamo caricato <strong>file molto grandi</strong> e funzionava tutto regolarmente, ma da qualche mese ci siamo trovati in difficoltà nel visualizzare i contenuti, perché il browser tentava di <strong>scaricare tutto il pdf</strong> prima di mostrarlo.</p>



<p class="wp-block-paragraph">Ho fatto una serie di ricerche ed effettivamente <strong>pdfjs</strong> gestisce già da tempo il <strong>lazy loading</strong> dei pdf, grazie agli header <strong>Accept-Ranges</strong> e <strong>Content-Length</strong> e dopo qualche verifica mi sono accorto che effettivamente mancava l&#8217;header Content-Length nella risposta del server. Questo succede perché il file pdf non viene recuperato staticamente sul server, ma servito da uno script PHP che controlla se si hanno o meno i privilegi per visualizzarlo.</p>



<p class="wp-block-paragraph">A questo punto doveva essere cambiato qualcosa lato server; ho provato a controllare tra le segnalazioni per apache ed è saltata fuori questa cosa: <a href="https://bz.apache.org/bugzilla/show_bug.cgi?id=68973" target="_blank" rel="noreferrer noopener">#68973: Content-Length header missing in 2.4.59 is a breaking change</a>. In pratica con il rilascio di <strong>Apache 2.4.59</strong> è stato introdotto un fix di sicurezza per la segnalazione <a href="https://cve.mitre.org/cgi-bin/cvename.cgi?name=2024-24795" target="_blank" rel="noreferrer noopener">CVE-2024-24795</a> che serve a prevenire che script CGI (compreso PHP in modalità fpm) inviino l&#8217;header <strong>Content-Length</strong>.</p>



<p class="wp-block-paragraph">Fortunatamente c&#8217;è una variabile d&#8217;ambiente che possiamo impostare in apache per ripristinare il funzionamento precedente: <strong>ap_trust_cgilike_cl</strong>.</p>



<p class="wp-block-paragraph">Possiamo quindi creare un file chiamato <strong>/etc/apache2/conf-available/fix-content-length.conf</strong> con il seguente contenuto:</p>



<pre class="wp-block-code"><code>SetEnv ap_trust_cgilike_cl 1</code></pre>



<p class="wp-block-paragraph">e poi attivare la configurazione e riavviare il servizio apache:</p>



<pre class="wp-block-code"><code>a2enconf fix-content-length
systemctl reload apache2</code></pre>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">Se invece neanche le risorse statiche vengono servite correttamente se passato il parametro range, es:</p>



<pre class="wp-block-code"><code>curl https://www.smsoft.it/ -H "Range: bytes=0-8"</code></pre>



<p class="wp-block-paragraph">deve restituire solo <strong>&lt;!DOCTYPE</strong> mentre se invece restituisce tutta la pagina va installato anche <strong>mod_security</strong>:</p>



<pre class="wp-block-code"><code>apt install libapache2-mod-security2
a2enmod security2
systemctl restart apache2</code></pre>



<p class="wp-block-paragraph">assicurandosi che la direttiva <strong>SecResponseBodyAccess</strong> in <strong>/etc/modsecurity/modsecurity.conf</strong> sia impostata ad <strong>On</strong></p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">enjoy!</p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"></p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.smsoft.it/2024/08/13/apachephp-content-length-header-mancante/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
