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
15 changes: 15 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@
weblog's public URLs. Comment posts, RSD and
`/roller-ui/rendering/media-resources/` links in entries work as before.

- **User details in templates.** The user and visitor objects no longer
provide an email address. Bundled themes use the existing name properties.
- **Longer passwords on account forms.** Registration, profile and the
administrator's user form take passwords up to 72 UTF-8 bytes.
- **Request and result limits.** Multipart requests to the Roller UI allow
five files of the "Maximum file size" set in Site Settings plus 1 MiB of
form data (11 MiB with the default 2 MB), and the limit follows that setting.
XML-RPC request limits allow for the configured file size and its base64
encoding, up to 32 MiB, with a 1 MiB limit when uploads are off. Blogger
and MetaWeblog return at most 200 recent entries, including when the
requested count is zero or negative.
- **Configuration and weblog logging.** Configuration debug messages show
property names without values, and weblog lookup errors print handles on
one line.

### Bug fixes

- **Media filenames keep their punctuation** when inserted into an entry.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.text.StringEscapeUtils;
import org.apache.roller.weblogger.WebloggerException;
import org.apache.roller.weblogger.business.pings.AutoPingManager;
import org.apache.roller.weblogger.business.pings.PingTargetManager;
Expand Down Expand Up @@ -376,7 +377,7 @@ public Weblog getWeblogByHandle(String handle, Boolean visible) throws Weblogger
if (handle == null) {
throw new WebloggerException("Handle cannot be null");
} else if (!isAlphanumeric(handle)) {
throw new WebloggerException("Invalid handle: '"+handle+"'");
throw new WebloggerException("Invalid handle: '" + StringEscapeUtils.escapeJava(handle) + "'");
}

// check cache first
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,7 @@ public final class WebloggerConfig {
// finally we can start logging...
log = LogFactory.getLog(WebloggerConfig.class);

// some debugging for those that want it
if(log.isDebugEnabled()) {
log.debug("WebloggerConfig looks like this ...");

String key;
Enumeration<Object> keys = config.keys();
while(keys.hasMoreElements()) {
key = (String) keys.nextElement();
log.debug(key+"="+config.getProperty(key));
}
}
log.debug("Loaded " + config.size() + " configuration properties");

}

