prevent csv injection
This commit is contained in:
parent
a884e06b72
commit
54478d1a6a
@ -35,6 +35,8 @@ abstract class Export implements FromCollection, ShouldAutoSize, WithHeadings, W
|
|||||||
|
|
||||||
$date_fields = ['paid_at', 'invoiced_at', 'billed_at', 'due_at', 'issued_at', 'created_at'];
|
$date_fields = ['paid_at', 'invoiced_at', 'billed_at', 'due_at', 'issued_at', 'created_at'];
|
||||||
|
|
||||||
|
$evil_chars = ['=', '+', '-', '@'];
|
||||||
|
|
||||||
foreach ($this->fields() as $field) {
|
foreach ($this->fields() as $field) {
|
||||||
$value = $model->$field;
|
$value = $model->$field;
|
||||||
|
|
||||||
@ -42,6 +44,11 @@ abstract class Export implements FromCollection, ShouldAutoSize, WithHeadings, W
|
|||||||
$value = Date::parse($value)->format('Y-m-d');
|
$value = Date::parse($value)->format('Y-m-d');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prevent CSV injection https://security.stackexchange.com/a/190848
|
||||||
|
if (Str::startsWith($value, $evil_chars)) {
|
||||||
|
$value = "'" . $value;
|
||||||
|
}
|
||||||
|
|
||||||
$map[] = $value;
|
$map[] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user