diff --git a/application/src/main/java/run/halo/app/theme/finders/impl/CommentPublicQueryServiceImpl.java b/application/src/main/java/run/halo/app/theme/finders/impl/CommentPublicQueryServiceImpl.java index 8655f8be97..e6a157967f 100644 --- a/application/src/main/java/run/halo/app/theme/finders/impl/CommentPublicQueryServiceImpl.java +++ b/application/src/main/java/run/halo/app/theme/finders/impl/CommentPublicQueryServiceImpl.java @@ -1,12 +1,14 @@ package run.halo.app.theme.finders.impl; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.apache.commons.lang3.ObjectUtils.defaultIfNull; import static run.halo.app.extension.index.query.QueryFactory.and; import static run.halo.app.extension.index.query.QueryFactory.equal; import static run.halo.app.extension.index.query.QueryFactory.isNull; import static run.halo.app.extension.index.query.QueryFactory.or; +import com.google.common.hash.Hashing; import java.security.Principal; import java.util.HashMap; import java.util.Optional; @@ -20,7 +22,6 @@ import org.springframework.security.core.context.SecurityContext; import org.springframework.stereotype.Component; import org.springframework.util.Assert; -import org.springframework.util.DigestUtils; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import run.halo.app.content.comment.OwnerInfo; @@ -172,7 +173,9 @@ private Mono filterCommentSensitiveData(CommentVo commentVo specOwner.setName(""); var email = owner.getEmail(); if (StringUtils.isNotBlank(email)) { - var emailHash = DigestUtils.md5DigestAsHex(email.getBytes()); + var emailHash = Hashing.sha256() + .hashString(email.toLowerCase(), UTF_8) + .toString(); if (specOwner.getAnnotations() == null) { specOwner.setAnnotations(new HashMap<>(2)); } @@ -224,7 +227,9 @@ private Mono filterReplySensitiveData(ReplyVo replyVo) { specOwner.setName(""); var email = owner.getEmail(); if (StringUtils.isNotBlank(email)) { - var emailHash = DigestUtils.md5DigestAsHex(email.getBytes()); + var emailHash = Hashing.sha256() + .hashString(email.toLowerCase(), UTF_8) + .toString(); if (specOwner.getAnnotations() == null) { specOwner.setAnnotations(new HashMap<>(2)); } diff --git a/application/src/test/java/run/halo/app/theme/finders/impl/CommentPublicQueryServiceIntegrationTest.java b/application/src/test/java/run/halo/app/theme/finders/impl/CommentPublicQueryServiceIntegrationTest.java index 463e5b0562..5413e62b4d 100644 --- a/application/src/test/java/run/halo/app/theme/finders/impl/CommentPublicQueryServiceIntegrationTest.java +++ b/application/src/test/java/run/halo/app/theme/finders/impl/CommentPublicQueryServiceIntegrationTest.java @@ -389,7 +389,8 @@ String fakeReplyJson() { "name":"", "displayName":"fake-display-name", "annotations":{ - "email-hash": "4249f4df72b475e7894fabed1c5888cf" + "email-hash": \ + "79783106d88279c6c8f94f1f4dec22bdb9f90a8d14c9d6c6628a11430e236cbf" } }, "creationTime": "2024-03-11T06:23:42.923294424Z",