dousongqiang2585 2017-11-24 07:11
浏览 87
已采纳

Laravel如何保护自己免受html注入?

Hello I'm new to laravel and I tried to add HTML to a <h6> field like below image .1

and it appears in the page source like this

source

My question is why it doesn't render in the browser ? What has Laravel done here ?

My Blade code :

   @extends('layouts')

<div class="row">
    <div class='col-md-6 offset-md-3'   >
    @section('content')
    <h1>{{$card->title}}</h1>

    {{$card->created_at}}


    <br>
    <ul class="list-group">
    @foreach($card->notes as $note)

    <li class="list-group-item">
        <h6>{{$note->body}}</h6> <button class="btn btn-info btn-sm" onclick="togglediv('divform{{$note->id}}')" >Edit</button>

        <div class="col-md-6 offset-md-3" id="divform{{$note->id}}" style="display: none;">
    <hr>
<form action="/notes/{{$note->id}}/edit" method="POST">
  {{ csrf_field() }}
  {{ method_field('PATCH') }}
  <div class="form-group">
    <label for="exampleInputPassword1"><h6>Edit the note</h6></label>
    <input type="text-area" name="body" class="form-control" id="body" placeholder="{{$note->body}}">
  </div>


  <button type="submit" class="btn btn-success btn-sm">Done</button>
</form>
</div>


    </li>


    @endforeach


<script type="text/javascript">function togglediv(id) {
    var div = document.getElementById(id);
    div.style.display = div.style.display == "none" ? "block" : "none";
}</script>






    </ul>
</div>
</div>
@endsection

@section('footer')

<br>
<div class="col-md-6 offset-md-3">
    <hr>
<form action="/cards/{{$card->id}}/notes" method="POST">
  {{ csrf_field() }}
  <div class="form-group">
    <label for="exampleInputPassword1"><h3>Add a new note</h3></label>
    <input type="text-area" name="body" class="form-control" id="body" placeholder="Body">
  </div>


  <button type="submit" class="btn btn-primary">Add Note</button>
</form>
</div>
@endsection
  • 写回答

1条回答 默认 最新

  • dps43633 2017-11-24 07:16
    关注

    Your html is escaped ,if you don't want that use the following syntax to output the html

      {!!$note->body!!}
    

    more info

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?