<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ## 防護XSRF的方式:post請求之類偽造請求 * #### 每一個用戶一個cookie,所用的請求都需要驗證這個cookie,如果沒有這個cookie,則被認為跨站請求偽造 * #### 挾制用戶在當前已登錄的Web應用程序上執行非本意的操作的攻擊方法 * #### CSRF 利用的是網站對用戶網頁瀏覽器的信任 ## beego自帶的防范機制: * #### 配置文件配置: * ~~~ enablexsrf = true xsrfkey = 61oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o xsrfexpire = 3600 ? //過期時間,默認1小時,單位秒 ~~~ * #### main.go文件的run前面: * ~~~ beego.BConfig.WebConfig.EnableXSRF = true beego.BConfig.WebConfig.XSRFKey = "61oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o" beego.BConfig.WebConfig.XSRFExpire = 360 ~~~ * #### 函數中設置xsrf數據:得在渲染模板的Get方法里面設置數據: ~~~ import "html/template" ? ? func (c *UserController) Get() { ? c.Data["xsrfdata"]=template.HTML(c.XSRFFormHTML()) ? c.TplName = "user.html" } ~~~ ~~~ func (c *UserController) Post() { ? c.TplName = "index.tpl" } ~~~ * 函數中重新設置過期時間: ~~~ this.XSRFExpire = 7200 this.Data["xsrfdata"]=template.HTML(this.XSRFFormHTML()) ~~~ * 模板中使用: ~~~ <form action="/user" method="post"> {{ .xsrfdata }} <input type="submit" value="提交"/> </form> ~~~ * #### ajax中使用:添加 \_xsrf 參數,需要兩個插件 #### jQuery cookie插件:[https://github.com/carhartl/jquery-cookie](https://github.com/carhartl/jquery-cookie) #### base64 插件:[http://phpjs.org/functions/base64\_decode/](http://phpjs.org/functions/base64_decode/) ~~~ var xsrf, xsrflist; xsrf = $.cookie("_xsrf"); xsrflist = xsrf.split("|"); args._xsrf = base64_decode(xsrflist[0]); ? args就是要提交的數據 ~~~ ## 支持controller級別的屏蔽:不讓xsrf在這個控制器中生效,就要重寫此控制器的Prepare方法。 ### **此處的Prepare不能寫錯或寫別的方法。** * #### 只需要在需要屏蔽的controller中的Prepare方法中設置為false即可: ~~~ // Prepare方法實在init后,請求方法前執行的 func (c *UploadController) Prepare() { ? c.EnableXSRF = false } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看