Skip to content

Commit 429834b

Browse files
dantewangbrianchandotcom
authored andcommitted
LPS-144246 Add size and number check to put(HttpSession, ...)
1 parent 0231837 commit 429834b

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

portal-kernel/src/com/liferay/portal/kernel/util/SessionClicks.java

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.liferay.portal.kernel.portlet.PortletPreferencesFactoryUtil;
2323

2424
import java.util.ConcurrentModificationException;
25+
import java.util.Enumeration;
2526

2627
import javax.servlet.http.HttpServletRequest;
2728
import javax.servlet.http.HttpSession;
@@ -143,10 +144,46 @@ public static void put(HttpSession httpSession, String key, String value) {
143144
public static void put(
144145
HttpSession httpSession, String namespace, String key, String value) {
145146

146-
String sessionKey = StringBundler.concat(
147-
namespace, StringPool.COLON, key);
147+
if ((key.length() > _SESSION_CLICKS_MAX_SIZE_TERMS) ||
148+
(value.length() > _SESSION_CLICKS_MAX_SIZE_TERMS)) {
149+
150+
if (_log.isWarnEnabled()) {
151+
_log.warn(
152+
StringBundler.concat(
153+
"Session clicks has attempted to exceed the maximum ",
154+
"size allowed for keys or values with {key=", key,
155+
", value=", value, "}"));
156+
}
157+
158+
return;
159+
}
160+
161+
Enumeration<String> enumeration = httpSession.getAttributeNames();
162+
163+
int size = 0;
164+
165+
while (enumeration.hasMoreElements()) {
166+
enumeration.nextElement();
167+
168+
size++;
169+
}
148170

149-
httpSession.setAttribute(sessionKey, value);
171+
if (size < _SESSION_CLICKS_MAX_ALLOWED_VALUES) {
172+
String sessionKey = StringBundler.concat(
173+
namespace, StringPool.COLON, key);
174+
175+
httpSession.setAttribute(sessionKey, value);
176+
177+
return;
178+
}
179+
180+
if (_log.isWarnEnabled()) {
181+
_log.warn(
182+
StringBundler.concat(
183+
"Session clicks has attempted to exceed the maximum ",
184+
"number of allowed values with {key=", key, ", value=",
185+
value, "}"));
186+
}
150187
}
151188

152189
private static final String _DEFAULT_NAMESPACE =

0 commit comments

Comments
 (0)