diff --git a/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/repository/AbstractRepository.java b/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/repository/AbstractRepository.java index b4a4a5478e..da72f0eecf 100644 --- a/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/repository/AbstractRepository.java +++ b/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/repository/AbstractRepository.java @@ -23,6 +23,8 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Enumeration; import java.util.HashMap; import java.util.LinkedHashSet; @@ -38,6 +40,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.geronimo.kernel.util.InputUtils; import org.apache.geronimo.kernel.util.XmlUtil; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -158,17 +161,7 @@ public void setTypeHandler(String type, ArtifactTypeHandler handler) { public void copyToRepository(File source, Artifact destination, FileWriteMonitor monitor) throws IOException { // ensure there are no illegal chars in destination elements - Matcher groupMatcher = ILLEGAL_CHARS.matcher(destination.getGroupId()); - Matcher artifactMatcher = ILLEGAL_CHARS.matcher(destination.getArtifactId()); - Matcher versionMatcher = ILLEGAL_CHARS.matcher(destination.getVersion().toString()); - Matcher typeMatcher = ILLEGAL_CHARS.matcher(destination.getType()); - if (groupMatcher.find() || - artifactMatcher.find() || - versionMatcher.find() || - typeMatcher.find()) - { - throw new IllegalArgumentException("Artifact "+destination+" contains illegal characters, .. ( ) < > , ; : / \\ \' \" "); - } + InputUtils.validateSafeInput(new ArrayList(Arrays.asList(destination.getGroupId(), destination.getArtifactId(), destination.getVersion().toString(), destination.getType()))); if(!destination.isResolved()) { throw new IllegalArgumentException("Artifact "+destination+" is not fully resolved"); diff --git a/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/InputUtils.java b/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/InputUtils.java new file mode 100644 index 0000000000..f8d0442e74 --- /dev/null +++ b/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/InputUtils.java @@ -0,0 +1,55 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.geronimo.kernel.util; + +// import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * Utility functions related to Input validation. + * + * @version $Rev$ $Date$ + */ +public class InputUtils { + private static final Log log = LogFactory.getLog(InputUtils.class); + + private static final Pattern ILLEGAL_CHARS = Pattern.compile("[\\.]{2}|[<>:\\\\/\"\'\\|]"); + + public final static void validateSafeInput(String input) { + // look for illegal chars in input + if (input != null) { + Matcher inputMatcher = ILLEGAL_CHARS.matcher(input); + if (inputMatcher.find()) + { + log.warn("Illegal characters detected in input" + input); + throw new IllegalArgumentException("input "+input+" contains illegal characters: .. < > : / \\ \' \" | "); + } + } + } + + public final static void validateSafeInput(ArrayList inputs) { + for (String input : inputs) { + validateSafeInput(input); + } + } +} diff --git a/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/keystore/FileKeystoreManager.java b/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/keystore/FileKeystoreManager.java index ed55c00395..e949e976dd 100644 --- a/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/keystore/FileKeystoreManager.java +++ b/framework/modules/geronimo-security/src/main/java/org/apache/geronimo/security/keystore/FileKeystoreManager.java @@ -58,6 +58,7 @@ import org.apache.geronimo.kernel.config.ConfigurationUtil; import org.apache.geronimo.kernel.config.EditableConfigurationManager; import org.apache.geronimo.kernel.config.InvalidConfigException; +import org.apache.geronimo.kernel.util.InputUtils; import org.apache.geronimo.management.geronimo.KeyIsLocked; import org.apache.geronimo.management.geronimo.KeystoreException; import org.apache.geronimo.management.geronimo.KeystoreInstance; @@ -367,6 +368,10 @@ public SSLContext createSSLContext(String provider, String protocol, String algo } public KeystoreInstance createKeystore(String name, char[] password, String keystoreType) throws KeystoreException { + + // ensure there are no illegal chars in DB name + InputUtils.validateSafeInput(name); + File test = new File(directory, name); if(test.exists()) { throw new IllegalArgumentException("Keystore already exists "+test.getAbsolutePath()+"!"); diff --git a/plugins/ca-helper/geronimo-ca-helper/pom.xml b/plugins/ca-helper/geronimo-ca-helper/pom.xml index a357edce46..f9ef23a1fa 100644 --- a/plugins/ca-helper/geronimo-ca-helper/pom.xml +++ b/plugins/ca-helper/geronimo-ca-helper/pom.xml @@ -38,6 +38,12 @@ + + org.apache.geronimo.plugins + console-filter + ${version} + + org.apache.geronimo.framework geronimo-kernel diff --git a/plugins/ca-helper/geronimo-ca-helper/src/main/webapp/WEB-INF/web.xml b/plugins/ca-helper/geronimo-ca-helper/src/main/webapp/WEB-INF/web.xml index 508d37229f..3bedc2baff 100644 --- a/plugins/ca-helper/geronimo-ca-helper/src/main/webapp/WEB-INF/web.xml +++ b/plugins/ca-helper/geronimo-ca-helper/src/main/webapp/WEB-INF/web.xml @@ -23,6 +23,20 @@ CA Helper + + + + XSSXSRFFilter + org.apache.geronimo.console.filter.XSSXSRFFilter + + + XSSXSRFFilter + /* + + + org.apache.geronimo.console.filter.XSSXSRFFilter + + CertificateRequestServlet CertificateRequestServlet diff --git a/plugins/console/console-base-portlets/src/main/webapp/WEB-INF/view/keystore/createKeystore.jsp b/plugins/console/console-base-portlets/src/main/webapp/WEB-INF/view/keystore/createKeystore.jsp index bad9dadd48..ac4495ebb2 100644 --- a/plugins/console/console-base-portlets/src/main/webapp/WEB-INF/view/keystore/createKeystore.jsp +++ b/plugins/console/console-base-portlets/src/main/webapp/WEB-INF/view/keystore/createKeystore.jsp @@ -29,8 +29,12 @@ var formName = "KeystoreForm"; var requiredFields = new Array("filename", "password"); var passwordFields = new Array("password"); function validateForm(){ + var illegalChars= /[\.]{2}|[()<>,;:\\/"'\|]/ ; if(!textElementsNotEmpty(formName, requiredFields)) { return false; + } else if (document.forms[formName].filename.value.match(illegalChars)) { + alert("Keystore name contains illegal characters"); + return false; } if(!passwordElementsConfirm(formName, passwordFields)) { return false; diff --git a/plugins/console/console-base-portlets/src/main/webapp/WEB-INF/view/repository/normal.jsp b/plugins/console/console-base-portlets/src/main/webapp/WEB-INF/view/repository/normal.jsp index 06a179d7ba..509a0110cc 100644 --- a/plugins/console/console-base-portlets/src/main/webapp/WEB-INF/view/repository/normal.jsp +++ b/plugins/console/console-base-portlets/src/main/webapp/WEB-INF/view/repository/normal.jsp @@ -26,19 +26,19 @@ + \ No newline at end of file diff --git a/plugins/console/console-portal-driver/pom.xml b/plugins/console/console-portal-driver/pom.xml index 8a65e2ba97..832e7442e9 100644 --- a/plugins/console/console-portal-driver/pom.xml +++ b/plugins/console/console-portal-driver/pom.xml @@ -33,6 +33,12 @@ war + + org.apache.geronimo.plugins + console-filter + ${version} + + org.apache.geronimo.framework diff --git a/plugins/console/console-portal-driver/src/main/webapp/WEB-INF/web.xml b/plugins/console/console-portal-driver/src/main/webapp/WEB-INF/web.xml index 5abc33fdd7..552d0f2ba0 100644 --- a/plugins/console/console-portal-driver/src/main/webapp/WEB-INF/web.xml +++ b/plugins/console/console-portal-driver/src/main/webapp/WEB-INF/web.xml @@ -31,6 +31,19 @@ limitations under the License. /WEB-INF/pluto-portal-driver-services-config.xml + + + XSSXSRFFilter + org.apache.geronimo.console.filter.XSSXSRFFilter + + + XSSXSRFFilter + /* + + + org.apache.geronimo.console.filter.XSSXSRFFilter + + org.springframework.web.context.ContextLoaderListener diff --git a/plugins/console/pom.xml b/plugins/console/pom.xml index c7b250054f..e653aadc50 100644 --- a/plugins/console/pom.xml +++ b/plugins/console/pom.xml @@ -48,6 +48,7 @@ geronimo-converter console-core console-base-portlets + console-filter console-portal-driver console-ear console-tomcat diff --git a/plugins/monitoring/mconsole-war/pom.xml b/plugins/monitoring/mconsole-war/pom.xml index 1610333a43..f906bc467e 100644 --- a/plugins/monitoring/mconsole-war/pom.xml +++ b/plugins/monitoring/mconsole-war/pom.xml @@ -37,6 +37,13 @@ Geronimo Monitorin Console :: WEB Module + + + org.apache.geronimo.plugins + console-filter + ${version} + + org.apache.geronimo.framework geronimo-management diff --git a/plugins/monitoring/mconsole-war/src/main/java/org/apache/geronimo/monitoring/console/MonitoringPortlet.java b/plugins/monitoring/mconsole-war/src/main/java/org/apache/geronimo/monitoring/console/MonitoringPortlet.java index e8d6446dda..36f4f8f0ee 100644 --- a/plugins/monitoring/mconsole-war/src/main/java/org/apache/geronimo/monitoring/console/MonitoringPortlet.java +++ b/plugins/monitoring/mconsole-war/src/main/java/org/apache/geronimo/monitoring/console/MonitoringPortlet.java @@ -510,7 +510,7 @@ private void updateView(ActionRequest actionRequest, DBManager DBase = new DBManager(); Connection con = DBase.getConnection(); String name = actionRequest.getParameter("name"); - String description = actionRequest.getParameter("description"); + String description = actionRequest.getParameter("minxss_description"); String[] graphsArray = actionRequest.getParameterValues("graph_ids"); if (graphsArray == null) { graphsArray = new String[0]; @@ -553,7 +553,7 @@ private void addView(ActionRequest actionRequest, DBManager DBase = new DBManager(); Connection con = DBase.getConnection(); String name = actionRequest.getParameter("name"); - String description = actionRequest.getParameter("description"); + String description = actionRequest.getParameter("minxss_description"); String[] graphsArray = actionRequest.getParameterValues("graph_ids"); if (graphsArray == null) { graphsArray = new String[0]; @@ -797,7 +797,7 @@ private void addGraph(ActionRequest actionRequest, DBManager DBase = new DBManager(); Connection con = DBase.getConnection(); String name = actionRequest.getParameter("name"); - String description = actionRequest.getParameter("description"); + String description = actionRequest.getParameter("minxss_description"); String server_id = actionRequest.getParameter("server_id"); String xlabel = actionRequest.getParameter("xlabel"); String ylabel = actionRequest.getParameter("ylabel"); @@ -870,7 +870,7 @@ private void updateGraph(ActionRequest actionRequest, actionResponse.setRenderParameter("graph_id", graph_id); String name = actionRequest.getParameter("name"); - String description = actionRequest.getParameter("description"); + String description = actionRequest.getParameter("minxss_description"); String server_id = actionRequest.getParameter("server_id"); String xlabel = actionRequest.getParameter("xlabel"); String ylabel = actionRequest.getParameter("ylabel"); diff --git a/plugins/monitoring/mconsole-war/src/main/webapp/WEB-INF/view/monitoringAddGraph.jsp b/plugins/monitoring/mconsole-war/src/main/webapp/WEB-INF/view/monitoringAddGraph.jsp index f7e54791d5..389a5d6106 100644 --- a/plugins/monitoring/mconsole-war/src/main/webapp/WEB-INF/view/monitoringAddGraph.jsp +++ b/plugins/monitoring/mconsole-war/src/main/webapp/WEB-INF/view/monitoringAddGraph.jsp @@ -459,7 +459,7 @@ if (!message.equals("")) { :   + name="minxss_description"> diff --git a/plugins/monitoring/mconsole-war/src/main/webapp/WEB-INF/view/monitoringAddView.jsp b/plugins/monitoring/mconsole-war/src/main/webapp/WEB-INF/view/monitoringAddView.jsp index b645dc4188..5f75ef098c 100644 --- a/plugins/monitoring/mconsole-war/src/main/webapp/WEB-INF/view/monitoringAddView.jsp +++ b/plugins/monitoring/mconsole-war/src/main/webapp/WEB-INF/view/monitoringAddView.jsp @@ -56,7 +56,7 @@ document.getElementById(x).style.display=''; } function validate() { if (! (document.addView.name.value - && document.addView.description.value )) + && document.addView.minxss_description.value )) { alert("Name and Description are required fields"); return false; @@ -100,7 +100,7 @@ function openNewWindow(theURL,winName,features) { :   - + : diff --git a/plugins/monitoring/mconsole-war/src/main/webapp/WEB-INF/view/monitoringEditGraph.jsp b/plugins/monitoring/mconsole-war/src/main/webapp/WEB-INF/view/monitoringEditGraph.jsp index d8ee95ff6f..84e42fb09d 100644 --- a/plugins/monitoring/mconsole-war/src/main/webapp/WEB-INF/view/monitoringEditGraph.jsp +++ b/plugins/monitoring/mconsole-war/src/main/webapp/WEB-INF/view/monitoringEditGraph.jsp @@ -508,7 +508,7 @@ function addOption(selectbox, value, text ) :   - + diff --git a/plugins/monitoring/mconsole-war/src/main/webapp/WEB-INF/view/monitoringEditView.jsp b/plugins/monitoring/mconsole-war/src/main/webapp/WEB-INF/view/monitoringEditView.jsp index 789f3d668a..0b3be4cc8c 100644 --- a/plugins/monitoring/mconsole-war/src/main/webapp/WEB-INF/view/monitoringEditView.jsp +++ b/plugins/monitoring/mconsole-war/src/main/webapp/WEB-INF/view/monitoringEditView.jsp @@ -73,7 +73,7 @@ document.getElementById(x).style.display=''; } function validate() { if (! (document.editView.name.value - && document.editView.description.value )) + && document.editView.minxss_description.value )) { alert("Name and Description are required fields"); return false; @@ -128,7 +128,7 @@ function openNewWindow(theURL,winName,features) { :   - + : diff --git a/plugins/monitoring/mconsole-war/src/main/webapp/WEB-INF/web.xml b/plugins/monitoring/mconsole-war/src/main/webapp/WEB-INF/web.xml index 85b5ce8524..1c084b068f 100644 --- a/plugins/monitoring/mconsole-war/src/main/webapp/WEB-INF/web.xml +++ b/plugins/monitoring/mconsole-war/src/main/webapp/WEB-INF/web.xml @@ -19,6 +19,23 @@ + + + XSSXSRFFilter + org.apache.geronimo.console.filter.XSSXSRFFilter + + enableXSRF + false + + + + XSSXSRFFilter + /* + + + org.apache.geronimo.console.filter.XSSXSRFFilter + + monitoring org.apache.pluto.core.PortletServlet diff --git a/plugins/system-database/sysdb-portlets/src/main/java/org/apache/geronimo/console/internaldb/RunSQLHelper.java b/plugins/system-database/sysdb-portlets/src/main/java/org/apache/geronimo/console/internaldb/RunSQLHelper.java index 12b01b42dc..ea7dd4aa9b 100644 --- a/plugins/system-database/sysdb-portlets/src/main/java/org/apache/geronimo/console/internaldb/RunSQLHelper.java +++ b/plugins/system-database/sysdb-portlets/src/main/java/org/apache/geronimo/console/internaldb/RunSQLHelper.java @@ -25,6 +25,8 @@ import java.sql.SQLException; import java.sql.Statement; +import org.apache.geronimo.kernel.util.InputUtils; + public class RunSQLHelper { private final static Log log = LogFactory.getLog(RunSQLHelper.class); @@ -46,6 +48,10 @@ public class RunSQLHelper { private static final String BAK_PREFIX = "BAK_"; public String createDB(String dbName) { + + // ensure there are no illegal chars in DB name + InputUtils.validateSafeInput(dbName); + String result = DB_CREATED_MSG + ": " + dbName; Connection conn = null; diff --git a/plugins/system-database/sysdb-portlets/src/main/webapp/WEB-INF/view/internaldb/runSQLNormal.jsp b/plugins/system-database/sysdb-portlets/src/main/webapp/WEB-INF/view/internaldb/runSQLNormal.jsp index 1757ecbab7..d5386ae3f5 100644 --- a/plugins/system-database/sysdb-portlets/src/main/webapp/WEB-INF/view/internaldb/runSQLNormal.jsp +++ b/plugins/system-database/sysdb-portlets/src/main/webapp/WEB-INF/view/internaldb/runSQLNormal.jsp @@ -28,9 +28,16 @@ var requiredFields = new Array("createDB"); var requiredFields2 = new Array("sqlStmts"); function validateForm1(){ + var illegalChars= /[\.]{2}|[()<>,;:\\/"'\|]/ ; var action = document.forms[formName].elements['action']; action.value="Create"; - return textElementsNotEmpty(formName, requiredFields); + if (!textElementsNotEmpty(formName, requiredFields)) + { + return false; + } else if (document.forms[formName].createDB.value.match(illegalChars)) { + alert("Database name contains illegal characters"); + return false; + } } function validateForm2(){ var action = document.forms[formName].elements['action']; diff --git a/plugins/welcome/geronimo-welcome/pom.xml b/plugins/welcome/geronimo-welcome/pom.xml index 3d9124c351..daf453f44a 100644 --- a/plugins/welcome/geronimo-welcome/pom.xml +++ b/plugins/welcome/geronimo-welcome/pom.xml @@ -39,6 +39,12 @@ + + org.apache.geronimo.plugins + console-filter + ${version} + + org.apache.geronimo.framework geronimo-plugin diff --git a/plugins/welcome/geronimo-welcome/src/main/webapp/WEB-INF/web.xml b/plugins/welcome/geronimo-welcome/src/main/webapp/WEB-INF/web.xml index a6e7ad4766..9c7fad3229 100644 --- a/plugins/welcome/geronimo-welcome/src/main/webapp/WEB-INF/web.xml +++ b/plugins/welcome/geronimo-welcome/src/main/webapp/WEB-INF/web.xml @@ -26,46 +26,17 @@ Welcome to Geronimo - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + XSSXSRFFilter + org.apache.geronimo.console.filter.XSSXSRFFilter + + + XSSXSRFFilter + /* + + + org.apache.geronimo.console.filter.XSSXSRFFilter +