Tagging a string as html safe may be a security risk

RuboCop(0.48.1) で Tagging a string as html safe may be a security risk と怒られた

htmlタグを直書きせずにcontent_tagを使えということらしい↓

# bad
"<p>#{text}</p>".html_safe

# good
content_tag(:p, text)

# bad
out = ""
out << content_tag(:li, "one")
out << content_tag(:li, "two")
out.html_safe

# good
out = []
out << content_tag(:li, "one")
out << content_tag(:li, "two")
safe_join(out)

引用元
Class: RuboCop::Cop::Rails::OutputSafety — Documentation for rubocop (0.41.2)

RailsでHSTS includeSubDomainsを外す方法

Rails5からforce_sslを設定しているHSTSでサブドメインまで対象にされてしまうようで設定から外したい

config/initializers/new_framework_defaults.rb に以下を追加でサブドメインを外すことができます

Rails.application.config.ssl_options = { hsts: { subdomains: false } }

参考

ssl - How can I turn off includeSubDomains for HSTS in rails? - Stack Overflow

Chromeでhttpからhttpsに勝手にリダイレクトされる問題の解消[SSL]

なぜかChromeだけhttpからhttpsにリダイレクトされるサイトがあり原因を探していたらこちらの記事を発見

beniyama.hatenablog.jp

ChromeSSLサイトのドメインを覚えて勝手にリダイレクトしてくれているらしい
HTTP Strict Transport Security(HSTS)め…
設定次第ではサブドメインまで勝手にSSLにされるという余計なお世話感

HSTSをリセットする方法

以下のURLにアクセス
chrome://net-internals/#hsts

Delete domainで対象ドメインを削除

参考
https://i-think-it.net/chrome-http-https-force-redirect-approache/

Rails コントローラーからヘルパーメソッドを呼ぶ [controller,helper]

Railsのコントローラーからヘルパーメソッドを呼びたい

view_context を使う

view_context.hogehoge

ヘルパーをインクルードしたりしなくても使えるみたい