-
Notifications
You must be signed in to change notification settings - Fork 623
Add security headers filter to OpenAPI UI #20260
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
Merged
arturdzm
merged 1 commit into
OpenLiberty:integration
from
arturdzm:openapi-ui-sec-headers
Mar 1, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.