Rails宝典之第九式: 在日志里过滤敏感数据

自定义Json注解实现输出日志字段脱敏 背景: 在日志输出的时候,有时会输出一些用户的敏感信息,如手机号,身份证号,银行卡号等,现需要对这些信息在日志输出的时候进行脱敏处理 思路: 使用fastjson的ValueFilter对带有自定义注解的字段进行过滤 阅读详情
这是个安全问题,当我们在系统注册页面输入密码等敏感数据时,我们可以看到,密码以明文的形式显示在日志文件里: 
Java代码   收藏代码
  1. Processing UsersController#create (for 127.0.0.1 at 2007-02-23 19:11:20) [POST]  
  2.   Session ID: 4047778b64af62d387f7e860e51cce20  
  3.   [color=red]Parameters[/color]: {"user" => {"name" => "Ryan", "password_confirmation" => "abc123", "password" => "abc123"}, "commit" =>   
  4. "Register", "action" => "create", "controller" => "users"}  
  5.   SQL (0.000108) BEGIN  
  6.   [color=red]SQL[/color] (0.000238) INSERT INTO users ('name', 'password') VALUES('Ryan', 'abc123')  
  7.   SQL (0.000395) COMMIT  
  8. Redirected to http://localhost:3000/users/5  
  9. ...  

我们看到Parameters一行密码是明文显示的,这样当然不安全。 

解决方案也十分简单: 
Java代码   收藏代码
  1. class ApplicationController < ActionController::Base  
  2.   filter_parameter_logging "password"  
  3. end  

这样在Parameters那行就会显示"password_confirmation" => "[FILTERED]","password" => "[FILTERED]" 
filter_parameter_logging的方法定义位于action_pack/lib/action_controller/base.rb。 

但是我们也看到SQL一行也是明文密码,我们的filter不会过滤SQL语句,怎么办? 

解决方案是,部署production环境时,日志不会再打印SQL语句,这样就避免了此问题。
小米澎湃OS EU版刷机实战:KernelSU 0.9.4 激活与钱包模块精简指南 本文详细介绍了小米澎湃OS EU版的刷机实战,重点讲解了KernelSU 0.9.4的激活与钱包模块的精简方案。通过移除非必要组件和优化NFC支付功能,实现更纯净的Android体验,同时保留核心支付功能如公交卡模拟。适合追求系统精简与功能平衡的发烧友。 阅读详情

相关推荐

静态代码扫描——PMD自定义规则实践(Log日志文件中不要输出敏感信息)

上篇文章用一个简单的规则举例,帮助大家快速了解如何自定义规则。接下来我们开始使用比较复杂的例子进行剖析撰写规则的过程。

oggboy的专栏 3468

日志里的敏感信息还在打明文?3 种日志脱敏方案任你选

背景我们打的日志中经常包含姓名、手机号、银行卡号等敏感信息,如果不做任何处理,就会以明文的形式展示在日志中,存在安全风险。像下面这样:我们需要一种能自动帮我们脱敏的工具,效果如下:方案1 - 基于 logback我们得先搞清楚消息内容是在哪里处理的,也就是配置文件中这个占位符的内容:对应到源码是这里 ch.qos.logback.classic.PatternLayout :这里可以看出来都是通...

JiuQianWan的博客 1万+

敏感信息检查工具 关键字过滤

敏感词过滤、查找

Rails 安全之Filtered parameter logging

因为最近项目所需,翻到这篇老文,去年8月的文章,比较有用,原文地址:[url]http://weblog.rubyonrails.com/2006/8/21/filtered-parameter-logging[/url]ActionController#filter_parameter_logging 可以用来过滤那些你不想保存在日志中的数据,它可以阻止一些敏感数据赤裸裸的暴露在日志文件中,比如...

weixin_34336292的博客 145

3DSlicer冠脉分割实战:从DICOM导入到三维重建的完整流程(附常见问题解决)

本文详细介绍了使用3DSlicer进行冠脉分割的完整流程,从DICOM数据导入到三维重建,涵盖环境配置、视图优化、心脏区域分割及冠脉精细分割等关键步骤。针对常见问题提供实用解决方案,帮助医学影像从业者高效完成心血管结构分析,提升诊断准确性。

weixin_29271053的博客 627

用SPSS做信效度分析

