Skip to content
This repository was archived by the owner on Dec 19, 2023. It is now read-only.

Commit 8179a82

Browse files
committed
fix: check allowed origins for websocket subscription
fixes #941
1 parent a701d4a commit 8179a82

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
1717
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1818
#
19-
version=15.0.1-SNAPSHOT
19+
version=15.1.0-SNAPSHOT
2020
### Project Metadata
2121
group=com.graphql-java-kickstart
2222
PROJECT_NAME=graphql-spring-boot
@@ -32,7 +32,7 @@ TARGET_COMPATIBILITY=17
3232
LIB_GRAPHQL_JAVA_VER=20.1
3333
LIB_EXTENDED_SCALARS_VER=19.1
3434
LIB_SPRING_BOOT_VER=3.0.5
35-
LIB_GRAPHQL_SERVLET_VER=15.0.0
35+
LIB_GRAPHQL_SERVLET_VER=15.1.0-SNAPSHOT
3636
LIB_GRAPHQL_JAVA_TOOLS_VER=13.0.3
3737
LIB_GRAPHQL_ANNOTATIONS_VER=9.1
3838
LIB_REFLECTIONS_VER=0.10.2

graphql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/autoconfigure/web/servlet/GraphQLSubscriptionWebsocketProperties.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package graphql.kickstart.autoconfigure.web.servlet;
22

3+
import static java.util.Collections.emptyList;
4+
5+
import java.util.List;
36
import lombok.Data;
47
import org.springframework.boot.context.properties.ConfigurationProperties;
58

@@ -8,4 +11,5 @@
811
class GraphQLSubscriptionWebsocketProperties {
912

1013
private String path = "/subscriptions";
14+
private List<String> allowedOrigins = emptyList();
1115
}

graphql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/autoconfigure/web/servlet/GraphQLWebsocketAutoConfiguration.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
@ConditionalOnWebApplication(type = Type.SERVLET)
3636
@ConditionalOnClass({DispatcherServlet.class, ServerEndpointRegistration.class})
3737
@Conditional(OnSchemaOrSchemaProviderBean.class)
38-
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
3938
@ConditionalOnProperty(
4039
value = "graphql.servlet.websocket.enabled",
4140
havingValue = "true",
@@ -63,7 +62,11 @@ public GraphQLWebsocketServlet graphQLWebsocketServlet(
6362
}
6463
keepAliveListener().ifPresent(listeners::add);
6564
return new GraphQLWebsocketServlet(
66-
graphQLInvoker, invocationInputFactory, graphQLObjectMapper, listeners);
65+
graphQLInvoker,
66+
invocationInputFactory,
67+
graphQLObjectMapper,
68+
listeners,
69+
websocketProperties.getAllowedOrigins());
6770
}
6871

6972
private Optional<SubscriptionConnectionListener> keepAliveListener() {

graphql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/autoconfigure/web/servlet/GraphQLWsServerEndpointRegistration.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ public GraphQLWsServerEndpointRegistration(String path, GraphQLWebsocketServlet
1818
this.servlet = servlet;
1919
}
2020

21+
@Override
22+
public boolean checkOrigin(String originHeaderValue) {
23+
return servlet.checkOrigin(originHeaderValue);
24+
}
25+
2126
@Override
2227
public void modifyHandshake(
2328
ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {

0 commit comments

Comments
 (0)