热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

ReactLandingPage与Rails后端的安全通信?-SecurecommunicationfromReactLandingPagewithRailsBackend?

ImbuildingaLandingPageinReactwhereavisitorsubmitssomedata(includingnameandphone)an

I'm building a Landing Page in React where a visitor submits some data (including name and phone) and this data is sent over HTTP to a Rails 4.2 Backend.

我正在React中构建一个登陆页面,其中访问者提交一些数据(包括姓名和电话),这些数据通过HTTP发送到Rails 4.2后端。

Now, in order for the Landing Page to be able to POST data to the backend, there needs to be some sort of authentication, as only a registered staff member should have access to the data. The Rails backend currently uses regular Devise user/password login to the backend.

现在,为了使着陆页能够将数据发布到后端,需要进行某种身份验证,因为只有注册的工作人员才能访问数据。 Rails后端目前使用常规的Devise用户/密码登录到后端。

I thought about making a dummy account and hardcode an authorization token on the POST header from the landing page, but this is obviously a big security flaw as anyone can see the hardcoded token when they submit the form.

我考虑过制作虚拟帐户并在登陆页面的POST标题上对授权令牌进行硬编码,但这显然是一个很大的安全漏洞,因为任何人都可以在提交表单时看到硬编码令牌。

How can I secure the Landing Page to send / receive data to the backend server in a user-agnostic way (since visitors don't make accounts, they just fill a form with their details)?

如何保护目标网页以用户无关的方式向后端服务器发送/接收数据(因为访问者不会创建帐户,他们只是填写表单及其详细信息)?

2 个解决方案

#1


1  

I am not rails user. But as for your API, like almost all the RESTful API backend, I would assume that rails has the concept of public/private API. I would make the API for getting data from the user public, so that people can send their information without authentication and the other API routes private.

我不是rails用户。但至于你的API,就像几乎所有RESTful API后端一样,我认为rails具有公共/私有API的概念。我会创建用于从用户公开获取数据的API,以便人们可以在没有身份验证的情况下发送他们的信息,并且其他API路由是私有的。

In java spring framework, I can allow an API route to accessible by everyone, like login and generic(no private info) API routes and every other API routes are private which requires Authentication(like an auth-token).

在java spring框架中,我可以允许每个人都可以访问API路由,例如登录和通用(无私有信息)API路由,并且每个其他API路由都是私有的,需要身份验证(如auth-token)。

#2


0  

When, you do the login flow and the user has entered the password and hit send, Once your backend authenticates the details, you would have to create an signed authorization token using maybe JWT** ( Json web token ) and send this authorization token to the front-end.

当您执行登录流程并且用户输入密码并点击发送时,一旦您的后端验证详细信息,您将不得不使用JWT **(Json Web令牌)创建签名授权令牌并将此授权令牌发送到前端。

Then, Whenever the front-end makes a call to the backend, it has to attach this token in the header before making the API call. And the back-end should de-code the token to find out which user is requesting it and if the ttl* is within the limits as the issuing token.

然后,每当前端调用后端时,它必须在进行API调用之前将此标记附加到标头中。并且后端应该对令牌进行解码以找出哪个用户正在请求它以及ttl *是否在作为发布令牌的限制内。

If both the cases pass, the back-end should send the requested data or it should send a HTTP CODE - 403/Forbidden, which should then be handled in the front-end to logout the user and open up the login page again.

如果两种情况都通过,后端应该发送请求的数据,或者它应该发送HTTP CODE-403 / Forbidden,然后应该在前端处理以注销用户并再次打开登录页面。

*(Time to live calculated based on the hours this token is valid from the time of issuing/login)

*(生效时间根据此令牌从签发/登录时起有效的小时数计算)

** JWTs are basically base-64 encoded data ( and signed with a unique key by your backend ) of the user's data. A decoded JWT token of a user would most likely look like this :

** JWT基本上是用户数据的base-64编码数据(并由后端用唯一键签名)。用户的解码JWT令牌很可能如下所示:

{ 
    userIs : "0000-aa12-bb43-cd18", 
    userName : "Some name", 
    ttl : "Time to live of this token" 
}

推荐阅读
  • 使用ffmpeg进行视频格式转换的简单例子2006-12-1623:12主要参考FFMPEG里面的apiexample.c以及output_example.c编写intmain(in ... [详细]
  • node的特点:它作为js的运行平台,node保留了前端浏览器js那些熟悉的接口,依旧基于作用于和原型链,区别在于它将前端中广泛应用的思想迁移到服务器。异步IO:关键字:异 ... [详细]
  • FroggerTimeLimit:1000MSMemoryLimit:65536KTotalSubmissions:32257Accepted:10396DescriptionFr ... [详细]
  • 8月3日每日安全热点用Chankro绕过PHP disable_functions
    8月3日每日安全热点用Chankro绕过PHP disable_functions ... [详细]
  • 开发笔记:sql盲注之报错注入(附自动化脚本)
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了sql盲注之报错注入(附自动化脚本)相关的知识,希望对你有一定的参考价值。 ... [详细]
  • rtemsapi用户指南Elixir代表了相对较新的编程语言,面向更广泛的受众。它于2011年发布,此后一直在开发中。他的主要特征是取消功能范式 ... [详细]
  • 篇首语:本文由编程笔记#小编为大家整理,主要介绍了将JSON数组反序列化为强类型的.NET对象相关的知识,希望对你有一定的参考价值。 ... [详细]
  • Android 自定义控件基础 canvas paint
    1、首先说一下canvas类:ClassOverviewTheCanvasclassholdsthedrawcalls.Todrawsomething,youne ... [详细]
  • 在写每日签到的时候,我居然使用的是本地时间被项目经理笑哭了。。。。,如果你在写单机游戏,没有游戏服务器,但又不想使用本地时间,就可以采用下面方法.方法总结:     1.使用 ... [详细]
  • 一、使用ContentProvider(内容提供者)共享数据ContentProvider在android中的作用是对外共享数据,也就是说 ... [详细]
  • Spark 贝叶斯分类算法
    一、贝叶斯定理数学基础我们都知道条件概率的数学公式形式为即B发生的条件下A发生的概率等于A和B同时发生的概率除以B发生的概率。根据此公式变换,得到贝叶斯公式:即贝叶斯定律是关于随机 ... [详细]
  • IE下PHPiframe跨域导致session丢失问题的解决方法|一个登录页面,被别的网站用iframe嵌进去后,死活无法登录(只在IE中存在这种情况)。主要是session无 ... [详细]
  • ASP.NET使用Ajax如何返回Json对象的示例方法介绍
    这篇文章主要介绍了ASP.NET使用Ajax返回Json对象的方法,非常不错,具有参考借鉴价值,需要的朋友可以参考下一、 ... [详细]
  • MySQL的SQL语句写法,除了那些基本的之外,还有一些也算比较常用的,这里记录下来,以便以后查找。好记性不如烂笔头& ... [详细]
  • 历史指对人类社会过来的事件和流动,以及对这些事件行为有零碎的记录、钻研和诠释。历史是文化的传承,积攒和扩大,是人类文明的轨迹。APISpace的历史上的 ... [详细]
author-avatar
e我爱你很多
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有