Struts1の脆弱性対策(続き)
Apache Struts1の脆弱性問題(S2-020)の対策として、先日の記事でbeanutilsのPropertyUtils
クラスを修正する方法を紹介した。
RequestProcessorを拡張する方法
その後検討した結果、Struts1が提供するRequestProcessor
を拡張する方法でも対応できることがわかった。
ただし、この方法に関しては、以下のブログがすでに言及しているので、そちらを参照願いたい。
http://qiita.com/kawasima/items/670d2591bc8fea19dc1d
→後半の「(4/30 追記)」の部分に記載あり。
実際にRequestProcessor
を拡張するコードはこちら。
https://gist.github.com/kawasima/c22a1c706656e4004d41
PropertyUtils#setNestedPropertyのコード
なお参考までに、先日の記事では省略したPropertyUtils#setNestedProperty
のコードを紹介しておく。
public static void setNestedProperty(Object bean, String name, Object value) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { if (bean == null) { throw new IllegalArgumentException("No bean specified"); } if (name == null) { throw new IllegalArgumentException("No name specified"); } BeanutilsSecurityChecker.check(bean); // [S2-020]対応 https://struts.apache.org/release/2.3.x/docs/s2-020.html int indexOfINDEXED_DELIM = -1; int indexOfMAPPED_DELIM = -1; while (true) { int delim = name.indexOf(NESTED_DELIM); if (delim < 0) { break; } String next = name.substring(0, delim); indexOfINDEXED_DELIM = next.indexOf(INDEXED_DELIM); indexOfMAPPED_DELIM = next.indexOf(MAPPED_DELIM); if (bean instanceof Map) { bean = ((Map) bean).get(next); } else if (indexOfMAPPED_DELIM >= 0) { bean = getMappedProperty(bean, next); } else if (indexOfINDEXED_DELIM >= 0) { bean = getIndexedProperty(bean, next); } else { bean = getSimpleProperty(bean, next); } if (bean == null) { throw new IllegalArgumentException ("Null property value for '" + name.substring(0, delim) + "'"); } BeanutilsSecurityChecker.check(bean); // [S2-020]対応 https://struts.apache.org/release/2.3.x/docs/s2-020.html name = name.substring(delim + 1); } indexOfINDEXED_DELIM = name.indexOf(INDEXED_DELIM); indexOfMAPPED_DELIM = name.indexOf(MAPPED_DELIM); if (bean instanceof Map) { // check to see if the class has a standard property PropertyDescriptor descriptor = getPropertyDescriptor(bean, name); if (descriptor == null) { // no - then put the value into the map ((Map) bean).put(name, value); } else { // yes - use that instead setSimpleProperty(bean, name, value); } } else if (indexOfMAPPED_DELIM >= 0) { setMappedProperty(bean, name, value); } else if (indexOfINDEXED_DELIM >= 0) { setIndexedProperty(bean, name, value); } else { setSimpleProperty(bean, name, value); } }
[近棟 稔]