Skip to content

Commit

Permalink
Changed logger to lo4j, log invalid login with username (log4shell in…
Browse files Browse the repository at this point in the history
…put). Added commons-collection to do a deserialization RCE on newer java version based on log4shell.
  • Loading branch information
bmvermeer committed Jan 6, 2022
1 parent 4625d86 commit 186ff5c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import io.github.todolist.core.domain.Todo;
import io.github.todolist.core.repository.api.TodoRepository;
import org.apache.commons.collections.list.UnmodifiableList;
import org.springframework.stereotype.Repository;

import javax.persistence.EntityManager;
Expand Down Expand Up @@ -57,7 +58,7 @@ public Todo getTodoById(final long id) {
public List<Todo> getTodoListByUser(final long userId) {
TypedQuery<Todo> query = entityManager.createNamedQuery("findTodosByUser", Todo.class);
query.setParameter(1, userId);
return query.getResultList();
return UnmodifiableList.decorate(query.getResultList());
}

/**
Expand All @@ -67,7 +68,7 @@ public List<Todo> getTodoListByUserAndTitle(final long userId, final String titl
TypedQuery<Todo> query = entityManager.createNamedQuery("findTodosByTitle", Todo.class);
query.setParameter(1, userId);
query.setParameter(2, "%" + title.toUpperCase() + "%");
return query.getResultList();
return UnmodifiableList.decorate(query.getResultList());
}

/**
Expand Down
7 changes: 7 additions & 0 deletions todolist-goof/todolist-web-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,12 @@
<version>4.3.1.Final</version>
</dependency>

<!--vulnerable commons collections (deserialization) -->
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.1</version>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public static String getStatusLabel(boolean status) {
* @param input text to which apply the style for each matched pattern
* @param pattern the pattern to highlight
* @return the transformed text
*
*/
public static String highlight(final String input, final String pattern) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import io.github.benas.todolist.web.action.BaseAction;
import io.github.benas.todolist.web.common.form.ChangePasswordForm;
import io.github.benas.todolist.web.common.form.RegistrationForm;
Expand All @@ -45,7 +45,7 @@
*/
public class AccountAction extends BaseAction {

private static final Logger LOGGER = LoggerFactory.getLogger(AccountAction.class.getName());
private static final Logger LOGGER = LogManager.getLogger(AccountAction.class.getName());

private ChangePasswordForm changePasswordForm;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
package io.github.benas.todolist.web.action.user;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import io.github.benas.todolist.web.action.BaseAction;
import io.github.benas.todolist.web.common.form.LoginForm;
import io.github.benas.todolist.web.common.util.TodoListUtils;
Expand All @@ -39,7 +39,7 @@
*/
public class SessionAction extends BaseAction {

private static final Logger LOGGER = LoggerFactory.getLogger(SessionAction.class.getName());
private static final Logger LOGGER = LogManager.getLogger(SessionAction.class.getName());

private LoginForm loginForm;

Expand All @@ -61,6 +61,7 @@ public String doLogin() {
session.put(TodoListUtils.SESSION_USER, user);
return Action.SUCCESS;
} else {
LOGGER.error("Login failed for email: " + loginForm.getEmail());
error = getText("login.error.global.invalid");
return Action.INPUT;
}
Expand Down

0 comments on commit 186ff5c

Please sign in to comment.