-
-
Notifications
You must be signed in to change notification settings - Fork 792
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Back porting of security patches (#3197)
* Merge pull request from GHSA-fr2w-mp56-g4xp * Enforce file download for attachments table(s) * Enforce file download for attachment in 'StockItemTestResult' table (cherry picked from commit 76aa3a7) * Merge pull request from GHSA-7rq4-qcpw-74gq * Merge pull request from GHSA-rm89-9g65-4ffr * Enable HTML escaping for all tables by default * Enable HTML escaping for all tables by default * Adds automatic escaping for bootstrap tables where custom formatter function is specified - Intercept the row data *before* it is provided to the renderer function - Adds a function for sanitizing nested data structure * Sanitize form data before processing (cherry picked from commit cd418d6) * Increment version number for release * Fix sanitization for array case - was missing a return value
- Loading branch information
1 parent
f9c28ee
commit 26bf51c
Showing
12 changed files
with
195 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,33 @@ | ||
"""Admin classes""" | ||
|
||
from import_export.resources import ModelResource | ||
|
||
|
||
class InvenTreeResource(ModelResource): | ||
"""Custom subclass of the ModelResource class provided by django-import-export" | ||
Ensures that exported data are escaped to prevent malicious formula injection. | ||
Ref: https://owasp.org/www-community/attacks/CSV_Injection | ||
""" | ||
|
||
def export_resource(self, obj): | ||
"""Custom function to override default row export behaviour. | ||
Specifically, strip illegal leading characters to prevent formula injection | ||
""" | ||
row = super().export_resource(obj) | ||
|
||
illegal_start_vals = ['@', '=', '+', '-', '@', '\t', '\r', '\n'] | ||
|
||
for idx, val in enumerate(row): | ||
if type(val) is str: | ||
val = val.strip() | ||
|
||
# If the value starts with certain 'suspicious' values, remove it! | ||
while len(val) > 0 and val[0] in illegal_start_vals: | ||
# Remove the first character | ||
val = val[1:] | ||
|
||
row[idx] = val | ||
|
||
return row |
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
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.