Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kharissulistiyo/0e4b14eee7a001e6e6cf67592fbfdb05 to your computer and use it in GitHub Desktop.
Save kharissulistiyo/0e4b14eee7a001e6e6cf67592fbfdb05 to your computer and use it in GitHub Desktop.
Bad PHP code sample: CSV Injection vulnerability
<?php
public function write( $data, $columns ) {
$is_test_mode_off = ! defined( 'AAL_TESTMODE' ) || ( defined( 'AAL_TESTMODE' ) && ! AAL_TESTMODE );
if ( $is_test_mode_off ) {
header( 'Content-type: text/csv' );
header( 'Content-Disposition: attachment; filename="activity-log-export.csv"' );
}
$fp = fopen( 'php://output', 'w' );
fputcsv( $fp, $columns );
foreach ( $data as $row ) {
fputcsv( $fp, $row );
}
fclose( $fp );
if ( $is_test_mode_off ) {
exit;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment