- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们正在使用 Ping Federate 来保护两个 Web 服务器(两个都是 IIS,并且都使用 IIS 集成工具包或 Ping 的 opentoken 模块进行保护)。一台服务器托管 WEB API 应用程序,另一台服务器托管网页。 Web API 应用程序启用了 CORS。
该网页使用 json 数据向 API 服务器发出 Ajax post 请求。这会导致浏览器启动预检选项请求。在 API 服务器上,Ping 模块拦截了这个不包含凭据的请求(规范说预检选项请求不应该包含凭据)并在 Web API 代码可以处理它之前返回 302 重定向,而它应该返回 200 .
我目前唯一的猜测是制作一个处理选项请求的自定义模块,并将其安装在 opentoken 模块之前。还有其他可能/更好的解决方案吗?
最佳答案
我没有等待 PING,而是在他们的 .NET 集成工具包/代理之上放置了一个 IAuthorizationFilter。像这样的自定义过滤器的好处是您可以更好地控制 API 端点的安全要求。
在编写过滤器时,我使用了以下引用资料:
https://msdn.microsoft.com/en-us/magazine/dn781361.aspx
使用开放 token ;使用 PF.SAML.Result;使用系统;使用 System.Collections.Generic;使用系统配置;使用 System.Linq;使用 System.Net.Http;使用 System.Net.Http.Headers;使用 System.Security.Claims;使用系统文本;使用系统线程;使用 System.Threading.Tasks;使用 System.Web.Http.Filters;
命名空间 PF.SAML.过滤器{ 公共(public)类 PingAuthenticationAttribute :IAuthenticationFilter { public bool AllowMultiple { get { 返回 false; }
// http://www.asp.net/web-api/overview/security/authentication-filters
// https://msdn.microsoft.com/en-us/magazine/dn781361.aspx
public async Task AuthenticateAsync( HttpAuthenticationContext context, CancellationToken cancellationToken )
{
await Task.Run( () => {
/*
* Look for credentials in the request.
* If there are no credentials, do nothing and return (no-op).
* If there are credentials but the filter does not recognize the authentication scheme, do nothing and return (no-op). Another filter in the pipeline might understand the scheme.
* If there are credentials that the filter understands, try to authenticate them.
* If the credentials are bad, return 401 by setting context.ErrorResult.
* If the credentials are valid, create an IPrincipal and set context.Principal.
*/
var opentoken = context.Request.Headers.GetCookies()
.SelectMany( c => c.Cookies )
.Where( c => c.Name == "opentoken" )
.FirstOrDefault();
if( opentoken == null ) return;
var userInfo = getOpenToken( opentoken.Value );
if( userInfo == null ) {
context.ErrorResult = new AuthenticationFailureResult( "Invalid Token", context.Request );
return;
}
var claims = new List<Claim>();
foreach( var item in userInfo ) {
foreach( var value in userInfo[item.Key] ) {
claims.Add( new Claim( item.Key, value ) );
}
}
var id = new ClaimsIdentity( claims, "opentoken" );
var principle = new ClaimsPrincipal( new[] { id } );
context.Principal = principle;
} );
}
public async Task ChallengeAsync( HttpAuthenticationChallengeContext context, CancellationToken cancellationToken )
{
await Task.Run( () => {
var challenge = new AuthenticationHeaderValue( "SAML" );
context.Result = new AddChallengeOnUnauthorizedResult( challenge, context.Result );
} );
}
private MultiStringDictionary getOpenToken( string token )
{
MultiStringDictionary attributes = null;
Configuration.Agent agentConfig = (Configuration.Agent) ConfigurationManager.GetSection( "pfConfigurationGroup/agentConfiguration" );
AgentConfiguration config = new AgentConfiguration
{
CookieDomain = agentConfig.CookieDomain,
CookiePath = agentConfig.CookiePath,
NotBeforeTolerance = agentConfig.NotBeforeTolerance,
ObfuscatePassword = agentConfig.ObfuscatePassword,
RenewUntilLifetime = agentConfig.RenewUntilLifetime,
SecureCookie = agentConfig.SecureCookie,
SessionCookie = agentConfig.SessionCookie,
TokenLifetime = agentConfig.TokenLifetime,
TokenName = agentConfig.TokenName,
UseCookie = agentConfig.UseCookie,
UseSunJCE = agentConfig.UseSunJCE,
UseVerboseErrorMessages = agentConfig.UseVerboseErrorMessages
};
var str = ( config.ObfuscatePassword
? Encoding.UTF8.GetString( Obfuscator.Deobfuscate( agentConfig.Password ) )
: Encoding.ASCII.GetString( Convert.FromBase64String( agentConfig.Password ) ) );
config.SetPassword( str, Token.CipherSuite.AES_128_CBC );
// TODO: Check for token expiration
Agent agent = new Agent( config );
attributes = agent.ReadTokenMultiStringDictionary( token );
return attributes;
}
}
关于javascript - Pingfederate opentoken 模块 CORS 请求返回 302 而不是 200,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36658253/
我尝试访问此 API click here for more info POST https://api.line.me/v2/oauth/accessToken 但总是得到错误: XMLHttpRe
我在掌握 CORS 概念时遇到问题... 我认为同源策略保护应用程序不会对“不受信任的域”进行 ajax 调用。所以, mydomain.com 向 发出 ajax 调用somedomain.com
一个技术性很强的问题,可能只有了解浏览器内部结构的人才能回答...... 浏览器缓存 CORS 预检响应的准确程度如何(假设在对 OPTIONS 预检请求的响应中返回了 Access-Control-
我一直在阅读 CORS以及它是如何工作的,但我发现很多事情令人困惑。例如,有很多关于事情的细节,比如 User Joe is using browser BrowserX to get data fr
在 OWASP site 上看到这个矛盾,我感到很困惑。 CORS 备忘单: 使用 Access-Control-Allow-Credentials: true 响应 header 时要特别小心。将允
我们无法在飞行前恢复使用 cors:任何帮助都非常感谢 ==========错误========================== About to connect() to localhost p
跨域请求字体文件时,您必须确保允许请求域使用 CORS header 访问字体文件: 访问控制允许来源 访问控制允许凭据 然而,这在请求图像时不是必需的,无论是对于 img元素或 background
CORS 规范没有说明服务器应如何响应无效的 CORS 请求。例如,如果请求 Origin 无效,则 CORS spec states :“终止这组步骤。请求超出了本规范的范围。”其他错误情况也有类似
我在理解同源策略和“解决”它的不同方法时遇到了一些麻烦。 很明显,同源策略是作为一种安全措施而存在的,因此来自服务器/域的一个脚本无法访问来自另一个服务器/域的数据。 也很明显,有时能够打破此规则很有
我正在尝试使用 cloudformation 在 API Gateway 中部署 API。这些方法需要启用 CORS,我遵循此处的模板 Enable CORS for API Gateway in C
我正在构建一个使用 CORS 的 REST 应用程序。每个 REST 调用都是不同的,我发现获取预检 OPTIONS 调用会产生很大的开销。有没有办法缓存并应用预检选项结果,以便对同一域的任何后续调用
我正在将我的 WebApi 升级到 MVC6。 在 WebApi 中,我可以拦截每个 HTTP 请求,如果是预检,我可以用浏览器可以接受的 header 进行响应。 我正在尝试找出如何在 MVC6 W
假设一个 CORS 预检请求进来了,但它为一个或多个 Access-Control-Request-* 指定了一个不受支持的值。标题。服务器应该如何将其传达回浏览器? 一些例子: 浏览器发送带有 Ac
问题中的一切。 附加信息: 使用 Win 10,GraphDB 免费,9.1.1 • RDF4J 3.0.1 • Connectors 12.0.2 我在控制台 => 设置中添加了 graphdb.w
我正在尝试通过 jQuery 调用 Sonar 网络服务之一。由于调用是跨域进行的,因此调用在 Chrome 上失败并出现以下错误: 请求的资源上不存在“Access-Control-Allow-Or
我想使用 NestJs api,但我在每个 fetch 中都收到相同的错误消息: Access to fetch at 'http://localhost:3000/articles' from or
我不确定这是否属于这里,但我在开发我的 svelte 应用程序时遇到了问题。 在开发过程中,它目前在独立服务器上运行(遵循使用 rollup 和 sirv 的指南)并针对不同端口上的后端 API。 稍
如果在服务器上正确设置 CORS 以仅允许某些来源访问服务器,这是否足以防止 XSRF 攻击? 最佳答案 更具体地说,很容易错误地认为如果 evil.com 由于 CORS 无法向 good.com
我在 Istio 入口上启用 CORS 时遇到问题。正如 Istio Ingress 文档所述,“ingresskubernetes.io”注释将被忽略。是否可以在 Istio 入口上启用 CORS?
我在 Istio 入口上启用 CORS 时遇到问题。正如 Istio Ingress 文档所述,“ingresskubernetes.io”注释将被忽略。是否可以在 Istio 入口上启用 CORS?
我是一名优秀的程序员,十分优秀!