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

Allow Kolibri to run without a CSP of unsafe-inline #12809

Closed
rtibbles opened this issue Nov 8, 2024 · 0 comments · Fixed by #12851
Closed

Allow Kolibri to run without a CSP of unsafe-inline #12809

rtibbles opened this issue Nov 8, 2024 · 0 comments · Fixed by #12851
Assignees

Comments

@rtibbles
Copy link
Member

rtibbles commented Nov 8, 2024

Observed behavior

Currently Kolibri requires the unsafe-inline CSP in order to operate, because of injection of:

  • Frontend messages wrapped with inline calls to the core API to register the messages
  • Plugin data for the frontend, wrapped in JSON.parse calls and assigning to a global object
  • Registration of async loaded modules, such as content renderers
  • Django JS Reverse URLs object that exposes functions for every backend URL

This can be handled by:

Plugin data:

  • Updating plugin data injection to put its JSON data into a <template> tag as the text body, with a data-plugin attribute set to the identifier of the plugin.
  • The frontend kolibri-plugin-data (formerly known as plugin_data) will be updated to read data from this template tag and call JSON.parse on it.

URLs:

  • Injecting Django JS Reverse JSON data into the default frontend plugin data.
  • Updating the kolibri/urls module to read its JSON data from kolibri-plugin-data, add additional frontend code to handle the URL function generation.

Messages:

  • Inject frontend message JSON into <template> tags with a data-i18n attribute set to the identifier of the plugin.
  • Create a new Django templatetag that renders all these i18n <template> tags and use this in the <head> of base.html so that these are all injected prior to i18n initialization.
  • When i18n initializes, we also register all frontend messages found in these template tags.

Content renderers:

  • Inject content renderer URLs into <template> tags with a data-viewer attribute set to the identifer of the plugin.
  • Update usage of the content Django templatetag so it is injected before the default frontend is loaded
  • When the plugin mediator is initialized, pre-register all content renderers injected in these kinds of templates.
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.

1 participant