8
8
// I think that really depends on how much OWASP ESAPI plans on tracking changes to this
9
9
// version vs. if the plan was just to fork from it and maintain OWASP's own version.
10
10
// At this point, I think I prefer split from tracking Harder's original, but I'm easily
11
- // persuaded otherwise. - Kevin Wall
11
+ // persuaded otherwise. (In fact, we have already done so w/ decodeToObject().) - Kevin Wall
12
12
13
13
/**
14
14
* <p>Encodes and decodes to and from Base64 notation.</p>
@@ -136,6 +136,12 @@ public class Base64
136
136
*/
137
137
public final static int ORDERED = 32 ;
138
138
139
+ /**
140
+ * System property name that must be set to true in order to invoke {@code Base64.decodeToObject()}.
141
+ * @see https://github.com/ESAPI/esapi-java-legacy/issues/354
142
+ * @see http://foxglovesecurity.com/2015/11/06/what-do-weblogic-websphere-jboss-jenkins-opennms-and-your-application-have-in-common-this-vulnerability/
143
+ */
144
+ public final static String ENABLE_UNSAFE_SERIALIZATION = "org.owasp.esapi.enableUnsafeSerialization" ; // Do NOT change!
139
145
140
146
/* ******** P R I V A T E F I E L D S ******** */
141
147
@@ -1091,6 +1097,15 @@ public static byte[] decode( String s, int options )
1091
1097
* untrusted data from a string and deserialize it into
1092
1098
* an object can potentially result in remote command
1093
1099
* injection vulnerabilities. Use at your own risk!
1100
+ * </p><p><b>IMPORTANT BACKWARD COMPATIBILITY NOTICE</b></br>
1101
+ * Because this static method can easily be used as an attack vector
1102
+ * for those passing in deserialized objects, in a manner similar to the
1103
+ * <a href="https://issues.apache.org/jira/browse/COLLECTIONS-580">Apache Commons Collections InvokerTransformer</a>
1104
+ * issue, we are requiring that the system property
1105
+ * {@code org.owasp.esapi.enableUnsafeSerialization}
1106
+ * be set to "true" in order for this method to be successfully invoked.
1107
+ * We apologize for the inconvenience this may cause in breaking anyone's
1108
+ * application, but we feel that it is for the greater good.
1094
1109
* </p>
1095
1110
*
1096
1111
* @param encodedObject The Base64 data to decode
@@ -1110,6 +1125,16 @@ public static byte[] decode( String s, int options )
1110
1125
@ Deprecated
1111
1126
public static Object decodeToObject ( String encodedObject )
1112
1127
{
1128
+ // We will do better when we attempt this again, allowing for a second argument
1129
+ // to specify some sort of a collection of white-listed classes. Until then...
1130
+ // See: http://www.ibm.com/developerworks/library/se-lookahead/ for how-to.
1131
+ if ( ! "true" .equalsIgnoreCase ( System .getProperty ( ENABLE_UNSAFE_SERIALIZATION ) ) ) {
1132
+ throw new UnsupportedOperationException (
1133
+ "Deserialization by Base64.decodeToObject(String) is disabled for security reasons. " +
1134
+ "To re-enable it, set the system property '" + ENABLE_UNSAFE_SERIALIZATION + "' to 'true'." +
1135
+ "For details, see: https://github.com/ESAPI/esapi-java-legacy/issues/354" );
1136
+ }
1137
+
1113
1138
// Decode and gunzip if necessary
1114
1139
byte [] objBytes = decode ( encodedObject );
1115
1140
0 commit comments