我正在使用服务堆栈开发自托管Windows HTTP服务,我请求实现基本身份验证(用户名/密码)以对调用应用程序进行身份验证。这是我现在使用的代码,它工作正常:
Plugins.Add(new AuthFeature(() => new AuthUserSession() {},
new IAuthProvider[] { new BasicAuthProvider() })); //CustomBasicAuthProvider()
container.Register<ICacheClient>(new MemoryCacheClient());
var userRepository = new InMemoryAuthRepository();
container.Register<IUserAuthRepository>(userRepository);
string hash;
string salt;
new SaltedHash().GetHashAndSaltString("passwordinhere", out hash, out salt);
userRepository.CreateUserAuth(new UserAuth()
{
Id = 1,
DisplayName = "userdisplayname",
UserName = "usernameinhere",
PasswordHash = hash,
Salt = salt
}
, "app");
当我检查来自我的服务的响应标头时,我清楚地看到它包含 2 个 cookie:
Set-Cookie: ss-id=dT8Yy6ejhgfjhgfkVvcxcxCNtngYRS4;path=/
Set-Cookie: ss-pid=p4lsgo18JhYF4CTcxkhgkhgffRZob;path=/;expires=Fri, 09 Jan 2037 12:17:03 GMT
出于安全目的,我需要配置 ServiceStack 以将 ;httpOnly 标志添加到这些 cookie 中,但我找不到如何做到这一点。
所以伙计们,有人知道怎么做吗?任何想法都是非常受欢迎的。
提前感谢您的帮助:)
您可以控制是否在 Cookie 上设置HttpOnly
标志,默认情况下false
Config.AllowNonHttpOnlyCookies
,因此始终设置 HttpOnly
标志。不幸的是,自主机忽略了此设置,现在通过此提交解决了这个问题,现在默认情况下,该提交将填充所有 Cookie HttpOnly
标志。
此更改从 v4.5.5+ 开始提供,现在在 MyGet 上可用。