<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[FrontAccounting forum — Various FA Vulnerabilities that need to be addressed]]></title>
		<link>https://frontaccounting.com/punbb/viewtopic.php?id=6715</link>
		<atom:link href="https://frontaccounting.com/punbb/extern.php?action=feed&amp;tid=6715&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Various FA Vulnerabilities that need to be addressed.]]></description>
		<lastBuildDate>Sun, 19 Mar 2017 15:41:17 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Various FA Vulnerabilities that need to be addressed]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=27610#p27610</link>
			<description><![CDATA[<p>This issue is now fully <strong>fixed</strong> in both versions in the official repo.</p><p>Those using the <strong>dashboard theme/extension</strong> and the <strong>dynamic</strong> and <strong>exclusive</strong> themes can make similar changes in the following files for FA 2.3 and where appropriate in the themes in FA 2.4:</p><p>Extensions</p><p>Line 92 in dashboard/widgets/customers.php - <em>$filename = company_path(). &quot;/pdf_files/&quot;. uniqid(&quot;&quot;).&quot;.png&quot;;</em><br />Line 92 in dashboard/widgets/dimensions.php - <em>$filename = company_path(). &quot;/pdf_files/&quot;. uniqid(&quot;&quot;).&quot;.png&quot;;</em><br />Line 97 in dashboard/widgets/glreturn.php - <em>$filename = company_path(). &quot;/pdf_files/&quot;. uniqid(&quot;&quot;).&quot;.png&quot;;</em><br />Line 98 in dashboard/widgets/items.php - <em>$filename = company_path(). &quot;/pdf_files/&quot;. uniqid(&quot;&quot;).&quot;.png&quot;;</em><br />Line 92 in dashboard/widgets/suppliers.php - <em>$filename = company_path(). &quot;/pdf_files/&quot;. uniqid(&quot;&quot;).&quot;.png&quot;;</em></p><p>Line 93 in import_transactions/includes/import_sales_cart_class.inc - <em>$this-&gt;cart_id = uniqid(&#039;&#039;);</em> - Localised, so no change needed</p><p>Themes</p><p>Lines 306, 405, 506, 560, 623 in dynamic/renderer.php - <em>$filename = company_path(). &quot;/pdf_files/&quot;. uniqid(&quot;&quot;).&quot;.png&quot;;</em><br />Lines 265, 364, 465, 519, 582 in exclusive/renderer.php - <em>$filename = company_path(). &quot;/pdf_files/&quot;. uniqid(&quot;&quot;).&quot;.png&quot;;</em></p><p>The official repo for extension distribution for FA 2.3 will not be updated since it is EOL and if done will affect those with non-bleeding edge installs.</p>]]></description>
			<author><![CDATA[null@example.com (apmuthu)]]></author>
			<pubDate>Sun, 19 Mar 2017 15:41:17 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=27610#p27610</guid>
		</item>
		<item>
			<title><![CDATA[Re: Various FA Vulnerabilities that need to be addressed]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=27609#p27609</link>
			<description><![CDATA[<p>Consistent Excel Report download SOLVED!</p><p>First we need to include the <strong>fix in post 4</strong> of this thread.<br />The issue of filenames starting with a hyphen or underscore may need to be addressed.<br />The <strong>function clean_file_name()</strong> in <strong>includes/main.inc</strong> can also do the job.</p><p>Since we are now allowing underscores(_) and hyphens (-) in the random_id()&#039;s filenames, we need to allow it for excel filenames for download too.</p><p>Lines 30 to 55 in FA 2.3&#039;s <strong>reporting/prn_redirect.php</strong>:<br /></p><div class="codebox"><pre><code>if (isset($_GET[&#039;xls&#039;]))
{
    $filename = $_GET[&#039;filename&#039;];
    $unique_name = preg_replace(&#039;/[^0-9a-z.]/i&#039;, &#039;&#039;, $_GET[&#039;unique&#039;]);
    $path =  company_path(). &#039;/pdf_files/&#039;;
    header(&quot;Content-type: application/vnd.ms-excel&quot;);
    header(&quot;Content-Disposition: attachment; filename=$filename&quot; );
    header(&quot;Expires: 0&quot;);
    header(&quot;Cache-Control: must-revalidate, post-check=0,pre-check=0&quot;);
    header(&quot;Pragma: public&quot;);
    echo file_get_contents($path.$unique_name);
    exit();
}
elseif (isset($_GET[&#039;xml&#039;]))
{
    $filename = $_GET[&#039;filename&#039;];
    $unique_name = preg_replace(&#039;/[^0-9a-z.]/i&#039;, &#039;&#039;, $_GET[&#039;unique&#039;]);
    $path =  company_path(). &#039;/pdf_files/&#039;;
    header(&quot;content-type: text/xml&quot;);
    header(&quot;Content-Disposition: attachment; filename=$filename&quot;);
    header(&quot;Expires: 0&quot;);
    header(&quot;Cache-Control: must-revalidate, post-check=0,pre-check=0&quot;);
    header(&quot;Pragma: public&quot;);
    echo file_get_contents($path.$unique_name);
    exit();
}</code></pre></div><p>can be replaced with:<br /></p><div class="codebox"><pre><code>if (isset($_GET[&#039;xls&#039;]) || isset($_GET[&#039;xml&#039;]))
{
    $filename = $_GET[&#039;filename&#039;];
    $unique_name = preg_replace(&quot;/[^0-9_a-z.\-]/i&quot;, &#039;&#039;, $_GET[&#039;unique&#039;]);
    $path =  company_path(). &#039;/pdf_files/&#039;;
    if (isset($_GET[&#039;xls&#039;])) header(&quot;Content-type: application/vnd.ms-excel&quot;);
    else header(&quot;content-type: text/xml&quot;);
    header(&quot;Content-Disposition: attachment; filename=$filename&quot; );
    header(&quot;Expires: 0&quot;);
    header(&quot;Cache-Control: must-revalidate, post-check=0,pre-check=0&quot;);
    header(&quot;Pragma: public&quot;);
    echo file_get_contents($path.$unique_name);
    exit();
}</code></pre></div><p>@joe: please update both repos.</p><p>PHP PCRE (Regular Expressions) - <a href="http://webcheatsheet.com/php/regular_expressions.php">CheatSheet</a> | <a href="http://www.rexegg.com/regex-php.html">Tutorial</a>.</p>]]></description>
			<author><![CDATA[null@example.com (apmuthu)]]></author>
			<pubDate>Sun, 19 Mar 2017 11:24:51 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=27609#p27609</guid>
		</item>
		<item>
			<title><![CDATA[Re: Various FA Vulnerabilities that need to be addressed]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=27608#p27608</link>
			<description><![CDATA[<p>The current commits for this issue breaks excel report formation consistency. Zero byte excel file downloads occur frequently and sometimes it works correctly.</p><p>The file <strong>includes/main.inc</strong> is &quot;included&quot; in the <strong>includes/session.inc</strong> file (apart from during installation in the <strong>install/isession.inc</strong>). It may have been possible that the file redirection (<strong>reporting/prn_redirect.php</strong>) to download the excel file did not have this initially - the said session file seems included though.</p><p>Line 719 in <strong>reporting/excel_report.inc</strong>:<br /></p><div class="codebox"><pre><code>        meta_forward($path_to_root.&#039;/reporting/prn_redirect.php&#039;, &quot;xls=1&amp;filename=$this-&gt;filename&amp;unique=$this-&gt;unique_name&quot;);</code></pre></div><p>causes the redirection to download the excel file.</p><p>Line 33 in <strong>reporting/prn_redirect.php</strong>:<br /></p><div class="codebox"><pre><code>    $unique_name = preg_replace(&#039;/[^0-9a-z.]/i&#039;, &#039;&#039;, $_GET[&#039;unique&#039;]);</code></pre></div><p>seems to do some replacements that affect the downloaded filename. </p><p>@itronics / @joe: Is this necessary in the light of the current commits?</p>]]></description>
			<author><![CDATA[null@example.com (apmuthu)]]></author>
			<pubDate>Sun, 19 Mar 2017 10:18:36 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=27608#p27608</guid>
		</item>
		<item>
			<title><![CDATA[Re: Various FA Vulnerabilities that need to be addressed]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=27607#p27607</link>
			<description><![CDATA[<p>@itronics: please replace line 372 in FA 2.3&#039;s <strong>includes/main.inc</strong>:<br /></p><div class="codebox"><pre><code>    $id = strtr(base64_encode($bin), &#039;+/&#039;, &#039;-_&#039;);    // see RFC 4648 Section 5</code></pre></div><p>with<br /></p><div class="codebox"><pre><code>    $id = strtr(base64_encode($bin), &#039;+/=&#039;, &#039;-_x&#039;);    // see RFC 4648 Section 5</code></pre></div><p>and likewise in FA 2.4. The pad character &quot;=&quot; can be got rid off this way.<br />Before your commit, it was a 13 character file base name and it is now 24 (multiples of 8).<br />The original filename was like:<br />&nbsp; &nbsp; <em>dLPhO1A-K5vj5Dq4NxBA7w==.pdf</em><br />and the new file name will be like:<br />&nbsp; &nbsp; <strong>4vuNUMXvAVsQVuHEVzlrdwxx.pdf</strong></p><p>** Fixed in <a href="https://github.com/FrontAccountingERP/FA/commit/4e6811018489ed5d9e4c029342c958e266d7b298#diff-0573610df5937776b894248f8d930d41">FA 2.3</a> and <a href="https://github.com/FrontAccountingERP/FA/commit/f6064e8aa959aa1f9c3f35de524a641019e853ab#diff-0573610df5937776b894248f8d930d41">FA 2.4</a> commits.</p>]]></description>
			<author><![CDATA[null@example.com (apmuthu)]]></author>
			<pubDate>Sun, 19 Mar 2017 09:22:21 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=27607#p27607</guid>
		</item>
		<item>
			<title><![CDATA[Re: Various FA Vulnerabilities that need to be addressed]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=27606#p27606</link>
			<description><![CDATA[<p>As of 2015: <a href="https://bugs.php.net/bug.php?id=70014">PHP bug #70014</a> affects the reliability of <strong>openssl_random_pseudo_bytes()</strong>. <a href="https://github.com/paragonie/random_compat">paragonie/random_compat</a>, backports <em>random_bytes()</em> from PHP 7 into PHP 5. One of the fallbacks it supports is <em>openssl_random_pseudo_bytes()</em>, but if it can read directly from <em>/dev/urandom</em> it will prefer that instead.</p><p>As of 2016: There&#039;s another bug with <strong>openssl_random_pseudo_bytes()</strong> (<a href="https://bugs.php.net/bug.php?id=71915">71915</a>), which can result in duplicate values when you run it multiple times with the same process ID. Looks like it&#039;s fixed in 5.6.24.</p>]]></description>
			<author><![CDATA[null@example.com (apmuthu)]]></author>
			<pubDate>Sat, 18 Mar 2017 18:19:27 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=27606#p27606</guid>
		</item>
		<item>
			<title><![CDATA[Re: Various FA Vulnerabilities that need to be addressed]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=27605#p27605</link>
			<description><![CDATA[<p>@itronics: Thanks for the quick commits in <a href="https://github.com/FrontAccountingERP/FA/commit/06a878fac8f2aa889ee481a22bc9f68fef1f7c8b">FA 2.3</a> and <a href="https://github.com/FrontAccountingERP/FA/commit/c57a65eca46110b7e4a865dc2b007c1fd75838c3">FA 2.4</a>. There seem to be some files left out.</p><p>The file <strong>includes/main.inc</strong> is expected to be included in every instance where it is used as the new function random_id() is defined there and it refers to a variable <strong>$cstrong</strong> which is not assigned yet. This is <strong>mostly</strong> okay as it is a <a href="http://php.net/manual/en/function.openssl-random-pseudo-bytes.php">return diagnostics value</a> only. If there are any errors then just assign it a blank string before invocation as it is passed by reference.</p><p>The following files too use <strong>uniqid</strong> still and no changes in them yet in the commit done now:<br />1. includes/ui/ui_view.inc - <em>$name = uniqid(&#039;_el&#039;,true);</em><br />2. reporting/includes/class.mail.inc - <em>$this-&gt;boundary = md5(uniqid(time()));</em><br />3. reporting/includes/tcpdf.inc - <em>$owner_pass = uniqid(rand());</em></p><p>4. sales/includes/cart_class.inc - <em>$this-&gt;cart_id = uniqid(&#039;&#039;);</em> - This is just temporary cart id used to avoid erroneous concurrent edition inside single user session. This is not used in urls, so the security problem does not apply here.</p><p>In FA 2.4 additionally:<br />1. includes/dashboard.inc - <em>$filename = company_path(). &quot;/pdf_files/&quot;. uniqid(&quot;&quot;).&quot;.png&quot;;</em> - Fixed in <a href="https://github.com/FrontAccountingERP/FA/commit/020b23ce2e531ee516882266e9f7feeb02578bbc">this commit</a>.</p><p>When changes are made to the files above, we need to make sure that the said new function <strong>random_id()</strong> is available therein. Those using it in extensions and using SOAP / RESTful APIs too need to take care by defining the function if it dows not exists at the point of invocation.</p>]]></description>
			<author><![CDATA[null@example.com (apmuthu)]]></author>
			<pubDate>Sat, 18 Mar 2017 16:15:33 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=27605#p27605</guid>
		</item>
		<item>
			<title><![CDATA[Various FA Vulnerabilities that need to be addressed]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=27603#p27603</link>
			<description><![CDATA[<p><a href="http://securitymaverick.com/tag/php/">SecurityMaverick.com</a> has listed a few and one such code that limits entropy is <a href="http://securitymaverick.com/php-uniqid-entropy-analysis-and-potentially-vulnerable-apps/front-accounting-code/">here</a>.</p><p>Line 973 in <strong>reporting/includes/pdf_report.inc</strong>:<br /></p><div class="codebox"><pre><code>                $fname = $dir.&#039;/&#039;.uniqid(&#039;&#039;).&#039;.pdf&#039;;</code></pre></div><p>can be changed to<br /></p><div class="codebox"><pre><code>                $fname = $dir.&#039;/&#039;.md5(uniqid(mt_rand(), true)).&#039;.pdf&#039;;</code></pre></div><p>This improves the entropy from 10 to 29 bits but is still not good enough and is used in line 69 of <strong>includes/ui/ui_controls.inc</strong>.</p><p>Other places like this are in some repXXX.php files:<br /></p><div class="codebox"><pre><code>$filename = company_path(). &quot;/pdf_files/&quot;. uniqid(&quot;&quot;).&quot;.png&quot;;</code></pre></div><p>that need similar changes. Several others files in FA use <strong>uniqid</strong> too and will need some changes like this.</p><div class="quotebox"><blockquote><p>With or without the more_entropy option, uniqid(), as represented in the PHP sample code and documentation, results in poor entropy and should not be used.</p></blockquote></div><p>@joe: can we include this in both repos?</p>]]></description>
			<author><![CDATA[null@example.com (apmuthu)]]></author>
			<pubDate>Sat, 18 Mar 2017 10:20:07 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=27603#p27603</guid>
		</item>
	</channel>
</rss>
