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

CSP headers break schema #68

Assignees
Labels
bug Something isn't working owner: amsterdam

Comments

@Coperh
Copy link
Contributor

Coperh commented Sep 10, 2024

Product versie / Product version

0.8.0

Omschrijf het probleem / Describe the bug

CSP headers prevent schema from loading external scripts

Reported here, maykinmedia/open-klant#242/

Confirmed in OpenZaak 1.14

Stappen om te reproduceren / Steps to reproduce

  1. Go to open-klant /contactgegevens/api/v1/schema/

Verwacht gedrag / Expected behavior

Page should loader correctly

@Coperh Coperh added the bug Something isn't working label Sep 10, 2024
@Coperh Coperh self-assigned this Sep 10, 2024
@Coperh
Copy link
Contributor Author

Coperh commented Sep 10, 2024

Three potential fixes:

Exclude the schema URLs. This is the quick way but does need to include all component URLs since they are "prefixes"

# for open klant
CSP_EXCLUDE_URL_PREFIXES += (
    "/contactgegevens/api/v1/schema/",
    "/klantinteracties/api/v1/schema/"
)

Allow sources for SCP

# used for DRF Spectacular
CSP_FONT_SRC = ("'self'", "fonts.gstatic.com")
CSP_WORKER_SRC = ("'self'", "blob:")

CSP_DEFAULT_SRC += ["'unsafe-inline'"] # Open zaak might want this anyway
CSP_IMG_SRC += ["cdn.redoc.ly", "data:"]
CSP_SCRIPT_SRC += ["cdn.jsdelivr.net"]
CSP_STYLE_SRC += ["fonts.googleapis.com"]

Also might be extra per project source e.g. OZ wants the vng github

The more proper way might be to install drf-spectacular-sidecar https://drf-spectacular.readthedocs.io/en/latest/faq.html#my-swagger-ui-and-or-redoc-page-is-blank

@Coperh Coperh changed the title CSP headers break scheme CSP headers break schema Sep 10, 2024
@Coperh
Copy link
Contributor Author

Coperh commented Sep 10, 2024

@Coperh Coperh added the triage Triage means the team has not yet refined this issue. label Sep 10, 2024
@alextreme
Copy link
Member

Looking at drf-spectacular-sidecar, this seems to me to be the proper route. If you don't need externally hosted scripts served via a CDN then setting CSP headers site-wide becomes a lot easier. This combined with the move from yasg to spectacular for OZ means that this should work for all components.

As an aside, Sergei pointed out that /admin was also excluded in CSP_EXCLUDE_URL_PREFIXES. This shouldn't be the case (the whole reason why we added CSP to OAf was for /admin.

@joeribekker
Copy link
Member

Refinement:,Will be fixed in all components.

Coperh added a commit that referenced this issue Sep 20, 2024
Coperh added a commit that referenced this issue Sep 20, 2024
Coperh added a commit that referenced this issue Sep 25, 2024
Coperh added a commit to open-zaak/open-zaak that referenced this issue Sep 25, 2024
Coperh added a commit that referenced this issue Sep 25, 2024
…cular

🐛[#68] add CSP headers for DRF spectacular schema
Coperh added a commit to maykinmedia/open-klant that referenced this issue Sep 27, 2024
Coperh added a commit to maykinmedia/objecttypes-api that referenced this issue Sep 27, 2024
Coperh added a commit to maykinmedia/open-klant that referenced this issue Sep 27, 2024
Coperh added a commit to maykinmedia/referentielijsten that referenced this issue Sep 27, 2024
Coperh added a commit to maykinmedia/objects-api that referenced this issue Sep 27, 2024
Coperh added a commit to open-zaak/open-zaak that referenced this issue Sep 27, 2024
@github-project-automation github-project-automation bot moved this from Implemented to Done in Data en API fundament Sep 27, 2024
@Coperh Coperh reopened this Sep 27, 2024
@github-project-automation github-project-automation bot moved this from Done to In Progress in Data en API fundament Sep 27, 2024
Coperh added a commit to maykinmedia/objects-api that referenced this issue Oct 1, 2024
@github-project-automation github-project-automation bot moved this from Implemented to Done in Data en API fundament Oct 1, 2024
@Coperh Coperh reopened this Oct 1, 2024
@github-project-automation github-project-automation bot moved this from Done to In Progress in Data en API fundament Oct 1, 2024
@annashamray annashamray mentioned this issue Oct 1, 2024
6 tasks
Coperh added a commit to maykinmedia/open-klant that referenced this issue Oct 1, 2024
Coperh added a commit to open-zaak/open-notificaties that referenced this issue Oct 1, 2024
@github-project-automation github-project-automation bot moved this from Implemented to Done in Data en API fundament Oct 1, 2024
Coperh added a commit to maykinmedia/referentielijsten that referenced this issue Oct 1, 2024
@Coperh Coperh reopened this Oct 1, 2024
@github-project-automation github-project-automation bot moved this from Done to In Progress in Data en API fundament Oct 1, 2024
annashamray pushed a commit to maykinmedia/objects-api that referenced this issue Oct 1, 2024
annashamray pushed a commit to maykinmedia/objects-api that referenced this issue Oct 1, 2024
Coperh added a commit to maykinmedia/open-klant that referenced this issue Oct 3, 2024
@github-project-automation github-project-automation bot moved this from Implemented to Done in Data en API fundament Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment