Kích hoạt HSTS cho web sites

Tóm tắt nội dung

HTTP Strict Transport Security ( HSTS ) là một cơ chế chính sách giúp bảo vệ các trang web chống lại các cuộc tấn công trung gian như tấn công hạ cấp giao thức và chiếm quyền điều khiển cookie. Nó cho phép các máy chủ web tuyên bố rằng các trình duyệt web (hoặc các tác nhân người dùng tuân thủ khác) sẽ tự động tương tác với nó bằng các kết nối HTTPS chỉ cung cấp Bảo mật tầng vận chuyển (TLS/SSL), không giống như HTTP không an toàn được sử dụng một mình. HSTS là một giao thức theo dõi tiêu chuẩn của IETF và được chỉ định trong RFC 6797

Đối với tùy chọn [includeSubDomains] bên dưới, tất cả các tên miền phụ được bao gồm trong HSTS, vì vậy bạn cần xác minh kỹ trước khi cài đặt có thể truy cập vào tất cả các tên miền phụ bằng HTTS nếu chỉ định tùy chọn này

Cấu hình trên Powershell

trên powershell chạy với quyền quản trị là Admin và cấu hình như sau

				
					Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

# get site collection
PS C:\Users\Administrator> $sitesCollection = Get-IISConfigSection -SectionPath "system.applicationHost/sites" | Get-IISConfigCollection 

# get web site you'd like to set HSTS
# specify the name of site for "name"="***"
PS C:\Users\Administrator> $siteElement = Get-IISConfigCollectionElement -ConfigCollection $sitesCollection -ConfigAttribute @{"name"="RX-7.srv.world"} 

# get setting of HSTS for target site
PS C:\Users\Administrator> $hstsElement = Get-IISConfigElement -ConfigElement $siteElement -ChildElementName "hsts" 

# enable HSTS for target site
PS C:\Users\Administrator> Set-IISConfigAttributeValue -ConfigElement $hstsElement -AttributeName "enabled" -AttributeValue $true 

# set [max-age] of HSTS as 31536000 sec (365 days)
# for [max-age], refer to https://hstspreload.org/ 
PS C:\Users\Administrator> Set-IISConfigAttributeValue -ConfigElement $hstsElement -AttributeName "max-age" -AttributeValue 31536000 

# set [includeSubDomains] of HSTS as enabled
# this option applys to all subdomains
PS C:\Users\Administrator> Set-IISConfigAttributeValue -ConfigElement $hstsElement -AttributeName "includeSubDomains" -AttributeValue $true 

# set [redirectHttpToHttps] of HSTS as enabled
PS C:\Users\Administrator> Set-IISConfigAttributeValue -ConfigElement $hstsElement -AttributeName "redirectHttpToHttps" -AttributeValue $true 
				
			

Cấu hình trên GUI

Mở Server Manager và chọn Tools – Internet Information Services (IIS) Manager, sau đó chọn website bạn muốn đặt HSTS và nhấn chọn HSTS…

tiếp theo, nhấn chọn hộp Enable.
Đối với các tùy chọn khác bạn có thể tham khảo tại https://hstspreload.org/


Contact
Nhấn để liên hệ