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 Violation in Django REST Framework #3020

Closed
mlissner opened this issue Aug 14, 2023 · 6 comments · Fixed by #3038
Closed

CSP Violation in Django REST Framework #3020

mlissner opened this issue Aug 14, 2023 · 6 comments · Fixed by #3038
Assignees

Comments

@mlissner
Copy link
Member

I found one!

If you load this page:

https://www.courtlistener.com/api/rest/v3/

You'll see that there's a CSP violation:

10:31:38.723 Content-Security-Policy: The page’s settings blocked the loading of a resource at inline (“script-src”). v3:284:14

Drat. We'll want to fix this. I've noticed on the page, for example, that the OPTIONS button no longer works.

@cweider cweider self-assigned this Aug 14, 2023
@cweider
Copy link
Collaborator

cweider commented Aug 14, 2023

Good news: django-rest-framework has the fixes already. Bad news: the latest release is a year old and these fixes didn’t make it in. Probable solution is a switch of the dependency from the PyPI package to a (pinned) git ref.

The key changes are: encode/django-rest-framework#7016, encode/django-rest-framework#8783, and encode/django-rest-framework#8784.

@mlissner
Copy link
Member Author

Think it's worth asking for a release? I kind of hate pinned versions.

@cweider
Copy link
Collaborator

cweider commented Aug 17, 2023

Yup, exactly. Lurking in their discussion group, it doesn’t look like a release will be forthcoming. From a recent discussion in Django REST framework:

Hello group!
Does anybody know when the new version of DRF which would support Django 4.2 is expected?

Hi, i think DRF now support D4.2 https://github.com/encode/django-rest-framework#requirements

Master supports it, but the latest tagged version is 3.14 and it doesn't. So my question is when we can expect a new tag (3.15 maybe?)

Hi, if you need install the master/main branch you try this
pip install https://github.com/encode/django-rest-framework/archive/refs/heads/master.zip
if you do not want to wait for the tag 3.15

@mlissner
Copy link
Member Author

Wait, so their readme says it's supported, but the only way to get support is to use master??

@cweider
Copy link
Collaborator

cweider commented Aug 17, 2023

Evidently. I mean the readme is drawn from master so it is consistent. 10 months and counting from last release is a problem though. In other news, the built-in schema generation has been deprecated for about as long, but, being unreleased, the deprecation notice has yet to be published!

@mlissner
Copy link
Member Author

OK, well, let's do it, I guess.

cweider added a commit to cweider/courtlistener that referenced this issue Aug 22, 2023
`django-rest-framework` has recieved several patches for
CSP compatibility, but unfortunately these are not included
in the latest release (3.14.0) and a new release cannot be
expected for a while.

As such, we must replace the semantically versioned PyPI
reference with a reference to the latest commit on the master
branch of the package's Git Repository (do not use `master`
since it could change in unexpected and incompatible ways).

Fixes: freelawproject#3020
cweider added a commit to cweider/courtlistener that referenced this issue Aug 23, 2023
`django-rest-framework` has recieved several patches for
CSP compatibility, but unfortunately these are not included
in the latest release (3.14.0) and a new release cannot be
expected for a while.

As such, we must replace the semantically versioned PyPI
reference with a reference to the latest commit on the master
branch of the package's Git Repository (do not use `master`
since it could change in unexpected and incompatible ways).

Fixes: freelawproject#3020
cweider added a commit to cweider/courtlistener that referenced this issue Aug 23, 2023
`django-rest-framework` has recieved several patches for
CSP compatibility, but unfortunately these are not included
in the latest release (3.14.0) and a new release cannot be
expected for a while.

As such, we must replace the semantically versioned PyPI
reference with a reference to the latest commit on the master
branch of the package's Git Repository (do not use `master`
since it could change in unexpected and incompatible ways).

Fixes: freelawproject#3020
cweider added a commit to cweider/courtlistener that referenced this issue Aug 23, 2023
`django-rest-framework` has recieved several patches for
CSP compatibility, but unfortunately these are not included
in the latest release (3.14.0) and a new release cannot be
expected for a while.

As such, we must replace the semantically versioned PyPI
reference with a reference to the latest commit on the master
branch of the package's Git Repository that contains the
changes that we need (do not use `master` since it could
change in unexpected and incompatible ways).

Included in this change is the `inflection` package,
unfortunate dependency added by encode/django-rest-framework#8017
and later made less obtrusive by encode/django-rest-framework#8781,
but it did not eliminate it. Any usage of the schema generator
must be done in an environment that includes this package.

Fixes: freelawproject#3020
cweider added a commit to cweider/courtlistener that referenced this issue Aug 23, 2023
`django-rest-framework` has recieved several patches for
CSP compatibility, but unfortunately these are not included
in the latest release (3.14.0) and a new release cannot be
expected for a while.

As such, we must replace the semantically versioned PyPI
reference with a reference to the latest commit on the master
branch of the package's Git Repository that contains the
changes that we need (do not use `master` since it could
change in unexpected and incompatible ways).

Included in this change is the use of `inflection` for the
OpenAPI spec's `operationIds`, an unfortunate dependency
added by encode/django-rest-framework#8017 and later made
less obtrusive by encode/django-rest-framework#8781. Any
usage of the schema generator must be done in an environment
that includes this package. Additionally, this new approach
makes the generated `operationId` that was `listPersons` into
`listPeople`. Thankfully, this is immaterial.

Fixes: freelawproject#3020
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 a pull request may close this issue.

2 participants