对问卷进行Cronbach’s Alpha信度检验。如果此值高于0.8,则说明信度高;如果此值介于0.7-0.8之间,则说明信度较好;如果此值介于0.6~0.7,则说明信度可接受;如果此值小于0.6,说明信度不佳。下面利用SPSS进行分析,点击分析–标度–可靠性分析选项,选中所要分析的问卷数据或题目。得到结果,我们要看这个有用的结果,当克隆巴赫Alpha系数(也可以看标准化后的)大于0.8时候,说明问卷信度较高。

小高~的博客 1万+

超详细部署ELK日志分析系统!每一步骤都有记录!ELK的详细使用!

一、ELK简介 日志分析是运维工程师解决系统故障,发现问题的主要手段。日志主要包括系统日志、应用程序日志和安全日志。系统运维和开发人员可以通过日志了解服务器软硬件信息、检查配置过程中的错误及错误发生的原因,经常分析日志可以了解服务器的负荷,性能安全性,从而及时采取措施纠正错误。 日志是一个非常庞大的数据,并且常常被分散在不同的设备上,这样排查问题的时候找日志就非常繁琐困难。 这时,一个专门处理日志的系统就非常必要,这里介绍其中的一种,ELK日志分析系统(ELasticsearch+Logstash+Kiba

qq_41786285的博客 5531

PADS Layout中快速导入自定义元器件封装的实用技巧

本文详细介绍了在PADS Layout中高效导入自定义元器件封装的实用技巧。针对封装“找不到”、“对不上”、“导不进”三大痛点,系统梳理了从封装文件来源识别、库规划管理,到三种核心导入场景(从库文件添加、从其他设计借用、处理第三方格式)的完整操作流程,并提供了导入后的关键验证清单与常见问题排查方法,旨在帮助硬件工程师快速掌握这一提升设计效率的关键技能。

weixin_29302047的博客 375

#009_过滤日志中的敏感数据

当我们注册用户的时候,在日志中会自动保存一些敏感的字段,比如password等。 [code="ruby"]Processing LoginController#save (for 127.0.0.1 at 2008-04-08 13:53:22) [POST] Session ID: b40f205b38bd05382dc8ef2f362f5d5b Parameters: {"us...

wiisolax的专栏 511

of_graph_get_remote_port

isp { compatible = "isp"; core@0 { id = <0>; ports { #address-cells = <1>; #size-cells = <0>; port@0 { reg = <0>; ...

wmzjzwlzs的专栏 1163

【Web实战】微信小程序逆向

2E 70 6E 67”为带存放路径的文件名称,“00 00 11 7C”对应文件在小程序包中的具体偏移位置,“00 01 01 F7“对应文件在小程序包中的数据长度。但这并不是最初的原项目文件结构,原因是微信服务器会将小程序源码中所有的“js”文件压入“app-service.js”文件中,将所有的“json”文件压入“app-config.json”中,将所有的“wxml”文件压入“page-frame.html”文件中,“wxss”则在处理之后以“html”文件的形式存留在对应页面目录之下。

若有战,召必回 1941

Log4j日志分类和过滤敏感字段

项目上线时,需要对项目做安全检查,其中有两项是对输出日志进行分类和过滤掉日志中敏感字段。 项目使用Log4j日志系统,下面简单介绍下这两项要求的实现方式。 对日志进行分类,要求调用其他服务的API日志按照格式单独输出到一个文件。 方式: 除根Logger外,再额外增加一个apiLogger,如下, <!-- api logger的设置--> <logger name="l...

weixin_39722651的博客 9813

MIC(Maximal Information Coefficient)最大互信息系数

MIC(Maximal Information Coefficient)最大互信息系数是一种用于衡量两个变量之间相关性的统计量。它扩展了传统的互信息(MI)和条件互信息(CMI)的概念,具有更广泛的应用范围。MIC能够捕获包括功能性和非功能性的广泛的关联,具有普遍性和公平性。普遍性意味着在足够的样本量下,MIC能够捕捉到广泛的相关关系,而不仅仅局限于特定的功能类型;公平性则意味着MIC对不同类型的包含同等噪声的关系给出了相似的分数。需要注意的是,虽然MIC具有很多优点,但它也有一些局限性。

qlkaicx的博客 4603

敏感信息识别方法探究

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_33950035的博客 2836

uniapp H5刷新页面后返回按钮失效问题完美解决方案

这个问题其实很隐蔽,尤其是uniapp H5 场景下刷新导致栈清理,很多开发者一开始都懵掉了。uniapp 内部对「页面栈只有一个」时的返回逻辑是reLaunch;所以只要在这个分支里替换为自己的逻辑(比如),就能顺利实现预期。目前我在项目里已经跑通了,暂时没发现问题。不得不说,知道源码里这个逻辑后,真的是醍醐灌顶,只能膜拜框架大佬了 🤯。

代码简单说 Vue、JAVA、PHP、Node.js 熟练运用,接口、架构、性能全搞定。 522

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

敏 感 信 息 扫 描 工 具 使 用 对 比

0x00 前 言 渗 透 测 试 过 程 中 , 经 常 需 要 对 网 站 进 行 全 面 的 信 息 收 集 , 扫 描 网 站 是 否 存 在 敏 感 信 息 文 件 如 phpinfo 、 日 志 文 件 泄 漏 会 极 大的 方 便我 们 进 一 步 的 渗 透 测 试 , 特 别 是 对 于 一 些 403 网 站 , 通 过 爆 破 web 目 录 和 文 件 的 方 式 , 对 于...

weixin_34400525的博客 1526

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

1.logstash实现敏感信息脱敏及超长字符截取

我们通过filebeat收集的日志通常没有进行敏感信息的脱敏工作,以及一些base64超长字符如果不做处理,存储到es及在kibana展示也会耗费性能。 针对这两个问题我们可以进行如下配置: 1.设置超长字符截取 进入logstash安装目录,config文件夹下新建文件logstash_to_es相关配置如下: filter { if [type] == "filebeat" { grok ...

wang37444的专栏 4506

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

RailsCasts中文版,#9 Filtering Sensitive Logs 遮盖日志中记录的敏感信息

这是一个用户注册页面,填入用户名和密码按确认提交。 查看后台日志的话,能够发现所有页面提交的参数都是以明文方式保存在日志中的。 Processing UsersController#create (for 127.0.0.1 at 2009-01-02 10:13:13) [POST] Parameters: {"user"=>{"name"=>"eifion", "passw

边晓宇@优快云 1673

Log4j日志过滤

Log4J日志过滤器 过滤包含slow字符串的日志 设置只包含aduit字符串的日志

小程序员成长中...... 5235

rails日志过滤字段信息(filter_parameter_logging)

filter_parameter_logging : 该方法指定某些字段的内容不能显示在log日志中。 举例: filter_parameter_logging :password, :password_confirmation

ruby 闲谈 178

Github敏感信息自动扫描

‍‍新钛云服已为您服务1230天日常工作中,运维和开发同事通常会有自己的Github账号,用来上传自己编写的代码或存放博客文章、笔记等资料,有时会不经意的把公司或客户的敏感信息上传到Git...

NewTyun的博客 2182

[安全开发]日志敏感信息检测-3-正则合集(手机号、邮箱、车牌号)

前言 手机号 邮箱 车牌号 前言 从日志中提取所需信息时,建议两端加上\W用于匹配特殊字符,能减少不少误报 \W:匹配非单词字符,与"[^A-Za-z0-9_]"等效 手机号 手机号共11位,编码格式如下: 前3位:网络识别号 4至7位:地区编码 8至11位:用户号码 我们用下面这个正则,从日志中提取手机号 \W1[3-9]\d{9}\W 1[3-9]:匹配手机号前两位 \d{9}:匹配手机号后9位 虚拟运营商的出现,导致各种手机号段都有。并且2020年之后,中国广电也开始发行新的手机.

白夜的随笔 1996

Log文件显示敏感信息的问题

今天客户提出一个log里面显示了用户登录是显示了密码明文的问题,这些东西非常危险,恶意的人总是能想办法(这个办法很多,比如旁注等)拿到你的日志文件,而这个日志文件比起加密的数据库文件还要危险。 复制下面这行代码到ApplicaitonController Class中 filter_parameter_logging "password" 问题就解决了,log中显示为: Pr...

ghost138 1205
上一篇: Rails宝典之第八式: layout与content_for
下一篇: Rails宝典之第十式: 重构用户名-p1
blacksource
博客等级 码龄20年 66粉丝 23原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值