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

wysiwyg alignment changes access_token #10145

Closed
3 tasks done
lambdajack opened this issue Nov 29, 2021 · 6 comments · Fixed by #10234
Closed
3 tasks done

wysiwyg alignment changes access_token #10145

lambdajack opened this issue Nov 29, 2021 · 6 comments · Fixed by #10234
Assignees
Labels
Milestone

Comments

@lambdajack
Copy link

Preflight Checklist

Describe the Bug

When using the 'align left' 'align right' 'align center' 'align justify' formatting options on an image inside a wysiwyg field - setting anything other than what it was originally imported into the field as causes the default access_token (which has been set in the interface) to become an automatically generated token.

1. Importing an image / publishing etc:
1

2. Leaving the import alone - notice the access_token is what I've set it to be in the interface "web-app-public-token":
2

3. Centering the image and then publishing etc:
3

4. Notice how the centered image uses a completely random token.
4

5. If you move the image back to the alignment option it had when it was first imported, it starts using the token set in the interface again.

To Reproduce

  1. Create a brand new database and directus instance.
  2. Create a collection with a wysiwyg field.
  3. Take steps listed above - set the innerHtml somewhere in a client or use postman etc to see it.

Errors Shown

After some time (15 mins?) 'unauthorised' when trying to render the wysiwyg content if it does not have the access_token set to what has been set in the interface.

What version of Directus are you using?

Latest / 9.1.2 / Docker (9.0.1?)

What version of Node.js are you using?

LTS & latest

What database are you using?

Postgres & MySQL

What browser are you using?

Chrome, Firefox, Brave (completely stock - incognito - no extensions etc)

What operating system are you using?

Ubuntu

How are you deploying Directus?

Locally & Docker (not at the same time)

@lambdajack
Copy link
Author

Any help on this guys is much appreciated - a client requires the ability to format their images left / right / center etc in various places. Directus is great and have had good feedback from the client.

Let me know if there's anything else I can help with.

I think this is related to #9831

@rijkvanzanten
Copy link
Member

@jacksbrand Is that access token saved to the database? It's correct behavior that the preview within the app uses the temporary token

@lambdajack
Copy link
Author

@rijkvanzanten - thanks for getting back to me on this - yeah the database has saved the img element with the access token set to the temp string.

5

@lambdajack
Copy link
Author

@rijkvanzanten - just confirmed - when I import the image it saves with the token I've set in the interface:
6

But when I center it:
7

Strangely enough - when I set it back to where it was originally (justify it seems in this case) the original and correct token is written back to the db:
8

@rijkvanzanten rijkvanzanten self-assigned this Dec 2, 2021
@rijkvanzanten rijkvanzanten added this to the v9.1.3 milestone Dec 2, 2021
@rijkvanzanten
Copy link
Member

The regex used to replace the temporary token fails on img tags that have an inline style attribute, which is the case when using alignment in tinymce:

const regex = new RegExp(
`(<[^=]+=")(${escapeRegExp(
url
)}assets/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}(?:\\?[^#"]*)?(?:#[^"]*)?)("[^>]*>)`,
'gi'
);

With style attribute:

CleanShot 2021-12-02 at 14 11 28@2x

Without style attribute:

CleanShot 2021-12-02 at 14 11 51@2x

Most definitely within the first capture group here: (<[^=]+="). Time to brush up on my RegEx syntax ᕕ( ᐛ )ᕗ

@lambdajack
Copy link
Author

lambdajack commented Dec 2, 2021

@rijkvanzanten - legend nice spot - thank you. #RegexIsFun

rijkvanzanten added a commit that referenced this issue Dec 2, 2021
* Fix token manipulation on alignment change in images

Fixes #10145

* Update app/src/interfaces/input-rich-text-html/input-rich-text-html.vue

Co-authored-by: Nicola Krumschmidt <nicola.krumschmidt@freenet.de>

Co-authored-by: Nicola Krumschmidt <nicola.krumschmidt@freenet.de>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants