-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LPD-41486 Fix HTML injection in iframe client extension
Changing " to %22 is enough to fix the HTML injection for the URL. For the case of parameters we just need to replace " in the parameter name, which is not encoded by HttpComponentsUtil. The value is already encoded by that method so we are safe.
- Loading branch information
1 parent
828c178
commit 1880b4b
Showing
2 changed files
with
115 additions
and
2 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
104 changes: 104 additions & 0 deletions
104
...src/test/java/com/liferay/client/extension/web/internal/portlet/IFrameCETPortletTest.java
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,104 @@ | ||
/** | ||
* SPDX-FileCopyrightText: (c) 2024 Liferay, Inc. https://liferay.com | ||
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06 | ||
*/ | ||
|
||
package com.liferay.client.extension.web.internal.portlet; | ||
|
||
import com.liferay.client.extension.type.IFrameCET; | ||
import com.liferay.portal.kernel.util.Portal; | ||
import com.liferay.portal.kernel.util.PortalUtil; | ||
import com.liferay.portal.test.rule.LiferayUnitTestRule; | ||
import com.liferay.portal.util.PortalImpl; | ||
import com.liferay.portletmvc4spring.test.mock.web.portlet.MockPortletPreferences; | ||
|
||
import java.io.CharArrayWriter; | ||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
|
||
import java.util.Properties; | ||
|
||
import javax.portlet.RenderRequest; | ||
import javax.portlet.RenderResponse; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.ClassRule; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
import org.mockito.Mockito; | ||
|
||
/** | ||
* @author Iván Zaera Avellón | ||
*/ | ||
public class IFrameCETPortletTest { | ||
|
||
@ClassRule | ||
@Rule | ||
public static final LiferayUnitTestRule liferayUnitTestRule = | ||
LiferayUnitTestRule.INSTANCE; | ||
|
||
@Before | ||
public void setUp() { | ||
_portal = new PortalImpl(); | ||
|
||
new PortalUtil( | ||
).setPortal( | ||
_portal | ||
); | ||
} | ||
|
||
@Test | ||
public void testRenderWithQuotedProperties() throws IOException { | ||
IFrameCET iFrameCET = Mockito.mock(IFrameCET.class); | ||
|
||
Properties properties = new Properties(); | ||
|
||
properties.put("\"height", "399\""); | ||
|
||
Mockito.when( | ||
iFrameCET.getProperties() | ||
).thenReturn( | ||
properties | ||
); | ||
|
||
Mockito.when( | ||
iFrameCET.getURL() | ||
).thenReturn( | ||
"https://example.com" | ||
); | ||
|
||
IFrameCETPortlet iFrameCETPortlet = new IFrameCETPortlet( | ||
iFrameCET, "portletId", _portal); | ||
|
||
RenderRequest renderRequest = Mockito.mock(RenderRequest.class); | ||
|
||
Mockito.when( | ||
renderRequest.getPreferences() | ||
).thenReturn( | ||
new MockPortletPreferences() | ||
); | ||
|
||
RenderResponse renderResponse = Mockito.mock(RenderResponse.class); | ||
|
||
CharArrayWriter charArrayWriter = new CharArrayWriter(); | ||
|
||
PrintWriter printWriter = new PrintWriter(charArrayWriter); | ||
|
||
Mockito.when( | ||
renderResponse.getWriter() | ||
).thenReturn( | ||
printWriter | ||
); | ||
|
||
iFrameCETPortlet.render(renderRequest, renderResponse); | ||
|
||
Assert.assertEquals( | ||
"<iframe src=\"https://example.com?%22height=399%22\"></iframe>", | ||
charArrayWriter.toString()); | ||
} | ||
|
||
private Portal _portal; | ||
|
||
} |