首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >设计和安全:3个管理角色与布尔人。这100%安全吗?

设计和安全:3个管理角色与布尔人。这100%安全吗?
EN

Stack Overflow用户
提问于 2016-08-26 06:58:56
回答 1查看 143关注 0票数 1

我已经为基于设计的应用程序定义了3个管理角色。God_mode,normal_mode和guest_mode。他们都是布尔人。但我想知道是否没有办法绕过,以某种方式伪造一个请求,并发送一个'admin god_mode: True‘-请求一个正常的管理员或客人管理员?通过大规模分配或类似的方式攻击我的应用程序。

我只想知道这是否是完全不可破解和100%安全的。

为了这个例子本身,我搭建了CRUD--应用程序的一部分(在真实世界中不打算这样做),但是params部分是相同的。设计配置是默认的/开箱即用。

我基本上有3个管理员角色(布尔人)和一个"before_action :authenticate_admin!“+一个带有client_params和params.require(:client).permit(:name、:description)的私有方法--我想知道这本身是否足以使我的网站免受恶意攻击。我们假设我知道如何保护我自己的电脑,不被钓鱼,等等。

我搜索了很多,不幸的是,很多rails 3文章仍然弹出,并且是基于过时的(?)attr_accessible和类似的。我知道我们现在使用的是强参数,但对我来说,这一切看起来都太好了--对我来说--难道没有任何方法可以让你的客户管理员角色变成管理god_mode吗?

Clients.rb

代码语言:javascript
复制
class ClientsController < ApplicationController

before_action :set_client, only: [:show, :edit, :update, :destroy]

before_action :authenticate_admin!


# GET /clients
# GET /clients.json
def index
  @clients = Client.all
end

# GET /clients/1
# GET /clients/1.json

def show
end

# GET /clients/new

def new
  @client = Client.new
end

# GET /clients/1/edit

def edit
end

# POST /clients
# POST /clients.json

def create
@client = Client.new(client_params)

respond_to do |format|
  if @client.save
    format.html { redirect_to @client, notice: 'Client was successfully created.' }
    format.json { render :show, status: :created, location: @client }
  else
    format.html { render :new }
    format.json { render json: @client.errors, status: :unprocessable_entity }
  end
  end
  end

# PATCH/PUT /clients/1
# PATCH/PUT /clients/1.json
def update
  respond_to do |format|
    if @client.update(client_params)
      format.html { redirect_to @client, notice: 'Client was successfully updated.' }
    format.json { render :show, status: :ok, location: @client }
  else
    format.html { render :edit }
    format.json { render json: @client.errors, status: :unprocessable_entity }
  end
end
end

# DELETE /clients/1
# DELETE /clients/1.json
def destroy
  @client.destroy
    respond_to do |format|
    format.html { redirect_to clients_url, notice: 'Client was successfully destroyed.' }
    format.json { head :no_content }
  end
end

private
  # Use callbacks to share common setup or constraints between actions.
  def set_client
    @client = Client.find(params[:id])
  end

  # Never trust parameters from the scary internet, only allow the white list through.
  def client_params
    params.require(:client).permit(:name, :description)
  end
  end

schmema: (管理员应该有一个默认值=false):

代码语言:javascript
复制
ActiveRecord::Schema.define(version: 20160825190018) do

  create_table "admins", force: :cascade do |t|
    t.string   "email",                  default: "", null: false
    t.string   "encrypted_password",     default: "", null: false
    t.string   "reset_password_token"
    t.datetime "reset_password_sent_at"
    t.datetime "remember_created_at"
    t.integer  "sign_in_count",          default: 0,  null: false
    t.datetime "current_sign_in_at"
    t.datetime "last_sign_in_at"
    t.string   "current_sign_in_ip"
    t.string   "last_sign_in_ip"
    t.boolean  "god_mode"
    t.boolean  "normal_mode"
    t.boolean  "guest_mode"
    t.datetime "created_at",                          null: false
    t.datetime "updated_at",                          null: false
    t.index ["email"], name: "index_admins_on_email", unique: true
    t.index ["reset_password_token"], name: "index_admins_on_reset_password_token", unique: true
  end

  create_table "clients", force: :cascade do |t|
    t.string   "name"
    t.text     "description"
    t.datetime "created_at",  null: false
    t.datetime "updated_at",  null: false
  end

end
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-09-01 21:49:57

我会在您的代码中更改一些内容:

  • 我不会在数据库中有3个布尔字段来存储用户的角色,而是存储一个表示该角色的整数。这样,您就可以在需要时添加更多的角色。此外,没有什么可以阻止您设置多个这些标志为true,留下一个奇怪的配置。
  • 我不检查用户是否是管理员(这似乎就是before_action :authenticate_admin!的目的),而是检查日志记录的用户是否有执行某项任务的权限。在每个操作中,我将检查日志记录的用户是否有创建用户、更新用户等的权限。这些权限将定义在一个文件中,您只需说哪个角色可以执行这些操作。查看一下CanCan (Rails 3)或CanCanCan (Rails > 3)可能是有用的。这样做的原因是,在某个时候,您可能希望允许其他角色对您的用户执行某些操作(可能是索引?),您只需修改权限文件就可以让他们访问您的用户列表。甚至连控制器都不碰。

最后,我只想说,在安全性方面,没有人能保证一个系统是不可破解的。即使您尽力确保您的服务安全,0天漏洞、第三方宝石或人为错误(代码错误、配置错误的服务器/路由器、.)可能会留下一个小洞,足以让攻击者进入。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39160174

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档