- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我尝试上传普通 jpeg 图像和 png 时,我没有收到来自 AJAX/Rails 的错误。但是,当我尝试上传 gif(已列入白名单)时。它将用户重定向回主页。它声称在表单发布时没有创建csrf_token。使用 create.js.erb 时如何将 csrf_token 添加到表单?
服务器开发日志
Started POST "/posts" for 127.0.0.1 at 2019-02-24 19:39:51 -0500
Processing by PostsController#create as HTML
Parameters: {"utf8"=>"✓", "post"=>{"body_text"=>"Testing the gif again!", "photo_cache"=>""}, "commit"=>"Post"}
User Load (1.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 51], ["LIMIT", 1]]
Can't verify CSRF token authenticity.
(1.0ms) BEGIN
(0.0ms) COMMIT
Completed 401 Unauthorized in 110ms (ActiveRecord: 2.0ms)
Started GET "/login" for 127.0.0.1 at 2019-02-24 19:39:53 -0500
Processing by Devise::SessionsController#new as HTML
User Load (1.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 51], ["LIMIT", 1]]
Redirected to https://127.0.0.1/
Filter chain halted as :require_no_authentication rendered or redirected
Completed 302 Found in 5ms (ActiveRecord: 1.0ms)
Started GET "/" for 127.0.0.1 at 2019-02-24 19:39:55 -0500
Processing by HomeController#index as HTML
posts_form.html.erb
<%= simple_form_for(@post, multipart: true, remote: true) do |f| %>
<div class="row">
<div class="col">
<div class="post-textarea">
<%= f.input :body_text, as: :text, class: 'form-control post-placeholder', label: false, placeholder: 'Add a post to share with others', style: "overflow: hidden; resize: none;" %>
</div>
</div>
</div>
<div class="row">
<div class="col-md-5">
<%= f.button :submit, 'Post', class: 'form-control submit-button bttn-gradient bttn-md bttn-royal', :data => {:disable_with => 'Wait...a min'} %>
</div>
<div class="col-md-5">
<label class="bttn-minimal bttn-md bttn-royal">
Add Photo
<span style="display:none;">
<%= f.input :photo, as: :file, label: false, input_html: {accept: 'image/*'} %>
</span>
</label>
<% if f.object.photo? %>
<%= image_tag f.object.photo.url(:feed_preview), class: 'img-responsive img-thumbnail' %>
<% end %>
<%= f.hidden_field :photo_cache %>
<div class="post-preview-container">
<img id="img_prev" width="100" height="100" src="#" alt="preview" class="img-thumbnail d-none"/> <br/>
<a href="#" id="cancel_img_btn" class="d-none" onclick="return !(document.getElementById('photo').innerHTML=document.getElementById('photo').innerHTML);">Cancel
Upload</a>
</div>
</div>
</div>
<% end %>
create.js.erb
$("#container_posts").prepend("<%= j render partial: "posts/#{@post.post_type}", locals: {post: @post } %>");
$("#post_<%= @post.id %>").hide().fadeIn(1000);
$("#no-posts").hide().fadeOut();
$("#body_text").val("");
$("#img_prev").hide().fadeOut();
$("#cancel_img_btn").hide().fadeOut();
最佳答案
你可以尝试这样做。看看这是否有效。
<%= simple_form_for(@post, multipart: true, remote: true, authenticity_token: true) do |f| %>
关于javascript - 使用 Carrierwave 发布 gif 时,AJAX 无法验证 CSRF token 的真实性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54858207/
假设我的 Web 应用程序使用 CSRF token 防止 CSRF 攻击,此外,它使用 SSL 并防止 XSS 攻击。此外,出于这个问题的目的,假设它仅在最近的浏览器中使用并且它们没有错误。我可以使
很多人都在谈论实现 CSRF 来阻止对网页的跨站点攻击。但我认为破坏 CSRF 并向服务器发出请求非常容易。 那么它是如何工作的呢? 您从一个页面开始,呈现一个表单并使用 CSRF token 保留一
在阅读了许多有关 CSRF 的文档后,我仍然有点困惑。所以我希望有人可以向我解释一下: 假设我有一个仅供经过身份验证的用户使用的个人资料页面,比如说 abc.com/profile,它会显示我所有的私
我们基于 Angular 的 web 应用程序与在不同域和上下文路径上运行的企业门户集成。我正在使用基于 Spring Security 的 CSRF token 来验证传入的请求。该应用程序在本地完
我正在开发一个 Web API。身份验证是通过 cookie 进行的。所有端点通过JSON接收参数在请求正文中。 我需要实现 CSRF token保护他们?这怎么可能被利用呢?是否可以通过正常发送JS
我正在开发一个从 cookie header 解析 CSRF token 的应用程序。我想知道 CSRF token 是否使用 URL 安全字符进行 base64 编码(参见 https://simp
我知道当提交时表单中未包含 csrf token 时会发生此错误,但这次并非如此。 我正在尝试登录管理站点。管理员登录表单包含 csrf token ,我可以看到该 csrf token 的值与 cs
有没有办法对 Controller 的某些操作禁用 CSRF 验证,同时对其他操作保持启用状态? 就我而言,我有几个可配置的 Action 类,它们旨在注入(inject)到 Controller 中
我正在编写一个应用程序(Django,确实如此),我只想了解“CSRF token ”实际上是什么以及它如何保护数据。 如果不使用CSRF token ,发布数据不安全吗? 最佳答案 简单来说跨站请求
来自维基百科关于同源政策 https://en.wikipedia.org/wiki/Same-origin_policy The same-origin policy helps protect s
我在 Vue 环境中使用 axios 与用 Symfony 编写的网络服务对话。每个请求都需要设置一个 X-Auth-Token header 。该值存储在 auth_token cookie 中。
我想保护我的 REST 调用免受 XSRF 攻击。我正在做的是: 服务器在用户成功登录后向浏览器发送一个记录的 cookie。 在每个请求(GET、POST、DELETE)上,我将登录的 cookie
我知道这个问题以前有人问过。我已经尝试了人们给出的几乎所有选项,但我似乎无法解决它。我是一个完整的新手,所以请让我知道我哪里出错了。 我正在尝试编写一个简单的原始表单。到目前为止,我还没有实现任何身份
似乎 Laravel 5 默认将 CSRF 过滤器应用于所有非获取请求。这对于表单 POST 是可以的,但对于 POST DELETE 等的 API 可能是一个问题。 简单的问题: 如何设置没有 CS
当我从客户端向服务器发出 DELETE 请求时,我遇到了错误。 “CSRF token 已关联到此客户端”。响应代码:403 和响应头 { "cache-control": "no-cache,
to prevent CSRF attacks, a random CSRF secret has been generated. 以上内容来自 symfony: http://www.symfony
我正在使用 Django Rest Framework还有 django-rest-auth . 我有标准的 API 端点(/login、/logout、/registration...) 使用我的浏
这个问题在这里已经有了答案: OAuth2.0 Server stack how to use state to prevent CSRF? for draft2.0 v20 (3 个回答) 4年前关
我需要知道如何在 Impresspages cms 中禁用 CSRF 功能。我在之前的帖子中看到了一个可能的答案,但没有完全分类。当我的客户在 cleanwaterpartnership.co.uk
我正在使用 Django 1.7 和 django-rest-framework。 我制作了一个 API,它返回一些 JSON 数据并将其放入我的 settings.py REST_FRAMEWORK
我是一名优秀的程序员,十分优秀!