【问题标题】:Add httpOnly flag to ss-id/ss-pid servicestack cookies将 httpOnly 标志添加到 ss-id/ss-pid 服务堆栈 cookie
【发布时间】:2017-01-09 12:29:44
【问题描述】:

我正在使用服务堆栈开发自托管 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:

设置 Cookie:ss-id=dT8Yy6ejhgfjhgfkVvcxcxCNtngYRS4;path=/

Set-Cookie:ss-pid=p4lsgo18JhYF4CTcxkhgkhgffRZob;path=/;expires=Fri, 09 Jan 2037 12:17:03 GMT

出于安全目的,我需要配置 ServiceStack 以将 ;httpOnly 标志添加到这些 cookie 中,但我不知道该怎么做。

各位,有人知道怎么做吗?任何想法都非常受欢迎。

提前感谢您的帮助:)

【问题讨论】:

    标签: rest servicestack httponly cookie-httponly


    【解决方案1】:

    您可以使用Config.AllowNonHttpOnlyCookies 控制是否在Cookie 上设置HttpOnly 标志,默认情况下为false,因此将始终设置HttpOnly 标志。不幸的是,自主机忽略了此设置,现在使用 this commit 解决了这个问题,现在默认情况下将为所有 Cookie 填充 HttpOnly 标志。

    此更改从 v4.5.5+ 开始可用,现在为 available on MyGet

    【讨论】:

    • 感谢回复
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-29
    • 2017-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-12
    • 2011-05-18
    相关资源
    最近更新 更多