LoginSignup
7
5

More than 5 years have passed since last update.

Big-IPで付与されるCookieをセキュアにする

Last updated at Posted at 2018-08-17

背景

脆弱性スキャンを行った際、一部のCookieがSecure属性とhttponlyが付いていない事が判明
アプリ側で対応したが、それでも対応されていないCookieが存在した

curlで確認出来るので、下記コマンドを打てば、Set-Cookieの後にSecure, HttpOnlyと入ってなければ、セキュアになっていないCookieがわかる。

$ curl -I https://【対象サイト】
HTTP/1.0 200 Connection established

HTTP/1.1 200 OK
Cache-Control: private,no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0
Pragma: no-cache
Content-Length: 5938
Content-Type: text/html; charset=utf-8
Set-Cookie: ASP.NET_SessionId=xxxxxxxxxxxxxxxxxxxxx; path=/; secure; HttpOnly
X-AspNet-Version: 4.0.30319
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block
Content-Security-Policy: default-src 'self';
X-Content-Type-Options: nosniff
Date: Fri, 17 Aug 2018 06:45:35 GMT
Set-Cookie: BIGipServer【プール名】=!xxxxxdA7lFNwJAap8gex7xUUExxxxxrpyPJf4q9juW3Qq0LeFpvZMVg+qBN5Gcxxxxxad6Kq8BlE=; path=/;
Set-Cookie: TSxxxxxxxx=xxxxx4f668f3xxxxa33d6eb34fe4613ab33cf413354cf22cb9f9cb84ec415a00a75bf55629e649xxxxxd93c999c392a4906ed9c59d279ed00ed5da851123675981abdf98ad47ee59381ff7af8097e637e3f778587; Path=/;

Cookie

上記の結果、対象のCookieは下記3つとわかった

  • ASP.NET_SessionId=xxxxxxxxxxxxxxxxxxxxx; path=/; secure; HttpOnly
  • BIGipServer【プール名】=!xxxxxdA7lFNwJAap8gex7xUUExxxxxrpyPJf4q9juW3Qq0LeFpvZMVg+qBN5Gcxxxxxad6Kq8BlE=; path=/;
  • TSxxxxxxxx=xxxxx4f668f3xxxxa33d6eb34fe4613ab33cf413354cf22cb9f9cb84ec415a00a75bf55629e649xxxxxd93c999c392a4906ed9c59d279ed00ed5da851123675981abdf98ad47ee59381ff7af8097e637e3f778587; Path=/;

ASP.NET_SessionIdはアプリ側で付与したCookieで、secure; HttpOnlyが付いているので問題なし
残りの下記2つをセキュアにする必要がある

  • BIGipServer【プール名】
  • TSxxxxxxxx

各種設定変更

それぞれのCookieに対して、下記のように対応する必要がある

BIGipServer【プール名】 → Cookie Profileの設定
TSxxxxxxxx →環境変数の設定

Cookie Profileの設定

今回の構成だと、Big-IP配下にいるWebサーバに対して、セッション維持が必要であったため、Persistenceを設定していた
その中のCookie persistenceのInsert Modeを利用していたため、Big-IP独自でCookieを発行し、セッション維持を行っていた
そのCookieについての設定はPersistenceの設定で行える

設定手順

こちらは管理画面(GUI)から設定可能
まず、対象のPersistenceが何かを確認したいので、対象サーバのVirtual Serverを確認し、下記へ移動
Local Traffic ›› Virtual Servers : Virtual Server List >> Virtual Server >> Resources
こちらのDefault Persistence Profileに記載されているものが、対象のPersistenceの設定内容となる
上記の名前を元に、下記へ移動
Local Traffic ›› Profiles : Persistence
その中の、下記2項目をEnabledに設定

  • HTTPOnly Attribute
  • Secure Attribute

確認手順

GUIなので、設定したものが記載されていれば問題なし
冗長化されている場合、設定号機がIn Syncになっていれば他号機へ設定が入っているのでOK
気になる君なあなたは、他号機も見ればいいと思うよ

環境変数の設定

上記設定で、BIGipServer【プール名】のCookieはセキュアになったので、残りはTSxxxxxxxxとなる
TSxxxxxxxxは、The Main ASM cookieであり、セキュア属性とhttponlyをつけたい場合、
環境変数(cookie_secure_attrとcookie_httponly_attr)を設定する必要がある。

設定手順

環境変数はGUIからは設定できないみたいなので、SSHで接続してCLIで設定する
設定後にasmの再起動が必要なので、忘れず実施する

[15:57:17 bastion-user@bastion ~]$ ssh bigip-user@lb01
[bigip-user@lb01:Active:In Sync] ~ # /usr/share/ts/bin/add_del_internal add cookie_httponly_attr
Operation completed successfully. Don't forget to restart ASM to apply changes.
[bigip-user@lb01:Active:In Sync] ~ # /usr/share/ts/bin/add_del_internal add cookie_secure_attr
Operation completed successfully. Don't forget to restart ASM to apply changes.
[bigip-user@lb01:Active:In Sync] ~ # bigstart status asm
asm          run (pid 19471) 14 minutes, 4 starts
[bigip-user@lb01:Active:In Sync] ~ # bigstart restart asm
Aug 17 16:00:29 lb01 emerg logger: Re-starting bigd
[bigip-user@lb01:Offline:In Sync] ~ # bigstart status asm
asm          run (pid 20418) 5 seconds, 5 starts

また、冗長化構成の場合、環境変数は同期対象外のため、全号機設定が必要

確認手順

管理画面(GUI)から接続し、下記を表示する
そこに設定したcookie_secure_attrとcookie_httponly_attrが存在すれば、設定できている

  • BIG-IP ASM 11.3.0 and later
    • Security > Options > Application Security > Advanced Configuration > System Variables
  • BIG-IP ASM 10.2.2 through 11.2.1
    • Application Security > Options > Advance Configuration > System Variables

最終確認

$ curl -I https://【対象サイト】
HTTP/1.0 200 Connection established

HTTP/1.1 200 OK
Cache-Control: private,no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0
Pragma: no-cache
Content-Length: 5938
Content-Type: text/html; charset=utf-8
X-AspNet-Version: 4.0.30319
Set-Cookie: ASP.NET_SessionId=xxxxxxxxxxxxxxxxxxxxx; path=/; secure; HttpOnly
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block
Content-Security-Policy: default-src 'self';
X-Content-Type-Options: nosniff
Date: Fri, 17 Aug 2018 07:30:28 GMT
Set-Cookie: BIGipServer【プール名】=!xxxxxdA7lFNwJAap8gex7xUUExxxxxrpyPJf4q9juW3Qq0LeFpvZMVg+qBN5Gcxxxxxad6Kq8BlE=; path=/; Httponly; Secure
Set-Cookie: TSxxxxxxxx=xxxxx4f668f3xxxxa33d6eb34fe4613ab33cf413354cf22cb9f9cb84ec415a00a75bf55629e649xxxxxd93c999c392a4906ed9c59d279ed00ed5da851123675981abdf98ad47ee59381ff7af8097e637e3f778587; Path=/; Secure; HTTPOnly

となり、全CookieにSecureとHTTPOnlyがつきましたー

参考

7
5
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
7
5