-
Notifications
You must be signed in to change notification settings - Fork 604
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20260 from arturdzm/openapi-ui-sec-headers
Add security headers filter to OpenAPI UI
- Loading branch information
Showing
14 changed files
with
283 additions
and
6 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
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
50 changes: 50 additions & 0 deletions
50
...roprofile.openapi/src/com/ibm/ws/microprofile/openapi/servlet/filter/OpenAPIUIFilter.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,50 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 IBM Corporation and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* IBM Corporation - initial API and implementation | ||
*******************************************************************************/ | ||
/** | ||
* @version 1.0 | ||
*/ | ||
package com.ibm.ws.microprofile.openapi.servlet.filter; | ||
|
||
import javax.servlet.Filter; | ||
import javax.servlet.FilterConfig; | ||
import javax.servlet.FilterChain; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.ServletRequest; | ||
import javax.servlet.ServletResponse; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
|
||
public class OpenAPIUIFilter implements Filter { | ||
/** | ||
* Filters out specific requests and takes the appropriate action for each | ||
* | ||
* @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain) | ||
*/ | ||
@Override | ||
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException { | ||
|
||
if (resp instanceof HttpServletResponse) { | ||
HttpServletResponse httpServletResp = (HttpServletResponse) resp; | ||
httpServletResp.setHeader("X-Frame-Options", "DENY"); | ||
httpServletResp.setHeader("X-Content-Type-Options", "nosniff"); | ||
chain.doFilter(req, resp); | ||
} else { | ||
chain.doFilter(req, resp); | ||
} | ||
} | ||
|
||
@Override | ||
public void destroy() {} | ||
|
||
@Override | ||
public void init(FilterConfig arg0) throws ServletException {} | ||
} |
18 changes: 18 additions & 0 deletions
18
...microprofile.openapi/src/com/ibm/ws/microprofile/openapi/servlet/filter/package-info.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,18 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 IBM Corporation and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* IBM Corporation - initial API and implementation | ||
*******************************************************************************/ | ||
/** | ||
* @version 1.0 | ||
*/ | ||
@org.osgi.annotation.versioning.Version("1.0") | ||
@TraceOptions(traceGroup = "MPOPENAPI", messageBundle = "io.openliberty.microprofile.openapi.internal.resources.OpenAPI") | ||
package com.ibm.ws.microprofile.openapi.servlet.filter; | ||
|
||
import com.ibm.websphere.ras.annotation.TraceOptions; |
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
49 changes: 49 additions & 0 deletions
49
dev/com.ibm.ws.openapi.ui.private/src/com/ibm/ws/openapi/filter/OpenAPIFilter.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,49 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 IBM Corporation and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* IBM Corporation - initial API and implementation | ||
*******************************************************************************/ | ||
/** | ||
* @version 1.0 | ||
*/ | ||
package com.ibm.ws.openapi.filter; | ||
|
||
import javax.servlet.Filter; | ||
import javax.servlet.FilterConfig; | ||
import javax.servlet.FilterChain; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.ServletRequest; | ||
import javax.servlet.ServletResponse; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
|
||
public class OpenAPIFilter implements Filter { | ||
/** | ||
* Filters out specific requests and takes the appropriate action for each | ||
* | ||
* @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain) | ||
*/ | ||
@Override | ||
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException { | ||
if (resp instanceof HttpServletResponse) { | ||
HttpServletResponse httpServletResp = (HttpServletResponse) resp; | ||
httpServletResp.setHeader("X-Frame-Options", "DENY"); | ||
httpServletResp.setHeader("X-Content-Type-Options", "nosniff"); | ||
chain.doFilter(req, resp); | ||
} else { | ||
chain.doFilter(req, resp); | ||
} | ||
} | ||
|
||
@Override | ||
public void destroy() {} | ||
|
||
@Override | ||
public void init(FilterConfig arg0) throws ServletException {} | ||
} |
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
49 changes: 49 additions & 0 deletions
49
dev/com.ibm.ws.openapi.ui/src/com/ibm/ws/openapi/filter/OpenAPIFilter.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,49 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 IBM Corporation and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* IBM Corporation - initial API and implementation | ||
*******************************************************************************/ | ||
/** | ||
* @version 1.0 | ||
*/ | ||
package com.ibm.ws.openapi.filter; | ||
|
||
import javax.servlet.Filter; | ||
import javax.servlet.FilterConfig; | ||
import javax.servlet.FilterChain; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.ServletRequest; | ||
import javax.servlet.ServletResponse; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
|
||
public class OpenAPIFilter implements Filter { | ||
/** | ||
* Filters out specific requests and takes the appropriate action for each | ||
* | ||
* @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain) | ||
*/ | ||
@Override | ||
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException { | ||
if (resp instanceof HttpServletResponse) { | ||
HttpServletResponse httpServletResp = (HttpServletResponse) resp; | ||
httpServletResp.setHeader("X-Frame-Options", "DENY"); | ||
httpServletResp.setHeader("X-Content-Type-Options", "nosniff"); | ||
chain.doFilter(req, resp); | ||
} else { | ||
chain.doFilter(req, resp); | ||
} | ||
} | ||
|
||
@Override | ||
public void destroy() {} | ||
|
||
@Override | ||
public void init(FilterConfig arg0) throws ServletException {} | ||
} |
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
50 changes: 50 additions & 0 deletions
50
...napi.2.0.internal/src/com/ibm/ws/microprofile/openapi/servlet/filter/OpenAPIUIFilter.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,50 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 IBM Corporation and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* IBM Corporation - initial API and implementation | ||
*******************************************************************************/ | ||
/** | ||
* @version 1.0 | ||
*/ | ||
package com.ibm.ws.microprofile.openapi.servlet.filter; | ||
|
||
import javax.servlet.Filter; | ||
import javax.servlet.FilterConfig; | ||
import javax.servlet.FilterChain; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.ServletRequest; | ||
import javax.servlet.ServletResponse; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
|
||
public class OpenAPIUIFilter implements Filter { | ||
/** | ||
* Filters out specific requests and takes the appropriate action for each | ||
* | ||
* @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain) | ||
*/ | ||
@Override | ||
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException { | ||
|
||
if (resp instanceof HttpServletResponse) { | ||
HttpServletResponse httpServletResp = (HttpServletResponse) resp; | ||
httpServletResp.setHeader("X-Frame-Options", "DENY"); | ||
httpServletResp.setHeader("X-Content-Type-Options", "nosniff"); | ||
chain.doFilter(req, resp); | ||
} else { | ||
chain.doFilter(req, resp); | ||
} | ||
} | ||
|
||
@Override | ||
public void destroy() {} | ||
|
||
@Override | ||
public void init(FilterConfig arg0) throws ServletException {} | ||
} |
19 changes: 19 additions & 0 deletions
19
...openapi.2.0.internal/src/com/ibm/ws/microprofile/openapi/servlet/filter/package-info.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,19 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 IBM Corporation and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* IBM Corporation - initial API and implementation | ||
*******************************************************************************/ | ||
@Version(Constants.OSGI_VERSION) | ||
@TraceOptions(traceGroup = Constants.TRACE_GROUP, messageBundle = Constants.TRACE_OPENAPI) | ||
package com.ibm.ws.microprofile.openapi.servlet.filter; | ||
|
||
import org.osgi.annotation.versioning.Version; | ||
|
||
import com.ibm.websphere.ras.annotation.TraceOptions; | ||
|
||
import io.openliberty.microprofile.openapi20.internal.utils.Constants; |