[5.4] Escape csv formula characters in banner tracks export#48047
[5.4] Escape csv formula characters in banner tracks export#48047arib06 wants to merge 9 commits into
Conversation
|
the same issue can arise in other place, for example User Action Log export |
|
Good point to check. User Action Log export already runs its fields through |
|
shouldn't be better than to use the same method all over without duplicates? |
|
Makes sense. Dropped the duplicate helper and made |
|
@arib06 Please conform that you have read the Generative AI policy and your contribution is either not created with the help of AI or is compatible with the policy and GNU/GPL 2 or later by checking the check box at the top of your PR description. Thanks in advance. |
…onlogsHelper Signed-off-by: mohammed arib <arib@bugqore.com>
|
@richard67 Read the policy and ticked the box, it's GPL2-compatible. @joomdonation reverted the visibility change too and moved the escaping into BannersHelper so com_banners doesn't depend on the Action Logs helper. |
|
Given that we’re ourselfs then using it identically in two places and it might be also helpful to third-party extension developers, could be an idea to have it as output filter. What do you mean @joomdonation ? |
Signed-off-by: mohammed arib <arib@bugqore.com>
|
Happy to do that. Moving escapeCsvFormula into OutputFilter as a shared method means com_actionlogs and the tracks export both call the same code, and it's exposed to third-party extensions too. It also sidesteps the earlier cross-component dependency concern, since OutputFilter lives in the core library rather than in one component. If that's the direction you both prefer, I'll add it there and update com_actionlogs to use it. |
|
@arib06 i would assume that the issue only happens when you directly open the CSV with Excel by double click. This is not recommended anyway, the file should be imported into Excel from text. Can you confirm that the issue does not happen when you use the data import from text in Excel? |
|
@richard67 Yes, that's right. The formula only evaluates when the file gets parsed automatically, which is what a direct double-click open does since .csv is associated with Excel by default. If you go through Data > From Text/Get Data and set the column type to Text, the value comes in verbatim and isn't evaluated, so that import path is safe. The reason it's still worth escaping is that the double-click open is the common path for an admin grabbing a download, and LibreOffice Calc evaluates on open as well. This is the standard CSV formula injection case (CWE-1236), and the leading-space fix here is the same handling com_actionlogs already ships, so it's just bringing the tracks export in line rather than a new approach. |
|
I don’t quite understand what role this plays. The fix was already implemented elsewhere some time ago, and the behaviour is now inconsistent in parts of the CMS. |
com_actionlogs and the banner tracks export now call the same OutputFilter::escapeCsvFormula, and third-party extensions can reuse it.
|
@LadySolveig Agreed, the inconsistency was the real issue here. I've moved the escaping into |
|
@arib06 , your last commit was perhaps a bit rushed. I think best would be to wait for further feedback here before you invest any more time and effort. |
|
imho |
Signed-off-by: mohammed arib <arib@bugqore.com>
|
Addressed the review: instead of removing the old escapeCsvFormula method and its $characters property from ActionlogsHelper I've marked both @deprecated (5.4, to be removed in 7.0) with a pointer to OutputFilter, so nothing is dropped from the API and BC is preserved. On the OutputFilter move itself, understood that the shared-method direction and the target version are the maintenance team's call. I'm happy to hold here and not touch it further until there's a decision on whether it goes in a 5.x patch or waits for a later release. If you'd rather I pare this back to just the banner tracks fix and leave com_actionlogs untouched, say the word and I'll do that. |
|
I have tested this item ✅ successfully on 4cf3802 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/48047. |
@arib06 Meanwhile we have discussed your PR in the maintainers team and came to the conclusion to do the fix in 2 steps:
For 1. this means you should do the "pare this back to just the banner tracks fix and leave com_actionlogs untouched" thing as you supposed, but in the banner tracks it should be a private and not a public function for b/c (adding a private method does not break classes extended from that, while adding a public method would break that). For 2. it means that you could create a PR for the framework here https://github.com/joomla-framework/filter/pulls for the 4.x-dev with the new method in file When 2. will be done and a new 4.x release of the filter framework has been made, it will then need a third step:
Could you do the first 2 steps? That would be much appreciated. |
|
@richard67 Both done.
Happy to do step 3 here against 6.2-dev once that framework release is out. |
Pull Request resolves # .
Summary of Changes
The banner tracks CSV export in
TracksModel::getContent()writesbanner_name,client_nameandcategory_titleinto the file with only quote-doubling. Those values are user controlled (anyone with com_banners create/edit can set a banner or client name), so a name beginning with=,+,-or@lands in a cell that a spreadsheet evaluates as a formula when an administrator opens the exported file. com_actionlogs already escapes its CSV export this way; this applies the same leading-space escaping to the tracks export.Testing Instructions
=1+1(or=HYPERLINK("http://example.com","x")).Actual result BEFORE applying this Pull Request
The name cell is treated as a formula and evaluated by the spreadsheet.
Expected result AFTER applying this Pull Request
The value is prefixed with a space and shown verbatim as text, matching how com_actionlogs exports are handled.
Link to documentations
Please select:
Documentation link for guide.joomla.org:
No documentation changes for guide.joomla.org needed
Pull Request link for manual.joomla.org:
No documentation changes for manual.joomla.org needed