Expand All @@ -173,7 +163,7 @@ public static void init() {
*/
public static String getProperty(String key) {
String value = config.getProperty(key);
log.debug("Fetching property ["+key+"="+value+"]");
log.debug("Fetching property [" + key + "]");
return value == null ? null : value.trim();
}

Expand All @@ -185,7 +175,7 @@ public static String getProperty(String key) {
*/
public static String getProperty(String key, String defaultValue) {
String value = config.getProperty(key);
log.debug("Fetching property ["+key+"="+value+",defaultValue="+defaultValue+"]");
log.debug("Fetching property [" + key + "]");
if (value == null) {
return defaultValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,6 @@ private static String escapeOnce(String name) {
}


public String getEmailAddress() {
return this.pojo.getEmailAddress();
}


public Date getDateCreated() {
return this.pojo.getDateCreated();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
/*
* 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.core.filters;

import java.io.IOException;
import java.util.Locale;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ReadListener;
import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.roller.weblogger.config.WebloggerRuntimeConfig;

/**
* Limits the size of multipart requests to the Roller UI, ahead of the Struts
* filter that parses them. The limit follows the site's
* <code>uploads.file.maxsize</code> setting, so raising it in Site Settings
* also raises this limit: room for five files of that size (the media upload
* form has five file fields) plus 1 MiB for the other form fields.
*/
public class MultipartSizeFilter implements Filter {

private static final Log LOG = LogFactory.getLog(MultipartSizeFilter.class);
private static final long MIB = 1024L * 1024L;
static final int FILE_FIELDS = 5;
private static final long FORM_BYTES = MIB;
private static final double DEFAULT_FILE_MEGABYTES = 2.0;

@Override
public void init(FilterConfig filterConfig) {
// nothing to configure
}

@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {

HttpServletRequest httpRequest = (HttpServletRequest) request;
String contentType = httpRequest.getContentType();
if (contentType == null
|| !contentType.toLowerCase(Locale.ROOT).startsWith("multipart/")) {
chain.doFilter(request, response);
return;
}

long limit = maxRequestBytes();
if (httpRequest.getContentLengthLong() > limit) {
LOG.warn("Refusing a multipart request of " + httpRequest.getContentLengthLong()
+ " bytes; the limit is " + limit + " bytes (uploads.file.maxsize)");
HttpServletResponse httpResponse = (HttpServletResponse) response;
httpResponse.sendError(HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE);
return;
}

// the declared length may be absent, so count what is actually read
ServletInputStream input = new LimitedInputStream(httpRequest.getInputStream(), limit);
chain.doFilter(new HttpServletRequestWrapper(httpRequest) {
@Override
public ServletInputStream getInputStream() {
return input;
}
}, response);
}

/** @return the largest multipart request the current upload setting allows */
static long maxRequestBytes() {
double megabytes = DEFAULT_FILE_MEGABYTES;
String value = WebloggerRuntimeConfig.getProperty("uploads.file.maxsize");
if (value != null) {
try {
double configured = Double.parseDouble(value.trim());
if (configured > 0) {
megabytes = configured;
}
} catch (NumberFormatException e) {
LOG.debug("uploads.file.maxsize is not a number, using the default");
}
}
return (long) Math.ceil(megabytes * MIB) * FILE_FIELDS + FORM_BYTES;
}

@Override
public void destroy() {
// nothing to release
}

/** Fails a read once more than the limit has been read. */
private static final class LimitedInputStream extends ServletInputStream {

private final ServletInputStream input;
private final long limit;
private long count = 0;

LimitedInputStream(ServletInputStream input, long limit) {
this.input = input;
this.limit = limit;
}

private void counted(long n) throws IOException {
if (n > 0) {
count += n;
if (count > limit) {
throw new IOException("Multipart request is larger than " + limit + " bytes");
}
}
}

@Override
public int read() throws IOException {
int b = input.read();
if (b >= 0) {
counted(1);
}
return b;
}

@Override
public int read(byte[] buffer, int offset, int length) throws IOException {
int n = input.read(buffer, offset, length);
counted(n);
return n;
}

@Override
public boolean isFinished() {
return input.isFinished();
}

@Override
public boolean isReady() {
return input.isReady();
}

@Override
public void setReadListener(ReadListener listener) {
input.setReadListener(listener);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@

package org.apache.roller.weblogger.ui.core.filters;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ReadListener;
import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
Expand All @@ -33,11 +38,14 @@

/**
* Gates the XML-RPC endpoint on <code>webservices.enableXmlRpc</code>, ahead of
* the servlet, so a disabled service is not reachable.
* the servlet. Buffers a bounded request body before the XML-RPC parser reads it.
*/
public class XmlRpcEnabledFilter implements Filter {

private static final Log LOG = LogFactory.getLog(XmlRpcEnabledFilter.class);
private static final int MIB = 1024 * 1024;
private static final int MAX_REQUEST_BYTES = 32 * MIB;
private static final int ENVELOPE_BYTES = 64 * 1024;

@Override
public void init(FilterConfig filterConfig) {
Expand All @@ -48,16 +56,103 @@ public void init(FilterConfig filterConfig) {
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {

HttpServletResponse httpResponse = (HttpServletResponse) response;
if (!WebloggerRuntimeConfig.getBooleanProperty("webservices.enableXmlRpc")) {
LOG.warn("XML-RPC service is disabled; rejecting request");
HttpServletResponse httpResponse = (HttpServletResponse) response;
httpResponse.setStatus(HttpServletResponse.SC_NOT_FOUND);
httpResponse.setContentType("text/plain;charset=UTF-8");
httpResponse.getWriter().write("XML-RPC service is disabled");
sendText(httpResponse, HttpServletResponse.SC_NOT_FOUND, "XML-RPC service is disabled");
return;
}

chain.doFilter(request, response);
HttpServletRequest httpRequest = (HttpServletRequest) request;
if (!"POST".equals(httpRequest.getMethod())) {
chain.doFilter(request, response);
return;
}

String encoding = httpRequest.getHeader("Content-Encoding");
if (encoding != null && !encoding.isBlank() && !"identity".equalsIgnoreCase(encoding.trim())) {
sendText(httpResponse, HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "Unsupported Content-Encoding");
return;
}

int limit = maxRequestBytes();
if (httpRequest.getContentLengthLong() > limit) {
sendText(httpResponse, HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE, "XML-RPC request is too large");
return;
}
byte[] body = httpRequest.getInputStream().readNBytes(limit + 1);
if (body.length > limit) {
sendText(httpResponse, HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE, "XML-RPC request is too large");
return;
}

chain.doFilter(new HttpServletRequestWrapper(httpRequest) {
private final ServletInputStream input = bodyStream(body);

@Override
public ServletInputStream getInputStream() {
return input;
}
}, response);
}

private static int maxRequestBytes() {
if (!WebloggerRuntimeConfig.getBooleanProperty("uploads.enabled")) {
return MIB;
}
String value = WebloggerRuntimeConfig.getProperty("uploads.file.maxsize");
if (value == null) {
return MIB;
}
double megabytes;
try {
megabytes = Double.parseDouble(value);
} catch (NumberFormatException e) {
return MIB;
}
if (!(megabytes > 0)) {
return MIB;
}
double uploadBytes = Math.ceil(megabytes * MIB);
// Allow base64, line breaks at 76 columns, and the surrounding XML.
double base64Bytes = Math.ceil(uploadBytes / 3) * 4 * 78 / 76;
return (int) Math.min(MAX_REQUEST_BYTES, Math.max(MIB, base64Bytes + ENVELOPE_BYTES));
}

private static ServletInputStream bodyStream(byte[] body) {
ByteArrayInputStream input = new ByteArrayInputStream(body);
return new ServletInputStream() {
@Override
public int read() {
return input.read();
}

@Override
public int read(byte[] buffer, int offset, int length) {
return input.read(buffer, offset, length);
}

@Override
public boolean isFinished() {
return input.available() == 0;
}

@Override
public boolean isReady() {
return true;
}

@Override
public void setReadListener(ReadListener listener) {
throw new IllegalStateException("XML-RPC reads requests synchronously");
}
};
}

private static void sendText(HttpServletResponse response, int status, String message) throws IOException {
response.setStatus(status);
response.setContentType("text/plain;charset=UTF-8");
response.getWriter().write(message);
}

@Override
Expand Down
Loading
Loading