Skip to content

Commit

Permalink
improve secrets removal parser and catch possible exception and log it
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Feb 4, 2025
1 parent d961589 commit e9599ab
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
36 changes: 21 additions & 15 deletions core/src/main/java/lucee/runtime/exp/PageExceptionImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.LinkedList;

import lucee.commons.io.IOUtil;
import lucee.commons.io.log.Log;
import lucee.commons.io.log.LogUtil;
import lucee.commons.io.res.Resource;
import lucee.commons.io.res.util.ResourceUtil;
Expand Down Expand Up @@ -141,28 +142,33 @@ private static String filterSecrets(String msg, int startIndex) {
// S3 secret
startIndex = StringUtil.indexOfIgnoreCase(msg, "s3://", startIndex);
if (startIndex != -1) {
startIndex += 5;
int atIndex = msg.indexOf('@', startIndex + 1);
int colonIndex = msg.indexOf(':', startIndex + 1);
int slashIndex = msg.indexOf('/', startIndex + 1);
if (atIndex != -1) {
if (colonIndex != -1 && colonIndex < atIndex) {
String secretAccessKey = msg.substring(colonIndex + 1, atIndex);
try {
startIndex += 5;
int atIndex = msg.indexOf('@', startIndex + 1);
int colonIndex = msg.indexOf(':', startIndex + 1);
int slashIndex = msg.indexOf('/', startIndex + 1);
if (atIndex != -1) {
if (colonIndex != -1 && colonIndex < atIndex) {
String secretAccessKey = msg.substring(colonIndex + 1, atIndex);
int index = secretAccessKey.indexOf(':');
if (index != -1) {
secretAccessKey = secretAccessKey.substring(0, index);
}
msg = StringUtil.replace(msg, secretAccessKey, "{SECRET_ACCESS_KEY}", false, true);
return msg;
}
}
if (slashIndex != -1 && colonIndex != -1 && slashIndex > (colonIndex + 1)) {
String secretAccessKey = msg.substring(colonIndex + 1, slashIndex);
int index = secretAccessKey.indexOf(':');
if (index != -1) {
secretAccessKey = secretAccessKey.substring(0, index);
}
msg = StringUtil.replace(msg, secretAccessKey, "{SECRET_ACCESS_KEY}", false, true);
return msg;
}
}
if (slashIndex != -1) {
String secretAccessKey = msg.substring(colonIndex + 1, slashIndex);
int index = secretAccessKey.indexOf(':');
if (index != -1) {
secretAccessKey = secretAccessKey.substring(0, index);
}
msg = StringUtil.replace(msg, secretAccessKey, "{SECRET_ACCESS_KEY}", false, true);
catch (Exception e) {
LogUtil.log(Log.LEVEL_ERROR, "parsing", "failed to parse [" + msg + "] with startindex [" + startIndex + "]");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion loader/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project default="core" basedir="." name="Lucee"
xmlns:resolver="antlib:org.apache.maven.resolver.ant">

<property name="version" value="6.1.2.24-SNAPSHOT"/>
<property name="version" value="6.1.2.25-SNAPSHOT"/>

<taskdef uri="antlib:org.apache.maven.resolver.ant" resource="org/apache/maven/resolver/ant/antlib.xml">
<classpath>
Expand Down
2 changes: 1 addition & 1 deletion loader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.lucee</groupId>
<artifactId>lucee</artifactId>
<version>6.1.2.24-SNAPSHOT</version>
<version>6.1.2.25-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Lucee Loader Build</name>
Expand Down

0 comments on commit e9599ab

Please sign in to comment.