1

Currently I use database to store all data(description, name, etc) that user key in (user can self generate content)

Yet, my site is "hijacked" by someone who knows html.. Let's say in description, they enter

<a href="http://hijack.comhijack">abc</a>

to put link:

Link

The code in my Larvel view is {{$site->description}}

How can I restrict them to show this like plain text? enter image description here

Tt will mess-up my page, and when I put my description in meta property, it will mess up to..

any solution for this?

7
  • 2
    You have to HTML escape the data. If you're using blade, use triple curly braces: {{{ $site->description }}} Commented Jun 11, 2014 at 1:22
  • Are you are talking about escping HTML from user input ? Commented Jun 11, 2014 at 1:25
  • @WesleyMurch thanks, how bout i want break line to remain(not escaping) Commented Jun 11, 2014 at 1:36
  • @WereWolf-TheAlpha ya. escaping, i doesn't know how to say it. sorry. Commented Jun 11, 2014 at 1:37
  • If you are saving the user submitted data in to database then Validation of that field will protect you and inputs are sanitized (AFAIK). Commented Jun 11, 2014 at 1:39

3 Answers 3

4

In Laravel 5, double curly braces now automatically escape all the HTML from your string.

More info: Blade templating


If you're still using Laravel 4, use triple curly braces instead of double, which will escape all the HTML from your string:

{{{ $site->description }}}
Sign up to request clarification or add additional context in comments.

Comments

1

No need to use any blade syntax for this just use normal PHP:

<?php echo $site->description; ?>

I am new to Laravel and was looking for a blade solution but this worked for me and seemed to be the simplest solution

Comments

-2

you can try :

{!! $site->description !!}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.