Skip to content

Commit 90758f5

Browse files
Make sure identity verification runs before discovery and health won't leak info (#467)
1 parent d7ff874 commit 90758f5

File tree

1 file changed

+13
-22
lines changed

1 file changed

+13
-22
lines changed

sdk-core/src/main/java/dev/restate/sdk/core/EndpointRequestHandler.java

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -105,24 +105,24 @@ public RequestProcessor processorForRequest(
105105
LoggingContextSetter loggingContextSetter,
106106
Executor coreExecutor)
107107
throws ProtocolException {
108+
if (path.endsWith(HEALTH_PATH)) {
109+
return new StaticResponseRequestProcessor(200, "text/plain", Slice.wrap("OK"));
110+
}
111+
112+
// Verify request
113+
if (endpoint.getRequestIdentityVerifier() != null) {
114+
try {
115+
endpoint.getRequestIdentityVerifier().verifyRequest(headersAccessor);
116+
} catch (Exception e) {
117+
throw ProtocolException.unauthorized(e);
118+
}
119+
}
120+
108121
// Discovery request
109122
if (path.endsWith(DISCOVER_PATH)) {
110123
return this.handleDiscoveryRequest(headersAccessor);
111124
}
112125

113-
if (path.endsWith(HEALTH_PATH)) {
114-
return new StaticResponseRequestProcessor(
115-
200,
116-
"text/plain",
117-
Slice.wrap(
118-
"Serving services ["
119-
+ this.endpoint
120-
.getServiceDefinitions()
121-
.map(ServiceDefinition::getServiceName)
122-
.collect(Collectors.joining(", "))
123-
+ "]"));
124-
}
125-
126126
// Parse request
127127
String[] pathSegments = SLASH.split(path);
128128
if (pathSegments.length < 3) {
@@ -152,15 +152,6 @@ public RequestProcessor processorForRequest(
152152
throw ProtocolException.methodNotFound(serviceName, handlerName);
153153
}
154154

155-
// Verify request
156-
if (endpoint.getRequestIdentityVerifier() != null) {
157-
try {
158-
endpoint.getRequestIdentityVerifier().verifyRequest(headersAccessor);
159-
} catch (Exception e) {
160-
throw ProtocolException.unauthorized(e);
161-
}
162-
}
163-
164155
// Parse OTEL context and generate span
165156
final io.opentelemetry.context.Context otelContext =
166157
this.endpoint

0 commit comments

Comments
 (0)