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

Why my src attribute ignored? #485

Open
10cheon00 opened this issue Oct 7, 2022 · 0 comments
Open

Why my src attribute ignored? #485

10cheon00 opened this issue Oct 7, 2022 · 0 comments

Comments

@10cheon00
Copy link

10cheon00 commented Oct 7, 2022

I installed django-summernote and followed all setup, however when I upload image and post it with text, img tag doesn't have src attribute.

In db table, result is appeared like this,

 id |                 text
----+-------------------------------
  1 | <p>This is image.</p><p><br></p><img style="">

I try to find solution. The reason was discovered in SummernoteTextFormField.
When field saves data, field will run bleach.clean(). bleach will remove html tags, attributes, other things by settings what specified in settings.py
So I open settings.py and found that there is no src attribute.
After I wrote src in ATTRIBUTES, uploading image is successfully works.

 id |                                                               text                                                                
----+-----------------------------------------------------------------------------------------------------------------------------------
  1 |<p>This is image.</p><p><br></p><img src="http://127.0.0.1:8000/media/django-summernote/2022-10-07/b11642da-88a4-41c1-b509-b94a49371ad1.png" style="">

I think this isn't good solution to avoid XSS. There must be reason why src attributes doesn't exist in settings.ATTRIBUTES.

Before solve this problem, I got unexpected keyword argument error, #477. So I installed bleach-4.1.0. Is this cause above error?

update:
I solved this problem with below codes in project settings.py.

from django_summernote.settings import ATTRIBUTES


ATTRIBUTES["*"] += ["src",]
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

No branches or pull requests

1 participant