Skip to content
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

Add improved security headers to FastAPI responses #1355

Merged
merged 6 commits into from May 15, 2023

Conversation

tynandebold
Copy link
Member

@tynandebold tynandebold commented May 12, 2023

Description

Resolves #1348.

Development notes

I've added and am using the secure package to add the necessary security headers infosec requested, those headers being:

  • Strict-Transport-Security
  • X-Frame-Options

QA notes

You need to run the app locally or with Gitpod and view the main server response.

This is before the change:

Screenshot 2023-05-12 at 09 07 33

This is after:

Screenshot 2023-05-12 at 09 06 28

Checklist

  • Read the contributing guidelines
  • Opened this PR as a 'Draft Pull Request' if it is work-in-progress
  • Updated the documentation to reflect the code changes
  • Added new entries to the RELEASE.md file
  • Added tests to cover my changes

Signed-off-by: Tynan DeBold <thdebold@gmail.com>
Signed-off-by: Tynan DeBold <thdebold@gmail.com>
Signed-off-by: Tynan DeBold <thdebold@gmail.com>
…ore/add-secure-response-headers-to-fastapi-app

Signed-off-by: Tynan DeBold <thdebold@gmail.com>
Signed-off-by: Tynan DeBold <thdebold@gmail.com>
@tynandebold tynandebold removed the request for review from yetudada May 12, 2023 12:58
Copy link
Contributor

@rashidakanchwala rashidakanchwala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have enough knowledge abt security headers but the code looks fine, and I get those extra stuff in the response headers. thanks @tynandebold :)

Copy link
Contributor

@antonymilne antonymilne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also have minimal understanding of this, but looks good as far as I understand it.

Just one thing: should this also be applied to create_api_app_from_file? That is what runs if you do kedro-viz --load-file. If yes, then better to put this in _create_base_api_app instead.

Signed-off-by: Tynan DeBold <thdebold@gmail.com>
@tynandebold tynandebold merged commit a891a44 into main May 15, 2023
17 checks passed
@tynandebold tynandebold deleted the chore/add-secure-response-headers-to-fastapi-app branch May 15, 2023 11:03
@tynandebold tynandebold mentioned this pull request May 15, 2023
5 tasks
rashidakanchwala added a commit that referenced this pull request Dec 5, 2023
In response to issue #1348, which required the addition of security headers to demo.kedro.org, we implemented a solution in PR #1355. This solution involved adding security headers to the FastAPI application which results in all instances of kedro-viz, whether hosted or local, having these security headers. Having the security headers introduced a limitation where kedro-viz could not be used as an IFrame, affecting functionalities like %run_viz that embed kedro-viz in an iframe.

To address this, the current ticket introduces a conditional approach. We will add security headers only if the environment variable ADD_SECURITY_HEADER is set to true. This modification will be implemented in the Dockerfile when creating the docker image for the demo project. This image will then be uploaded to an EC2 instance and deployed using Lightsail.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add necessary security headers to demo.kedro.org
3 participants