我们遇到了麻烦的跨站点Scritpting在一个应用程序,我们正在工作。
我们的应用程序是用角2编码的,我们把它作为静态网站托管在AWS s3中。此应用程序连接到一个后端,该后端位于API网关后面。
我们的前端无法进行任何api调用,因为跨站点Scritping。
http://docs.aws.amazon.com/waf/latest/developerguide/web-acl-xss-conditions.html#web-acl-xss-conditions-values
这件我试过了,但对我来说行不通。本地前端和后端可以进行通信,它们都是独立工作的。
有没有一种好的、不太先进的方法来处理这个问题?
提前感谢!
发布于 2017-05-30 16:25:06
您还可以使用AWS控制台轻松地激活CORS。请参阅本有关启用CORS的更多详细信息指南。
发布于 2017-05-29 11:51:05
您激活了API网关上的CORS吗?我有完全相同类型的应用程序,在API网关中,您需要激活CORS:在链接到lambda的资源上(在POST中,如果我记得很清楚,这是强制性的)您添加了选项方法。下面是python中关于如何以编程方式激活CORS的示例:
gateway = boto3.client('apigateway', region_name=self.conf.region)
gateway.put_method(
restApiId=apiId,
resourceId=resourceId,
httpMethod="OPTIONS",
authorizationType="NONE"
)
gateway.put_method_response(
restApiId=apiId,
resourceId=resourceId,
httpMethod="OPTIONS",
statusCode="200",
responseParameters={
'method.response.header.Access-Control-Allow-Headers': True,
'method.response.header.Access-Control-Allow-Origin': True,
'method.response.header.Access-Control-Allow-Methods': True
},
responseModels={
'application/json': 'Empty'
}
)
gateway.put_integration(
restApiId=api['id'],
resourceId=apiResource['id'],
httpMethod="OPTIONS",
type="MOCK",
requestTemplates={
'application/json': '{"statusCode": 200}'
}
)
gateway.put_integration_response(
restApiId=api['id'],
resourceId=apiResource['id'],
httpMethod="OPTIONS",
statusCode="200",
selectionPattern=".*",
responseParameters={
"method.response.header.Access-Control-Allow-Headers": "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'",
"method.response.header.Access-Control-Allow-Methods": "'*'",
"method.response.header.Access-Control-Allow-Origin": "'*'"
},
responseTemplates={
'application/json': ''
}
)
gateway.put_method_response(
restApiId=apiId,
resourceId=resourceId,
httpMethod="POST",
statusCode=200,
responseParameters={'method.response.header.Access-Control-Allow-Origin': True},
responseModels={'application/json': 'Empty'}
https://stackoverflow.com/questions/44238930
复制相似问题