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
14 changes: 14 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@

### Behaviour changes worth reading before upgrading

- **Only global admins manage Admin on the aggregated front-page weblog.**
With `site.frontpage.weblog.aggregated=true`, that weblog's templates can
read the whole site, so granting, removing or inviting an Admin there now
needs a global admin. Before turning aggregation on, review who is Admin
on the front-page weblog.

- **OAuth 1.0a needs AtomPub with OAuth authentication.** The OAuth endpoints
and the OAuth keys page answer only when AtomPub is enabled and its
authentication is set to OAuth. A request token is issued only for a
correctly signed request, and each request gets new credentials.

- **Check "Absolute URL to site" (`site.absoluteurl`) after upgrading.**
Roller no longer takes the site's URL from the first request after a start.
New installs save it during setup, and on an upgraded site where it's empty,
Expand Down Expand Up @@ -103,6 +114,9 @@

### Bug fixes

- **The comment filter works after editing a comment.** Saving a comment
on the Comments page left the filter form with a used-up form token, so
filtering then failed with an error.
- **Media filenames keep their punctuation** when inserted into an entry.
- **Changing a password ends the account's other sessions.** Saving a new
password in the profile, an administrator's reset, or disabling an account
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ boolean authorizeRequestToken(String consumerKey, String requestToken, String us
throws OAuthException;

/**
* Generate a fresh request token and secret for a consumer.
* Generate fresh temporary credentials for a consumer. A consumer with
* active access credentials keeps its current grant.
*
* @throws OAuthException
*/
Expand All @@ -133,7 +134,7 @@ void generateRequestToken(
throws OAuthException;

/**
* Generate a fresh request token and secret for a consumer.
* Exchange the approved temporary credentials for an access token.
*
* @throws OAuthException
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.sql.Timestamp;
import java.util.Date;
import java.util.UUID;
import jakarta.persistence.EntityManager;
import jakarta.persistence.LockModeType;
import jakarta.persistence.Query;
import jakarta.persistence.TypedQuery;
import net.oauth.OAuthAccessor;
Expand All @@ -31,7 +33,6 @@
import net.oauth.OAuthProblemException;
import net.oauth.OAuthServiceProvider;
import net.oauth.OAuthValidator;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand Down Expand Up @@ -159,58 +160,47 @@ public boolean authorizeRequestToken(String consumerKey, String requestToken, St
}
}

/**
* Generate a fresh request token and secret for a consumer.
* @throws OAuthException
*/
@Override
public void generateRequestToken(
OAuthAccessor accessor)
throws OAuthException {

// generate oauth_token and oauth_secret
String consumer_key = accessor.consumer.consumerKey;
// generate token and secret based on consumer_key

// for now use md5 of name + current time as token
String token_data = consumer_key + System.nanoTime();
String token = DigestUtils.md5Hex(token_data);
// for now use md5 of name + current time + token as secret
String secret_data = consumer_key + System.nanoTime() + token;
String secret = DigestUtils.md5Hex(secret_data);

accessor.requestToken = token;
accessor.tokenSecret = secret;
accessor.accessToken = null;
public void generateRequestToken(OAuthAccessor accessor) throws OAuthException {
String consumerKey = accessor.consumer.consumerKey;
EntityManager em = strategy.getEntityManager(true);
// Serializes issuance even while the consumer has no accessor row.
if (em.find(OAuthConsumerRecord.class, consumerKey, LockModeType.PESSIMISTIC_WRITE) == null) {
throw new OAuthProblemException("consumer_key_unknown");
}
OAuthAccessorRecord record = em.find(OAuthAccessorRecord.class, consumerKey,
LockModeType.PESSIMISTIC_WRITE);
if (record != null && record.getAccessToken() != null) {
throw new OAuthProblemException("permission_denied");
}

// add to the local cache
addAccessor(accessor);
accessor.requestToken = UUID.randomUUID().toString();
accessor.tokenSecret = UUID.randomUUID().toString();
if (record == null) {
addAccessor(accessor);
} else {
record.setRequestToken(accessor.requestToken);
record.setTokenSecret(accessor.tokenSecret);
record.setAuthorized(Boolean.FALSE);
record.setUserName(null);
record.setUpdated(new Timestamp(System.currentTimeMillis()));
}
}

/**
* Generate a fresh request token and secret for a consumer.
* @throws OAuthException
*/
@Override
public void generateAccessToken(OAuthAccessor accessor)
throws OAuthException {

@Override
public void generateAccessToken(OAuthAccessor accessor) throws OAuthException {
String token = UUID.randomUUID().toString();
try {
// generate oauth_token and oauth_secret
// generate token and secret based on consumer_key
String consumer_key = accessor.consumer.consumerKey;

OAuthAccessorRecord record = (OAuthAccessorRecord) strategy.load(
OAuthAccessorRecord.class, accessor.consumer.consumerKey);

// for now use md5 of name + current time as token
String token_data = consumer_key + System.nanoTime();
String token = DigestUtils.md5Hex(token_data);

record.setRequestToken(null);
record.setAccessToken(token);
strategy.store(record);

Query query = strategy.getNamedUpdate("OAuthAccessorRecord.exchangeRequestToken");
query.setParameter(1, token);
query.setParameter(2, new Timestamp(System.currentTimeMillis()));
query.setParameter(3, accessor.consumer.consumerKey);
query.setParameter(4, accessor.requestToken);
if (query.executeUpdate() != 1) {
throw new OAuthProblemException("permission_denied");
}
accessor.accessToken = token;
accessor.requestToken = null;
} catch (WebloggerException ex) {
throw new OAuthException("ERROR: generating access token", ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@
* We also provide some methods for converting to different data types.
*/
public final class WebloggerRuntimeConfig {

public static boolean isAtomPubOAuthEnabled() {
return getBooleanProperty("webservices.enableAtomPub")
&& "oauth".equals(getProperty("webservices.atomPubAuth"));
}

private static Log log = LogFactory.getLog(WebloggerRuntimeConfig.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

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

import java.nio.charset.StandardCharsets;
import java.util.LinkedHashSet;
import java.util.Set;

Expand Down Expand Up @@ -116,16 +117,26 @@ public boolean matches(CharSequence rawPassword, String encodedPassword) {
return false;
}
// BCrypt, for one, treats some other passwords as equal to a marker,
// so refuse any password whose stored value a marker matches too
for (String marker : markers) {
if (delegate.matches(marker, encodedPassword)) {
logRefusal();
return false;
// so refuse any password whose stored value a marker matches too.
// BCrypt repeats its key with a NUL after each copy and reads at most
// 72 bytes, so only a password with a NUL, or of 72 bytes or more,
// can collide; the rest skip the extra hashes.
if (mayCollideWithAMarker(rawPassword.toString())) {
for (String marker : markers) {
if (delegate.matches(marker, encodedPassword)) {
logRefusal();
return false;
}
}
}
return true;
}

private static boolean mayCollideWithAMarker(String rawPassword) {
return rawPassword.indexOf('\0') >= 0
|| rawPassword.getBytes(StandardCharsets.UTF_8).length >= 72;
}

private static void logRefusal() {
// the password itself is never logged
log.info("Refused a password that Roller treats as an external-login marker"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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.core;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import org.apache.roller.weblogger.config.WebloggerRuntimeConfig;

/** Applies the AtomPub OAuth settings before running an OAuth UI action. */
public class OAuthSettingsInterceptor extends AbstractInterceptor {

@Override
public String intercept(ActionInvocation invocation) throws Exception {
if (!WebloggerRuntimeConfig.isAtomPubOAuthEnabled()) {
return "oauth-disabled";
}
return invocation.invoke();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,18 @@ public String save() {
addError("memberPermissions.oneAdminRequired");
error = true;
}
if (!error && isAdminMembershipLocked()) {
for (WeblogPermission perms : permsList) {
String sval = getParameter("perm-" + perms.getId());
if (sval != null && !perms.hasAction(sval)
&& (perms.hasAction(WeblogPermission.ADMIN)
|| Utilities.stringToStringList(sval, ",").contains(WeblogPermission.ADMIN))) {
addError("memberPermissions.frontPageAdminsGlobalOnly");
error = true;
break;
}
}
}
// one iteration for each line (user) in the members table
Map<String, List<String>> changes = new LinkedHashMap<>();
for (WeblogPermission perms : permsList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ public String save() {
addError("Error looking up invitee");
}

if (WeblogPermission.ADMIN.equals(getPermissionString()) && isAdminMembershipLocked()) {
addError("memberPermissions.frontPageAdminsGlobalOnly");
}

// if we already have an error then bail now
if(hasActionErrors()) {
return INPUT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,7 @@ public String pingNow() {
if (pingResult.isError()) {
log.debug("Ping Result: " + pingResult);
if (pingResult.getMessage() != null && !pingResult.getMessage().isBlank()) {
addError("ping.transmittedButError");
addError(pingResult.getMessage());
addPingServerError(pingResult.getMessage());
} else {
addError("ping.transmissionFailed");
}
Expand Down Expand Up @@ -272,4 +271,13 @@ public Map<String, Boolean> getPingStatus() {
public void setPingStatus(Map<String, Boolean> pingStatus) {
this.pingStatus = pingStatus;
}

/**
* Shows the ping server's error message. It is passed as an argument, so
* it is escaped and never looked up as a message key.
*/
void addPingServerError(String message) {
addError("ping.transmittedButError");
addError("ping.serverMessage", message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.roller.weblogger.ui.struts2.util;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.interceptor.ParameterNameAware;
import com.opensymphony.xwork2.util.ValueStack;
import org.apache.commons.text.StringEscapeUtils;
import org.apache.roller.weblogger.business.UserManager;
Expand Down Expand Up @@ -54,7 +55,7 @@
* getText(key) on the param passed into setError() and setSuccess().
*/
public abstract class UIAction extends ActionSupport
implements UIActionPreparable, UISecurityEnforced, RequestAware {
implements UIActionPreparable, UISecurityEnforced, RequestAware, ParameterNameAware {

// a result that sends the user to an access denied warning
public static final String DENIED = "access-denied";
Expand Down Expand Up @@ -147,6 +148,18 @@ public boolean isUserIsAdmin() {
return false;
}

/**
* Whether Admin membership of the action weblog is closed to this user.
* On the aggregated front-page weblog, whose templates read the whole
* site, only global admins may grant, change or remove Admin.
*/
protected boolean isAdminMembershipLocked() {
Weblog weblog = getActionWeblog();
return weblog != null
&& WebloggerRuntimeConfig.isSiteWideWeblog(weblog.getHandle())
&& !isUserIsAdmin();
}

/**
* Cancel.
*
Expand Down Expand Up @@ -325,7 +338,30 @@ public void setWeblog(String weblog) {
}

public String getPageTitle() {
return getText(pageTitle);
return isPageTitleKey(pageTitle) ? getText(pageTitle) : "";
}

/**
* A page title is a message key from struts.xml or the action, made of
* letters, digits, dots, dashes and underscores. Struts evaluates part of
* an unknown key, so nothing else is looked up.
*/
static boolean isPageTitleKey(String key) {
return key != null && PAGE_TITLE_KEY.matcher(key).matches();
}

private static final java.util.regex.Pattern PAGE_TITLE_KEY =
java.util.regex.Pattern.compile("[A-Za-z0-9_.-]+");

/**
* Request parameters never set the page title. Some actions take it from
* struts.xml through their setter, which the params interceptor would
* otherwise also call with request values.
*/
@Override
public boolean acceptableParameterName(String parameterName) {
return parameterName == null
|| !parameterName.toLowerCase(Locale.ROOT).contains("pagetitle");
}

public void setPageTitle(String pageTitle) {
Expand Down
Loading
Loading