Skip to content

APIv1: disable by default - #3608

Merged
valentijnscholten merged 5 commits into
DefectDojo:devfrom
valentijnscholten:apiv1-disable
Jan 14, 2021
Merged

valentijnscholten merged 5 commits into
DefectDojo:devfrom
valentijnscholten:apiv1-disable

Conversation

@valentijnscholten

@valentijnscholten valentijnscholten commented Jan 10, 2021 •

Copy link
Copy Markdown
Member

Now that APIv1 is deprecated, it might be best to disable it by default. It can be enabled by setting DD_LEGACY_API_V1_ENABLE environment variable to True. Or by setting LEGACY_API_V1_ENABLE to True in a local_settings.py file.

By default all apiv1 request return a 400 message with an error:

BadRequest at /api/v1/findings/1234/
{"error": "{'code': 666, 'message': \"APIv1 is deprecated and may contain vulnerabilities. It's disabled by default. At your own risk it can be enabled by setting DD_LEGACY_API_V1_ENABLE to True, or by setting LEGACY_API_V1_ENABLE to True in  settings(.dist).py or local_settings.py\"}"}

When APIv1 is enabled again, it will work, but will also return some warnings:

Response Headers
{
  ...
  "deprecation": "true",
  "warning": "666 APIv1 APIv1 is deprecated and may contain vulnerabilities. It's disabled by default. At your own or your admins risk it has been enabled.",
  ...
}

With unit test! And existing unit tests still work using a override_settings decorator.

@valentijnscholten
valentijnscholten changed the base branch from master to dev January 10, 2021 17:37
@valentijnscholten valentijnscholten changed the title Apiv1: disable by default APIv1: disable by default Jan 10, 2021
Comment thread dojo/api.py Resolved
Comment thread dojo/api.py Resolved
Comment thread dojo/settings/settings.dist.py Resolved
Comment thread dojo/api.py Resolved

@madchap madchap left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nicely done! I'd still love to see some of my comments addressed, yet this is dealing nicely with the deprecation we've had in the documentation for some time now.

@valentijnscholten

Copy link
Copy Markdown
Member Author

Please note that this was meant to be a quick sunday afternoon PR. Turns out that it's not so easy to override requests in tastypie because the framework itself is wrapping it's view method in a wrap_view wrapper. So we can't simply call super().wrap_view or super.callback() or super.view().
Every example that I found (stackoverflow FTW), is duplicating some code from the tastypie package itself.
Usually this would be a red flag. But in this case apiv1 is deprecated and will be removed in the next half year, so I'm good with it.

Same for those sanitize/escape things in there. They are used by the code from tastypie so wouldn't want to remove them and then see someone posting something on H1 :-D

@mtesauro mtesauro left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved.

@valentijnscholten
valentijnscholten merged commit b9a79d1 into DefectDojo:dev Jan 14, 2021
@madchap madchap mentioned this pull request Jan 19, 2021
9alexx3 pushed a commit to 9alexx3/django-DefectDojo that referenced this pull request Aug 12, 2026
* APIv1: Disable by default
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants