Details
-
Bug
-
Status: Closed
-
Resolution: Duplicate
-
7.3.10 DXP FP1, 7.3.X, Master
-
None
Description
Reproduction Steps on master:
1. Startup Liferay
2. Navigate to Site (Liferay) > Content & Data > Documents and Media
Add a document using File Upload with the title: test
3. Navigate to Site (Liferay) > Design > Widget Templates
Add an Asset Publisher Template: testTemplate with the following content:
<#-- Widget templates can be used to modify the look of a specific application. Please use the left panel to quickly add commonly used variables. Autocomplete is also available and can be invoked by typing "${". --> <#assign dlFileEntryService = serviceLocator.findService("com.liferay.document.library.kernel.service.DLFileEntryService") groupId = themeDisplay.getScopeGroupId() folderId = 0 title = "test" fileEntry = dlFileEntryService.getFileEntry(groupId, folderId, title)!"" fileEntryType = fileEntry.getDLFileEntryType() />
4. Navigate to Control Panel > System Settings > Template Engines
Look for serviceLocator
Click on the minus button to remove it
Click Save/Update
5. Navigate to the home page and add an Asset Publisher, with:
Add our created test document ( [+] > Content > test )
6. Configure the added Asset Publisher widget
Change Display Settings from Default to our created testTemplate
Click Save
7. Refresh the home page and check if denied access error occurs
Reproduction Steps on 7.3.x:
- Start Liferay DXP 7.3.x
- Go to Control Panel→System Settings→Template Engines
- Look for serviceLocator→click on the minus button to remove it→Update
- Return to the site
- Create a structure with DocumentList.json
as source and TestStructure as the title
- Create a template with DocumentList_mod.ftl
- Go to Documents and Media→Document Types→+ sign
- Title: TestDocumentType
- Add a Documents & Media field→Save
- Add a new TestDocumentType→title: TestDDM
- Click on Select→upload an image (test.jpg)→Save
- Create a web content with TestStructure
- Set TestDDM for the Documents field→Publish
- Create a widget page TestWidgetPage
- Click on the + sign to add portlets
- Click on the Content tab
- Search for TestWebContent and place it onto the page
- Checkpoint: a link is visible: Documents
- Open TestWebContent again
- Change the Documents field to test.jpg→Publish
- Visit TestWidgetPage again
Expected Behavior
we can see the link to the image, just like in the checkpoint step.
Actual Behavior
error in server logs and in the web content display:
Errors received:
An error occurred while processing the template. Denied access to model object as it does not belong to current company 20097 ---- FTL stack trace ("~" means nesting-related): - Failed at: #local fileEntryType = fileEntry.getD... [in template "20097#20123#40609" in macro "renderDocumentListContent" at line 33, column 17] - Reached through: @renderDocumentListContent text, docu... [in template "20097#20123#40609" at line 106, column 9] ----
The current code blocks access to all objects that don't belong to the current company (e.g. 20116 or something like that). That change was introduced this year and improves the security, it is not possible to access objects belonging to other companies anymore - which is correct.
But it has a hole, there are some objects, like the documenttype BASIC_DOCUMENT, that have a companyId of 0. So, if you want to handle files differently in freemarker based on the document type, you run into an "Access denied" error. And that's simply not correct. BASIC_DOCUMENT should be accessible.
A possible fix would check for that too and would allow objects with companyId == 0 too.
Attachments
Issue Links
- duplicates
-
LPS-151172 Could not access to Basic Document Type in templates
- Selected for Development
- is caused by
-
LPS-124940 Make the transaction triggered by freemarker template directly read only
-
- Closed
-