Reputation: 657
I've noticed when I use ckeditor and I post <script>alert('hi')</script>
as my content then it's saved as the following in the database and when I visit the page with with the blog post I don't get an alert.
<p><script></p>
<p>alert('hi');</p>
<p></script></p>
On the contrary when I post the same content without the plugin by just using textarea tag
then it's saved in the database as shown below and when I visit the page with the post I get an alert.
<script>
alert('hi');
</script>
Does this mean data provided by user using ckeditor is safe from XSS attacks?
To display the data I have to do it this way: {!! $post->body !!}
and I know laravel doesn't protect from XSS when the data is not escaped so I'm concerned about XSS in this case.
Upvotes: 1
Views: 1131
Reputation: 46
If you treat input from CKEditor as safe, then; No. Data provided by user using ckeditor is NOT safe from XSS attacks.
All depends on:
So as an example, using the Source button (if activated) a user can input:
<script>alert(XSSvulnerability)</script>
...and the script will run once outputted if you think "data provided by user using ckeditor is safe from XSS attacks".
Considering you are using Laravel, we can also use this method to run some PHP script as well:
$a = true;
if($a){
$this->db->query('DELETE * FROM posts');
$this->query->execute();
}
Even if you were to use htmlspecialchars($post->body)
, (and this would clearly break your HTML) an HTML attribute can be used to htmlspecialchars_decode($yourVariable)
and run the script.
As stated in CKEditor Best Practices guide here:
contentPreview
eventConsider the following:
<textarea>
is just a blank canvas for any ill-intended userUpvotes: 2