-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add input validation to report generator controller endpoints.
This pull request adds input validation filters to the user-supplied untrusted data provided to the report generator controller endpoints. The modifications do not change any of the data serialization or api of the endpoints. The user-supplied report text (title, header, footer etc.) is modified to filter out data that does not have a valid character encoding. This mitigates a bug in the report generator if you tried to create a report with a filename containing an invalid character such as 😊 then the UI would show an error message: ``` There was a problem creating / updating this report. (SQLSTATE[HY000]: General error: 1267 Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation 'like') ``` the new behaviour is that the report will save ok but any invalid characters will be converted to '?'. A complete fix for this bug is beyond the scope of this pull request. There are several complex regular expressions used to validate the data this is necessary due to the non-standard serialization used in the report generator. Unit tests have been added to confirm that the more complex regular expressions used do pass through permissable data.
- Loading branch information
Showing
6 changed files
with
298 additions
and
63 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace DataWarehouse\Access; | ||
|
||
class ReportGenerator extends Common | ||
{ | ||
/* Properties of reports. See also the enum columns in the moddb.Reports | ||
* table */ | ||
const REPORT_ID_REGEX = '/^[0-9]+-[0-9\.]+$/'; | ||
const REPORT_DATE_REGEX = '/^[0-9]{4}(-[0-9]{2}){2}$/'; | ||
const REPORT_FORMATS_REGEX = '/^doc|pdf$/'; | ||
const REPORT_FONT_REGEX = '/^Arial$/'; | ||
const REPORT_SCHEDULE_REGEX = '/^Once|Daily|Weekly|Monthly|Quarterly|Semi-annually|Annually$/'; | ||
const REPORT_DELIVERY_REGEX = '/^E-Mail$/'; | ||
|
||
/* Patterns related to report charts */ | ||
const REPORT_CHART_TYPE_REGEX = '/^chart_pool|volatile|report|cached$/'; | ||
const REPORT_CHART_REF_REGEX = '/^[0-9]+(-[0-9]+)?;[0-9]+$/'; | ||
const REPORT_CHART_DID_REGEX = '/^_d[0-9]+$/'; | ||
|
||
/* the save_report controller use a custom data serialization for charts | ||
* that have been modified from the original report */ | ||
const CHART_CACHEREF_REGEX = '/^([0-9]{4}(-[0-9]{2}){2};){2}(?(?=xd_report_volatile_)xd_report_volatile_[0-9]+;[0-9]+(_d[0-9]+)?|[0-9]+-[0-9\.]+;[0-9]+)$/'; | ||
|
||
/* The report download endpoint retrieves the report data from a temporary | ||
* directory that is created dynamically based on the report_id | ||
*/ | ||
const REPORT_TMPDIR_REGEX = '/^[0-9]+-[0-9\.]+-[a-zA-Z0-9\.]+$/'; | ||
|
||
/* | ||
* Character encoding used in the (user supplied) text contained in the | ||
* report. This must be consistent with the character set used in the | ||
* moddb.Report table. | ||
*/ | ||
const REPORT_CHAR_ENCODING = 'ISO-8859-1'; | ||
} |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.