0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Railsのログにおいてあるカラムの値がFILTEREDで表示されない

Posted at

はじめに

現在、フロントエンドからS3に対して presignedURLを通じた

ファイルアップロードを試みています。

成功後は あらかじめ生成した s3のkeyをbackendにPostして DBにインサートしています。

そこでRailsのログを眺めていたところ

先ほどの keyはただの文字列であるのに対して

カラムのログには "[FILTERED]"と出ていました。

こういうのって password とかそういうのだけではないの?

というのが疑問の発端です。

結論

Railsデフォルトのセキュリティ機能で

特定の文字列を含むデータベースカラムの値をログに表示させるとき、

条件に合致したら "[FILETERD]"と出力するためです。

原因は config/initilizers/parameter_logging.rbの下記

parameter_logging.rb
# Configure sensitive parameters which will be filtered from the log file.
Rails.application.config.filter_parameters += %i[
  passw secret token _key crypt salt certificate otp ssn
]

今回の場合は "s3_key"というカラムを表示させようとしていたので

上記条件に引っ掛かり "FILTERED"と表示されたというわけです。

終わりに

セキュリティ機能なので 無闇にいじることはやめておきます。

カラム名を変えるか、開発環境だけ出るようにするかにしたいと思います。

ただカラム名は 変に変えると後でわからなくなるし、本番でFILTEREDとしたら

追跡するの大変ではなかろうか。

普通どうやるもんなのでしょうかね。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?