Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions familyconnections/addressbook.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,33 @@ function displayExportSubmit ()
return;
}

$csv = "lname, fname, address, city, state, zip, email, home, work, cell\015\012";
$csv = '';
$handle = fopen('php://temp', 'w+');

if ($handle !== false)
{
fputcsv($handle, array('lname', 'fname', 'address', 'city', 'state', 'zip', 'email', 'home', 'work', 'cell'));
}

foreach ($rows as $row)
{
$csv .= '"'.join('","', str_replace('"', '""', $row))."\"\015\012";
$safeRow = array();
foreach ($row as $field)
{
$safeRow[] = cleanCsvField($field);
}

if ($handle !== false)
{
fputcsv($handle, $safeRow);
}
}

if ($handle !== false)
{
rewind($handle);
$csv = stream_get_contents($handle);
fclose($handle);
}

$date = fixDate('Y-m-d', $this->fcmsUser->tzOffset);
Expand Down
22 changes: 22 additions & 0 deletions familyconnections/inc/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,28 @@ function cleanFilename ($filename)

return $filename;
}

/**
* cleanCsvField
*
* Prevents spreadsheet formula execution when exporting user-controlled CSV.
*
* @param string $field
*
* @return string
*/
function cleanCsvField ($field)
{
$field = (string)$field;

if (preg_match('/^\s*[=+\-@]/', $field))
{
return "'".$field;
}

return $field;
}

/**
* unhtmlentities
*
Expand Down