Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
3891bd7
Decline only pending invitations and keep a weblog's last admin from …
mraible Nov 17, 2026
5fe75c9
Escape the commenter's user name in the LDAP comment authenticator's …
mraible Nov 18, 2026
4dc8846
Limit search query length and treat queries Lucene cannot run as find…
mraible Nov 18, 2026
9a588b6
Check for a remaining weblog admin and change memberships in one lock…
mraible Nov 18, 2026
199f58d
Remove pending invitations along with their weblog or user
mraible Nov 18, 2026
ad9de07
Handle disabled members and non-members in weblog membership changes
mraible Nov 19, 2026
265b8a3
Key Members page rows by permission so disabled members can be changed
mraible Nov 20, 2026
adcd464
Drop the opening quote of a phrase that the search query limit cuts off
mraible Nov 18, 2026
fe13d52
Check that a membership change is for a member before locking the weblog
mraible Nov 20, 2026
c08fa3f
Show no change counts on the Members page when saving fails
mraible Nov 20, 2026
fa59447
Show the outcome of resigning from a weblog on the main menu
mraible Nov 20, 2026
b809b07
Cap search queries without counting escaped quotes or surrounding whi…
mraible Nov 20, 2026
c6838b3
Treat only query errors from Lucene as a search that finds nothing
mraible Nov 20, 2026
d9dffbf
Tell a member who declines an accepted invitation that they're alread…
mraible Nov 20, 2026
13f860f
Tidy the membership test cleanup
mraible Nov 20, 2026
94621fc
Merge remote-tracking branch 'origin/roller-6.1.x' into weblog-member…
mraible Nov 20, 2026
2ddf152
Say in CHANGES how resigning, declining and search queries behave now
mraible Nov 20, 2026
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
11 changes: 7 additions & 4 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
refused with 413 before they're stored, and entries show the creator's
email address only to the creator (also in MetaWeblog responses) (#328).

- **Search queries are limited to 256 characters**, and a query the search
engine can't run finds nothing (#334).
- **Search queries are limited to 256 characters**, after spaces around them
are dropped, and a query the search engine can't run finds nothing (#334).

- **Weblog pages ignore a `skipCache` query parameter** (#325).

Expand Down Expand Up @@ -79,8 +79,11 @@
- **"nofollow" is added to links that need it.** `addNofollow` only touched
links that already had `rel="nofollow"` (#330).
- **Tags of a scheduled entry are counted once, when it goes live** (#328).
- **A weblog's only administrator can't resign from it**, and declining an
invitation only removes a pending invitation (#334).
- **A weblog's only administrator can't resign from it**, and the main menu
says why. Resigning now redirects to the main menu, as accepting and
declining an invitation do. Declining an invitation only removes a pending
invitation, and declining one you already accepted says you're already a
member (#334).
- **New passwords can't be the external-login placeholder.** Registration,
the profile page and user administration refuse
`users.passwords.externalAuthValue` (by default `<externalAuth>`) as a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,21 @@ List<WeblogPermission> getWeblogPermissions(Weblog weblog)
List<WeblogPermission> getPendingWeblogPermissions(Weblog weblog)
throws WebloggerException;

/**
* Change the memberships of a weblog as one operation that keeps the
* weblog's administrators. Changes for the same weblog are serialized:
* the weblog's row stays locked until the caller flushes or releases the
* session, so the administrator check and the changes cannot interleave
* with another membership update.
* @param weblog Weblog whose memberships change
* @param changes New actions by user name; a null value removes that
* user's membership
* @return false, with nothing changed, if the changes would remove the
* weblog's last administrator (pending invitations don't count)
*/
boolean updateWeblogMembership(Weblog weblog, Map<String, List<String>> changes)
throws WebloggerException;

/**
* Get all permissions (pending or actual) for a weblog.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import jakarta.persistence.EntityManager;
import jakarta.persistence.LockModeType;
import jakarta.persistence.NoResultException;
import jakarta.persistence.PersistenceException;
import jakarta.persistence.TypedQuery;
import org.apache.roller.weblogger.config.WebloggerConfig;
import org.apache.roller.weblogger.pojos.GlobalPermission;
Expand Down Expand Up @@ -77,7 +80,10 @@ public void removeUser(User user) throws WebloggerException {
String userName = user.getUserName();

// remove permissions, maintaining both sides of relationship
List<WeblogPermission> perms = getWeblogPermissions(user);
List<WeblogPermission> perms = new ArrayList<>(getWeblogPermissions(user));
// and pending invitations, which a new user of the same name would
// otherwise inherit
perms.addAll(getPendingWeblogPermissions(user));
for (WeblogPermission perm : perms) {
this.strategy.remove(perm);
}
Expand Down Expand Up @@ -513,6 +519,10 @@ public void declineWeblogPermission(Weblog weblog, User user) throws WebloggerEx
} catch (NoResultException ignored) {
throw new WebloggerException("ERROR: permission not found");
}
// only an invitation can be declined; members leave by resigning
if (!existingPerm.isPending()) {
throw new WebloggerException("ERROR: permission is not a pending invitation");
}
// remove permission
this.strategy.remove(existingPerm);
}
Expand Down Expand Up @@ -562,6 +572,94 @@ public List<WeblogPermission> getWeblogPermissions(Weblog weblog) throws Weblogg
return q.getResultList();
}

@Override
public boolean updateWeblogMembership(Weblog weblog, Map<String, List<String>> changes)
throws WebloggerException {

List<WeblogPermission> perms;
try {
// every change has to be for a member of, or a user invited to,
// the weblog; check before taking the lock, so a request for
// someone else's weblog doesn't wait for or hold it
checkMemberships(readMemberships(weblog.getHandle()), changes);

// lock the weblog's row so membership updates for it run one at
// a time
EntityManager em = strategy.getEntityManager(true);
Weblog locked = em.find(Weblog.class, weblog.getId(), LockModeType.PESSIMISTIC_WRITE);
if (locked == null) {
throw new WebloggerException("ERROR: weblog not found");
}

// read the memberships again now that the lock is held
perms = readMemberships(locked.getHandle());
checkMemberships(perms, changes);
} catch (PersistenceException e) {
throw new WebloggerException(e);
}

boolean adminBefore = false;
boolean adminAfter = false;
for (WeblogPermission perm : perms) {
if (perm.isPending()) {
continue;
}
// a disabled user can't manage the weblog
if (perm.getUser() == null || !Boolean.TRUE.equals(perm.getUser().getEnabled())) {
continue;
}
boolean admin = perm.hasAction(WeblogPermission.ADMIN);
adminBefore |= admin;
if (changes.containsKey(perm.getUserName())) {
List<String> actions = changes.get(perm.getUserName());
admin = actions != null && actions.contains(WeblogPermission.ADMIN);
}
adminAfter |= admin;
}
if (adminBefore && !adminAfter) {
return false;
}

for (WeblogPermission perm : perms) {
if (!changes.containsKey(perm.getUserName())) {
continue;
}
// change the row that was read, which also works for a disabled
// user and leaves an invitation pending
List<String> actions = changes.get(perm.getUserName());
if (actions == null) {
this.strategy.remove(perm);
} else {
perm.setActionsAsList(actions);
this.strategy.store(perm);
}
}
return true;
}

// a weblog's memberships and invitations, read from the database rather
// than the cache
private List<WeblogPermission> readMemberships(String handle) throws WebloggerException {
TypedQuery<WeblogPermission> q = strategy.getNamedQuery("WeblogPermission.getByWeblogIdIncludingPending",
WeblogPermission.class);
q.setParameter(1, handle);
q.setHint("eclipselink.refresh", "true");
return q.getResultList();
}

private static void checkMemberships(List<WeblogPermission> perms, Map<String, List<String>> changes)
throws WebloggerException {
for (String userName : changes.keySet()) {
boolean found = false;
for (WeblogPermission perm : perms) {
found |= perm.getUserName().equals(userName);
}
if (!found) {
throw new WebloggerException("ERROR: permission not found");
}
}
}

@Override
public List<WeblogPermission> getWeblogPermissionsIncludingPending(Weblog weblog) throws WebloggerException {
TypedQuery<WeblogPermission> q = strategy.getNamedQuery("WeblogPermission.getByWeblogIdIncludingPending",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,11 @@ private void removeWeblogContents(Weblog weblog)
removeCategories.setParameter(1, weblog);
removeCategories.executeUpdate();

// remove permissions
for (WeblogPermission perm : umgr.getWeblogPermissions(weblog)) {
umgr.revokeWeblogPermission(perm.getWeblog(), perm.getUser(), WeblogPermission.ALL_ACTIONS);
// remove permissions, and pending invitations, which a new weblog with
// the same handle would otherwise inherit. The rows are removed
// directly, as a disabled user's can't be looked up through the user.
for (WeblogPermission perm : umgr.getWeblogPermissionsIncludingPending(weblog)) {
this.strategy.remove(perm);
}

// flush the changes before returning. This is required as there is a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.TopFieldDocs;
import org.apache.lucene.util.automaton.TooComplexToDeterminizeException;
import org.apache.roller.weblogger.business.search.IndexManager;

/**
Expand Down Expand Up @@ -150,6 +151,15 @@ public void doRun() {
} catch (ParseException e) {
// who cares?
parseError = e.getMessage();

} catch (IllegalArgumentException | IndexSearcher.TooManyClauses
| TooComplexToDeterminizeException e) {
// Lucene rejects some queries that parse, such as an unfinished
// regular expression or a negative phrase slop, only when it
// builds or runs them. Treat them like a query that does not parse.
logger.debug("Could not run search query: " + e.getMessage());
searchresults = null;
parseError = e.getMessage() != null ? e.getMessage() : e.getClass().getName();
}
// don't need to close the reader, since we didn't do any writing!
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import javax.naming.NamingException;
import javax.naming.ldap.InitialLdapContext;
import javax.naming.ldap.LdapContext;
import javax.naming.ldap.Rdn;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

Expand Down Expand Up @@ -152,7 +153,7 @@ public boolean authenticate(HttpServletRequest request) {
* @param ldapUser
* @return
*/
private String getQualifedDc(String ldapDc, String ldapOu, String ldapUser) {
String getQualifedDc(String ldapDc, String ldapOu, String ldapUser) {
String qualifedDc = "";
for (String token : StringUtils.delimitedListToStringArray(ldapDc, ",")) {
if (!qualifedDc.isEmpty()) {
Expand All @@ -161,7 +162,9 @@ private String getQualifedDc(String ldapDc, String ldapOu, String ldapUser) {
qualifedDc += "dc=" + token;
}

return "uid=" + ldapUser + ", ou=" + ldapOu + "," + qualifedDc;
// escape the user name so it stays the uid value and cannot add or
// change other parts of the bind name
return "uid=" + Rdn.escapeValue(ldapUser) + ", ou=" + ldapOu + "," + qualifedDc;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public WeblogFeedRequest(HttpServletRequest request)
this.page = parsePageNum(request.getParameter("page"));

if(request.getParameter("q") != null && !request.getParameter("q").isBlank()) {
this.term = URLUtilities.decode(request.getParameter("q"));
this.term = WeblogSearchRequest.capQuery(URLUtilities.decode(request.getParameter("q")));
}

if(this.tags != null && !this.tags.isEmpty() && this.weblogCategoryName != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public class WeblogSearchRequest extends WeblogRequest {
private static Log log = LogFactory.getLog(WeblogSearchRequest.class);

public static final String SEARCH_SERVLET = "/roller-ui/rendering/search";

/** Longest search query kept, plenty for a person to type. */
public static final int MAX_QUERY_LENGTH = 256;

// lightweight attributes
private String query = null;
Expand Down Expand Up @@ -82,7 +85,7 @@ public WeblogSearchRequest(HttpServletRequest request)
* cat - limit results to a certain weblogCategoryName
*/
if(request.getParameter("q") != null && !request.getParameter("q").isBlank()) {
this.query = request.getParameter("q");
this.query = capQuery(request.getParameter("q"));
}

this.pageNum = parsePageNum(request.getParameter("page"));
Expand All @@ -93,6 +96,48 @@ public WeblogSearchRequest(HttpServletRequest request)
}
}

/**
* Keeps the first MAX_QUERY_LENGTH characters of a search query, so one
* request cannot hand the query parser unbounded work, such as thousands
* of nested parentheses. Leading and trailing whitespace doesn't count.
* Does not split a surrogate pair, and drops the opening quote of a
* phrase, or an escape character, that the cap cuts off.
*/
public static String capQuery(String query) {
if (query == null) {
return null;
}
query = query.strip();
if (query.length() <= MAX_QUERY_LENGTH) {
return query;
}
int end = MAX_QUERY_LENGTH;
if (Character.isHighSurrogate(query.charAt(end - 1))) {
end--;
}
String capped = query.substring(0, end);
// find a quote whose phrase the cap cut off; an escaped quote doesn't
// start or end a phrase
int openQuote = -1;
for (int i = 0; i < capped.length(); i++) {
char c = capped.charAt(i);
if (c == '\\') {
if (i == capped.length() - 1) {
// the cap cut off the escaped character
capped = capped.substring(0, i);
}
i++;
} else if (c == '"') {
openQuote = openQuote < 0 ? i : -1;
}
}
// drop it, so the rest still parses
if (openQuote >= 0) {
capped = capped.substring(0, openQuote) + capped.substring(openQuote + 1);
}
return capped;
}

public String getQuery() {
return query;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ public String decline() {
WeblogManager wmgr = WebloggerFactory.getWeblogger().getWeblogManager();
Weblog weblog = wmgr.getWeblog(getInviteId());
String handle = weblog.getHandle();
// a page loaded before the invitation was accepted still offers
// to decline it
if (umgr.getWeblogPermission(weblog, getAuthenticatedUser()) != null) {
addError("yourWebsites.declineMember", handle);
return DONE;
}
// TODO ROLLER_2.0: notify inviter that invitee has declined invitation
// TODO EXCEPTIONS: better exception handling here
umgr.declineWeblogPermission(weblog, getAuthenticatedUser());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,21 @@ public String execute() {
* Resign from a weblog
*/
public String resign() {
// isWeblogRequired() is false, so the weblog may not exist
if (getActionWeblog() == null) {
return DENIED;
}
try {
UserManager umgr = WebloggerFactory.getWeblogger().getUserManager();
// TODO: notify website members that user has resigned
// TODO EXCEPTIONS: better exception handling
umgr.revokeWeblogPermission(getActionWeblog(), getAuthenticatedUser(), WeblogPermission.ALL_ACTIONS);
// the check and the removal run as one operation, so concurrent
// membership changes can't leave the weblog without an admin
if (!umgr.updateWeblogMembership(getActionWeblog(),
Collections.singletonMap(getAuthenticatedUser().getUserName(), null))) {
addError("yourWebsites.resign.lastAdmin", getWeblog());
return SUCCESS;
}
WebloggerFactory.getWeblogger().flush();
addMessage("yourWebsites.resigned", getWeblog());
} catch (WebloggerException ex) {
Expand Down
Loading
Loading