Skip to content

Commit

Permalink
避免FE日志打印URL打印明文token。
Browse files Browse the repository at this point in the history
Signed-off-by: [email protected]
Signed-off-by: xyllq999 <[email protected]>
  • Loading branch information
xyllq999 committed Nov 4, 2024
1 parent 7f6af6a commit 5276f74
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
10 changes: 8 additions & 2 deletions fe/fe-core/src/main/java/com/starrocks/common/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.starrocks.catalog.Type;
import com.starrocks.common.AnalysisException;
import com.starrocks.common.TimeoutException;
import com.starrocks.http.WebUtils;
import com.starrocks.qe.ConnectContext;
import com.starrocks.server.GlobalStateMgr;
import com.starrocks.sql.analyzer.SemanticException;
Expand All @@ -64,6 +65,8 @@
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;
import java.util.function.Predicate;
import java.util.regex.Matcher;

Check failure on line 68 in fe/fe-core/src/main/java/com/starrocks/common/util/Util.java

View workflow job for this annotation

GitHub Actions / FE Code Style Check

[checkstyle] reported by reviewdog 🐶 Unused import - java.util.regex.Matcher. Raw Output: /github/workspace/./fe/fe-core/src/main/java/com/starrocks/common/util/Util.java:68:8: error: Unused import - java.util.regex.Matcher. (com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck)
import java.util.regex.Pattern;
import java.util.zip.Adler32;
import java.util.zip.DeflaterOutputStream;

Expand All @@ -74,6 +77,7 @@ public class Util {
private static final long DEFAULT_EXEC_CMD_TIMEOUT_MS = 600000L;

public static final String AUTO_GENERATED_EXPR_ALIAS_PREFIX = "EXPR$";
private static final Pattern TOKEN_PATTERN = Pattern.compile("token=[^&]*");

private static final String[] ORDINAL_SUFFIX =
new String[] {"th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th"};
Expand Down Expand Up @@ -321,8 +325,10 @@ public static String getResultForUrl(String urlStr, String encodedAuthInfo, int
int readTimeoutMs) {
StringBuilder sb = new StringBuilder();
InputStream stream = null;
String safeUrl = urlStr;
try {
URL url = new URL(urlStr);
safeUrl = WebUtils.sanitizeHttpReqUri(urlStr);
URLConnection conn = url.openConnection();
if (encodedAuthInfo != null) {
conn.setRequestProperty("Authorization", "Basic " + encodedAuthInfo);
Expand All @@ -338,14 +344,14 @@ public static String getResultForUrl(String urlStr, String encodedAuthInfo, int
sb.append(line);
}
} catch (Exception e) {
LOG.warn("failed to get result from url: {}. {}", urlStr, e.getMessage());
LOG.warn("failed to get result from url: {}. {}", safeUrl, e.getMessage());
return null;
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
LOG.warn("failed to close stream when get result from url: {}", urlStr, e);
LOG.warn("failed to close stream when get result from url: {}", safeUrl, e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,8 @@
import com.starrocks.common.Pair;
import com.starrocks.common.StarRocksHttpException;
import com.starrocks.common.util.UUIDUtil;
import com.starrocks.http.ActionController;
import com.starrocks.http.BaseAction;
import com.starrocks.http.BaseRequest;
import com.starrocks.http.BaseResponse;
import com.starrocks.http.HttpConnectContext;
import com.starrocks.common.util.Util;

Check failure on line 45 in fe/fe-core/src/main/java/com/starrocks/http/rest/RestBaseAction.java

View workflow job for this annotation

GitHub Actions / FE Code Style Check

[checkstyle] reported by reviewdog 🐶 Unused import - com.starrocks.common.util.Util. Raw Output: /github/workspace/./fe/fe-core/src/main/java/com/starrocks/http/rest/RestBaseAction.java:45:8: error: Unused import - com.starrocks.common.util.Util. (com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck)
import com.starrocks.http.*;

Check failure on line 46 in fe/fe-core/src/main/java/com/starrocks/http/rest/RestBaseAction.java

View workflow job for this annotation

GitHub Actions / FE Code Style Check

[checkstyle] reported by reviewdog 🐶 Using the '.*' form of import should be avoided - com.starrocks.http.*. Raw Output: /github/workspace/./fe/fe-core/src/main/java/com/starrocks/http/rest/RestBaseAction.java:46:26: error: Using the '.*' form of import should be avoided - com.starrocks.http.*. (com.puppycrawl.tools.checkstyle.checks.imports.AvoidStarImportCheck)
import com.starrocks.privilege.AccessDeniedException;
import com.starrocks.privilege.AuthorizationMgr;
import com.starrocks.qe.ConnectContext;
Expand Down Expand Up @@ -92,18 +89,20 @@ public RestBaseAction(ActionController controller) {
@Override
public void handleRequest(BaseRequest request) {
BaseResponse response = new BaseResponse();
String url = request.getRequest().uri();
try {
url = WebUtils.sanitizeHttpReqUri(request.getRequest().uri());
execute(request, response);
} catch (AccessDeniedException accessDeniedException) {
LOG.warn("failed to process url: {}", request.getRequest().uri(), accessDeniedException);
LOG.warn("failed to process url: {}", url, accessDeniedException);
response.updateHeader(HttpHeaderNames.WWW_AUTHENTICATE.toString(), "Basic realm=\"\"");
response.appendContent(new RestBaseResult(getErrorRespWhenUnauthorized(accessDeniedException)).toJson());
writeResponse(request, response, HttpResponseStatus.UNAUTHORIZED);
} catch (DdlException e) {
LOG.warn("fail to process url: {}", request.getRequest().uri(), e);
LOG.warn("fail to process url: {}", url, e);
sendResult(request, response, new RestBaseResult(e.getMessage()));
} catch (Exception e) {
LOG.warn("fail to process url: {}", request.getRequest().uri(), e);
LOG.warn("fail to process url: {}", url, e);
String msg = e.getMessage();
if (msg == null) {
msg = e.toString();
Expand Down

0 comments on commit 5276f74

Please sign in to comment.