代码改变世界

SharePoint 2019 Form based Authentication (FBA) SameSite=None 的问题总结

2022-09-07 14:45  四毛的家  阅读(158)  评论(0编辑  收藏  举报

场景:SharePoint 2019打完补丁后,发现原来正常使用的通过FBA登陆的站点,在chrome里无法登陆了。输入账号和密码点击登陆,页面刷新后并未跳转到首页,还是停留在登陆页。

但在IE和FireFox中可以正常登陆。

原因:此问题就是Chrome的SameSite导致的。

解决办法:

1.如果你是早期的Chrome(版本大于80),可以通过修改浏览器功能来启用。

打开chrome,输入 chrome://flags ,找到Cookie without SameSite must be secure,将其设为Disabled,然后重启浏览器即可。此方法只解决当前电脑的问题。

2.我的Chrome版本是105.xx,已经无此配置项了。只能修改web.config了。

对于Chrome来说,此配置项是为空跨域攻击,如果设置SameSite为None,那么就必须设置secure,也就是使用https。

如果你使用了https,则需要

<httpCookies sameSite="None" requireSSL="true"/>
<sessionState cookieSameSite="None" />
<authentication mode="Forms">
<forms loginUrl="/_forms/default.aspx" cookieSameSite="None" requireSSL="true" />
</authentication>

 

由于我的站点并未使用https,所以通过设置SameSite为Lax解决。

<system.web>
    <httpHandlers />
    <customErrors mode="On" />
    <httpRuntime maxRequestLength="256000" maxUrlLength="401" executionTimeout="1500" requestValidationMode="2.0" requestPathInvalidCharacters="\,*,?,&lt;,&gt;" />
    <httpCookies sameSite="Lax" requireSSL="false"/>
    <sessionState cookieSameSite="Lax" />
    <authentication mode="Forms">
        <forms loginUrl="/_forms/default.aspx" cookieSameSite="Lax" requireSSL="false" />
      </authentication>

设置前后Cookie的对比

设置前Cookie
FedAuth=77u/PD94bWwgxxxxxxxxxxxsHR0cDovL2VpcC5jYXJzZ2VuLmNvbTo4ODg4LzwvU1A+; path=/; SameSite=None; HttpOnly

设置后Cookie
FedAuth=77u/PDxxxxxxxxxxxxxxxxssxxxxxxxxxxxxxqQmdlMVBpQkpjNGkvcUl2Y2c9PSD4=; path=/; SameSite=None; HttpOnly; SameSite=Lax

 

3.官方文档 建议安装什么补丁,刚好我的环境没有。我尝试安装,结果失败。可能是我装了更新的补丁的原因。

https://techcommunity.microsoft.com/t5/microsoft-sharepoint-blog/effect-on-sharepoint-sites-that-use-adfs-saml-and-forms-based/ba-p/1253873

https://docs.microsoft.com/zh-cn/microsoft-365/troubleshoot/miscellaneous/chrome-behavior-affects-applications