Created
November 29, 2024 10:23
-
-
Save kharissulistiyo/0e4b14eee7a001e6e6cf67592fbfdb05 to your computer and use it in GitHub Desktop.
Bad PHP code sample: CSV Injection vulnerability
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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