-
Notifications
You must be signed in to change notification settings - Fork 810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WW-5439 Move DevMode security configuration to SecurityMemberAccess #979
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,11 @@ public void setUp() throws Exception { | |
ognlUtil = container.getInstance(OgnlUtil.class); | ||
} | ||
|
||
private void resetOgnlUtil(Map<String, ?> properties) { | ||
loadButSet(properties); | ||
ognlUtil = container.getInstance(OgnlUtil.class); | ||
} | ||
|
||
public void testCanSetADependentObject() { | ||
String dogName = "fido"; | ||
|
||
|
@@ -1152,8 +1157,8 @@ public void testAvoidCallingMethodsOnObjectClass() { | |
|
||
Exception expected = null; | ||
try { | ||
ognlUtil.setExcludedClasses(Object.class.getName()); | ||
ognlUtil.setValue("class.classLoader.defaultAssertionStatus", ognlUtil.createDefaultContext(foo), foo, true); | ||
// Object.class is excluded by default | ||
ognlUtil.setValue("class.classLoader", ognlUtil.createDefaultContext(foo), foo, true); | ||
fail(); | ||
} catch (OgnlException e) { | ||
expected = e; | ||
|
@@ -1166,9 +1171,11 @@ public void testAvoidCallingMethodsOnObjectClass() { | |
public void testAllowCallingMethodsOnObjectClassInDevModeTrue() { | ||
Exception expected = null; | ||
try { | ||
ognlUtil.setExcludedClasses(Foo.class.getName()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These methods don't do anything, so we inject the configuration instead |
||
ognlUtil.setDevModeExcludedClasses(""); | ||
ognlUtil.setDevMode(Boolean.TRUE.toString()); | ||
Map<String, String> properties = new HashMap<>(); | ||
properties.put(StrutsConstants.STRUTS_EXCLUDED_CLASSES, Foo.class.getName()); | ||
properties.put(StrutsConstants.STRUTS_DEV_MODE_EXCLUDED_CLASSES, ""); | ||
properties.put(StrutsConstants.STRUTS_DEVMODE, Boolean.TRUE.toString()); | ||
resetOgnlUtil(properties); | ||
|
||
Foo foo = new Foo(); | ||
String result = (String) ognlUtil.getValue("toString", ognlUtil.createDefaultContext(foo), foo, String.class); | ||
|
@@ -1180,14 +1187,18 @@ public void testAllowCallingMethodsOnObjectClassInDevModeTrue() { | |
} | ||
|
||
public void testExclusionListDevModeOnOff() throws Exception { | ||
ognlUtil.setDevModeExcludedClasses(Foo.class.getName()); | ||
Foo foo = new Foo(); | ||
|
||
ognlUtil.setDevMode(Boolean.TRUE.toString()); | ||
Map<String, String> properties = new HashMap<>(); | ||
properties.put(StrutsConstants.STRUTS_DEV_MODE_EXCLUDED_CLASSES, Foo.class.getName()); | ||
properties.put(StrutsConstants.STRUTS_DEVMODE, Boolean.TRUE.toString()); | ||
resetOgnlUtil(properties); | ||
|
||
OgnlException e = assertThrows(OgnlException.class, () -> ognlUtil.getValue("toString", ognlUtil.createDefaultContext(foo), foo, String.class)); | ||
assertThat(e).hasMessageContaining("com.opensymphony.xwork2.util.Foo.toString"); | ||
|
||
ognlUtil.setDevMode(Boolean.FALSE.toString()); | ||
properties.put(StrutsConstants.STRUTS_DEVMODE, Boolean.FALSE.toString()); | ||
resetOgnlUtil(properties); | ||
assertEquals("Foo", (String) ognlUtil.getValue("toString", ognlUtil.createDefaultContext(foo), foo, String.class)); | ||
} | ||
|
||
|
@@ -1196,7 +1207,7 @@ public void testAvoidCallingMethodsOnObjectClassUpperCased() { | |
|
||
Exception expected = null; | ||
try { | ||
ognlUtil.setExcludedClasses(Object.class.getName()); | ||
// Object.class is excluded by default | ||
ognlUtil.setValue("Class.ClassLoader.DefaultAssertionStatus", ognlUtil.createDefaultContext(foo), foo, true); | ||
fail(); | ||
} catch (OgnlException e) { | ||
|
@@ -1212,7 +1223,7 @@ public void testAvoidCallingMethodsOnObjectClassAsMap() { | |
|
||
Exception expected = null; | ||
try { | ||
ognlUtil.setExcludedClasses(Object.class.getName()); | ||
// Object.class is excluded by default | ||
ognlUtil.setValue("class['classLoader']['defaultAssertionStatus']", ognlUtil.createDefaultContext(foo), foo, true); | ||
fail(); | ||
} catch (OgnlException e) { | ||
|
@@ -1243,7 +1254,7 @@ public void testAvoidCallingMethodsOnObjectClassAsMapWithQuotes() { | |
|
||
Exception expected = null; | ||
try { | ||
ognlUtil.setExcludedClasses(Object.class.getName()); | ||
// Object.class is excluded by default | ||
ognlUtil.setValue("class[\"classLoader\"]['defaultAssertionStatus']", ognlUtil.createDefaultContext(foo), foo, true); | ||
fail(); | ||
} catch (OgnlException e) { | ||
|
@@ -1284,12 +1295,11 @@ public void testAvoidCallingMethodsWithBraces() { | |
assertEquals(expected.getMessage(), "Inappropriate OGNL expression: toString()"); | ||
} | ||
|
||
public void testAvoidCallingSomeClasses() { | ||
public void testStaticMethodBlocked() { | ||
Foo foo = new Foo(); | ||
|
||
Exception expected = null; | ||
try { | ||
ognlUtil.setExcludedClasses(Runtime.class.getName()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The exclusion list isn't checked here as it's already blocked by the static method check |
||
ognlUtil.setValue("@java.lang.Runtime@getRuntime().exec('mate')", ognlUtil.createDefaultContext(foo), foo, true); | ||
fail(); | ||
} catch (OgnlException e) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
isDevModeInit
check isn't thread-safe but it doesn't need to be as there's no negative consequence of running this method more than once when DevMode is enabled.