Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BugFix] Avoid token print in FE log. (backport #52511) #52664

Merged
merged 2 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 5 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.sql.analyzer.SemanticException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -342,8 +343,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 @@ -359,14 +362,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 @@ -46,6 +46,7 @@
import com.starrocks.http.BaseRequest;
import com.starrocks.http.BaseResponse;
import com.starrocks.http.HttpConnectContext;
import com.starrocks.http.WebUtils;
import com.starrocks.privilege.AccessDeniedException;
import com.starrocks.privilege.AuthorizationMgr;
import com.starrocks.qe.ConnectContext;
Expand Down Expand Up @@ -76,18 +77,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
Loading