Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
(`docs/security-model.md`).
- **An invitation offers one role.** Inviting a member accepts only Admin,
Author or Limited.
- **UI forms take plain parameter names.** The Roller UI now accepts only
plain request parameter names and `bean.<field>` (plus `group.<field>` and
`folder.<field>`) and ignores the rest. If you changed the bundled JSPs to
post nested or indexed names, flatten them.

- **OAuth 1.0a needs AtomPub with OAuth authentication.** The OAuth endpoints
and the OAuth keys page answer only when AtomPub is enabled and its
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/resources/struts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@
<interceptor-ref name="multiselect"/>
<interceptor-ref name="staticParams"/>
<interceptor-ref name="actionMappingParams"/>
<!-- Forms post plain names and one level into a form bean (or
the Planet group, or the Bookmarks folder). -->
<interceptor-ref name="params">
<param name="acceptParamNames">^\w+$,^(bean|group|folder)\.\w+$</param>
<param name="excludeParams">^action:.*,^method:.*</param>
</interceptor-ref>
<interceptor-ref name="conversionError"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. 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. For additional information regarding
* copyright in this work, please see the NOTICE file in the top level
* directory of this distribution.
*/

package org.apache.roller.weblogger.ui.struts2.util;

import java.io.InputStream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import com.opensymphony.xwork2.config.ConfigurationManager;
import com.opensymphony.xwork2.config.providers.XWorkConfigurationProvider;
import com.opensymphony.xwork2.interceptor.ParametersInterceptor;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* The params interceptor in rollerStack takes the parameter names that the
* UI forms post, and no others.
*/
class UIActionParameterNamesTest {

/** Exposes the name check that the interceptor applies to each parameter. */
static class CheckedParameters extends ParametersInterceptor {
boolean accepts(String name) {
return acceptableName(name);
}
}

private CheckedParameters params;

@BeforeEach
void setUp() throws Exception {
ConfigurationManager configurationManager = new ConfigurationManager("xwork");
configurationManager.addContainerProvider(new XWorkConfigurationProvider());
params = new CheckedParameters();
configurationManager.getConfiguration().getContainer().inject(params);
params.setAcceptParamNames(rollerStackParam("acceptParamNames"));
params.setExcludeParams(rollerStackParam("excludeParams"));
}

/** Read a param of the params interceptor in rollerStack from struts.xml. */
private static String rollerStackParam(String name) throws Exception {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
DocumentBuilder builder = dbf.newDocumentBuilder();
Document doc;
try (InputStream in = UIActionParameterNamesTest.class.getResourceAsStream("/struts.xml")) {
assertNotNull(in, "struts.xml on the classpath");
doc = builder.parse(in);
}
NodeList stacks = doc.getElementsByTagName("interceptor-stack");
for (int i = 0; i < stacks.getLength(); i++) {
Element stack = (Element) stacks.item(i);
if (!"rollerStack".equals(stack.getAttribute("name"))) {
continue;
}
NodeList refs = stack.getElementsByTagName("interceptor-ref");
for (int j = 0; j < refs.getLength(); j++) {
Element ref = (Element) refs.item(j);
if (!"params".equals(ref.getAttribute("name"))) {
continue;
}
NodeList values = ref.getElementsByTagName("param");
for (int k = 0; k < values.getLength(); k++) {
Element value = (Element) values.item(k);
if (name.equals(value.getAttribute("name"))) {
return value.getTextContent().trim();
}
}
}
}
throw new AssertionError("rollerStack params has no " + name);
}

@Test
void acceptsNamesTheFormsPost() {
for (String name : new String[] {
"weblog", "salt", "entryId", "bean.passwordText", "bean.emailAddress",
"bean.id", "group.handle", "group.title", "folder.name",
"uploadedFilesFileName", "opmlFileContentType"
}) {
assertTrue(params.accepts(name), name);
}
}

@Test
void rejectsOtherNames() {
for (String name : new String[] {
"bean.category.name", "bean['id']", "bean[0]", "bean.ids[0]",
"bean.list[0].name", "bean['tags'].size", "folder.parent.name",
"entry.title", "pingTarget.pingUrl", "group.planet.title",
"method:save", "action:foo"
}) {
assertFalse(params.accepts(name), name);
}
}
}