| @@ -276,8 +276,21 @@ | ||
| 276 | 276 | $attr[ $key ] = $atts[ $key ]; |
| 277 | 277 | } |
| 278 | 278 | } |
| 279 | 279 | |
| 280 | + // Whitelist allowed columns for ORDER BY to prevent SQL injection | |
| 281 | + $allowed_order_by = array( 'ID', 'id', 'name', 'createtime', 'updatetime' ); | |
| 282 | + | |
| 283 | + // Validate orderBy against whitelist | |
| 284 | + if ( ! in_array( $attr['orderBy'], $allowed_order_by, true ) ) { | |
| 285 | + $attr['orderBy'] = 'ID'; | |
| 286 | + } | |
| 287 | + | |
| 288 | + // Validate order against whitelist | |
| 289 | + if ( ! in_array( strtoupper( $attr['order'] ), array( 'ASC', 'DESC' ), true ) ) { | |
| 290 | + $attr['order'] = 'DESC'; | |
| 291 | + } | |
| 292 | + | |
| 280 | 293 | // Log the final attributes used for the query. |
| 281 | 294 | Logger::getInstance()->debug( 'Using the following attributes for the query.', [ |
| 282 | 295 | 'plugin' => 'double-opt-in', |
| 283 | 296 | 'attributes' => $attr, |