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

[ISSUE #4701] Fix bypass authentication(identity) problem. #4703

Merged
merged 1 commit into from
Jan 14, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ public class ConsoleConfig {
*/
@PostConstruct
public void init() {
methodsCache.initClassMethod("com.alibaba.nacos.core.controller");
methodsCache.initClassMethod("com.alibaba.nacos.naming.controllers");
methodsCache.initClassMethod("com.alibaba.nacos.console.controller");
methodsCache.initClassMethod("com.alibaba.nacos.config.server.controller");
methodsCache.initClassMethod("com.alibaba.nacos.console.controller");
}

@Bean
Expand Down
7 changes: 7 additions & 0 deletions console/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ nacos.core.auth.default.token.secret.key=SecretKey012345678901234567890123456789
### Turn on/off caching of auth information. By turning on this switch, the update of auth information would have a 15 seconds delay.
nacos.core.auth.caching.enabled=true

### Since 1.4.1, Turn on/off white auth for user-agent: nacos-server, only for upgrade from old version.
nacos.core.auth.enable.userAgentAuthWhite=false

### Since 1.4.1, worked when nacos.core.auth.enabled=true and nacos.core.auth.enable.userAgentAuthWhite=false.
### The two properties is the white list for auth and used by identity the request from other server.
nacos.core.auth.server.identity.key=serverIdentity
nacos.core.auth.server.identity.value=security

#*************** Istio Related Configurations ***************#
### If turn on the MCP server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
Method method = methodsCache.getMethod(req);

if (method == null) {
chain.doFilter(request, response);
// For #4701, Only support register API.
resp.sendError(HttpServletResponse.SC_NOT_FOUND,
"Not found mehtod for path " + req.getMethod() + " " + req.getRequestURI());
return;
}

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

package com.alibaba.nacos.core.code;

import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.exception.runtime.NacosRuntimeException;
import com.alibaba.nacos.common.utils.CollectionUtils;
import com.alibaba.nacos.core.auth.RequestMappingInfo;
import com.alibaba.nacos.core.auth.RequestMappingInfo.RequestMappingInfoComparator;
Expand Down Expand Up @@ -65,9 +67,6 @@ public class ControllerMethodsCache {

public Method getMethod(HttpServletRequest request) {
String path = getPath(request);
if (path == null) {
return null;
}
String httpMethod = request.getMethod();
String urlKey = httpMethod + REQUEST_PATH_SEPARATOR + path.replaceFirst(EnvUtil.getContextPath(), "");
List<RequestMappingInfo> requestMappingInfos = urlLookup.get(urlKey);
Expand All @@ -94,13 +93,12 @@ public Method getMethod(HttpServletRequest request) {
}

private String getPath(HttpServletRequest request) {
String path = null;
try {
path = new URI(request.getRequestURI()).getPath();
return new URI(request.getRequestURI()).getPath();
} catch (URISyntaxException e) {
LOGGER.error("parse request to path error", e);
throw new NacosRuntimeException(NacosException.NOT_FOUND, "Invalid URI");
}
return path;
}

private List<RequestMappingInfo> findMatchedInfo(List<RequestMappingInfo> requestMappingInfos,
Expand Down Expand Up @@ -219,6 +217,9 @@ private void addUrlAndMethodRelation(String urlKey, String[] requestParam, Metho
if (requestMappingInfos == null) {
urlLookup.putIfAbsent(urlKey, new ArrayList<>());
requestMappingInfos = urlLookup.get(urlKey);
// For issue #4701.
String urlKeyBackup = urlKey + "/";
urlLookup.putIfAbsent(urlKeyBackup, requestMappingInfos);
}
requestMappingInfos.add(requestMappingInfo);
methods.put(requestMappingInfo, method);
Expand Down