-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NO-ISSUE] Implement Origin check for terminal interpreter WebSocket …
…connections ### What is this PR for? This PR adds an Origin check to ensure that WebSocket connections are initiated from trusted sources only. By validating the `Origin` header in the initial WebSocket handshake, we can prevent unauthorized or malicious websites from establishing WebSocket connections with our server. Changes: - Added server-side validation of the `Origin` header during WebSocket connection requests. Other security enhancements may be needed and can be handled in future iterations. ### What type of PR is it? Improvement ### Todos * [ ] - Task ### How should this be tested? * Strongly recommended: add automated unit tests for any new or changed behavior * Outline any manual steps to test the PR here. ### Screenshots (if appropriate) ### Questions: * Does the license files need to update? No * Is there breaking changes for older versions? No * Does this needs documentation? No Closes #4823 from tbonelee/websocket. Signed-off-by: Jongyoul Lee <[email protected]> (cherry picked from commit 3575a3c) Signed-off-by: Jongyoul Lee <[email protected]>
- Loading branch information
Showing
5 changed files
with
228 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...c/main/java/org/apache/zeppelin/shell/terminal/websocket/TerminalSessionConfigurator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.zeppelin.shell.terminal.websocket; | ||
|
||
import javax.websocket.server.ServerEndpointConfig.Configurator; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class TerminalSessionConfigurator extends Configurator { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(TerminalSessionConfigurator.class); | ||
private String allowedOrigin; | ||
|
||
public TerminalSessionConfigurator(String allowedOrigin) { | ||
this.allowedOrigin = allowedOrigin; | ||
} | ||
|
||
@Override | ||
public boolean checkOrigin(String originHeaderValue) { | ||
boolean allowed = allowedOrigin.equals(originHeaderValue); | ||
LOGGER.info("Checking origin for TerminalSessionConfigurator: " + | ||
originHeaderValue + " allowed: " + allowed); | ||
return allowed; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.