Embed Preview throws 403 forbidden - Embed now requires a csrf token

Created on 10 June 2022, about 2 years ago
Updated 23 March 2023, over 1 year ago

Problem/Motivation

When trying to preview an url Embed in CKEditor, you get a 403 - Forbidden error.

Not quite sure why this was not documented on Embed module, but when upgrading the module to cover this security vulnerability: https://www.drupal.org/sa-contrib-2022-042 β†’ Embed now requires a CSRF Token to be present for previewing embeds. As you can check on EmbedController, checkCsrf() method.

These changes were included in commit #89b249e4

Please note the embed itself is OK when looking at the node, the issue is for previewing those embeds in the editor.

Steps to reproduce

1. Click url embed button in ckeditor
2. Add a social media url, like a twitter tweet, for example
3. Click on "Embed"
4. Note how the Tweet Preview is not displaying in the ckeditor
5. Check console logs, see the POST call has a 403 Forbidden error

So the 403 - Forbidden error is coming from the Embed controller (at route /embed/preview/{filter_format}), checkCsrf() method since the required header X-Drupal-EmbedPreview-CSRF-Token is missing.

Also, if you check the response headers for that request, you will see that the X-Drupal-Ajax-Token header is missing.

Proposed resolution

URL Embed should add a X-Drupal-EmbedPreview-CSRF-Token header to the preview request, and it should also add a token to that header.

So I'm adding a CR with those changes in the editor widget for the preview and in the drupalurl ckeditor plugin.

Remaining tasks

Add tests?

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡¦πŸ‡·Argentina anairamzap Buenos Aires

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡¦Ukraine SV
  • πŸ‡³πŸ‡΄Norway gisle Norway

    SV, why are you posting a patch containing code merged seven months ago?

  • πŸ‡ΊπŸ‡¦Ukraine SV

    gisle, I still use 8.x-1.0-alpha1 version and just needed to have it posted as a static unchangeable patch

  • πŸ‡³πŸ‡΄Norway gisle Norway

    I don't think that's the right way to do this.

    I am a site moderator here, and your patch was flagged as spam and also reported as an attempt to game the credit system.

    I've cleared the spam flags against your account now, but I shall suggest you save any legacy patches you need to retain locally, instead of posting them to closed issue queues on Drupal.org.

Production build 0.69.0 2024