Kan*_*yan 5 amazon-web-services graphql aws-appsync
根据合规性,我们需要删除生产环境中 AppSync 端点的内省查询。使用 AppSync 禁用自省查询的最佳方法是什么?
我没有看到 AppSync 的任何设置。
小智 9
我使用 AWS WAF 并制定了一条规则,该规则阻止任何包含 string 的查询__schema,然后将其与我的 AppSync 端点关联——该端点使用 OpenID 进行身份验证(请参阅此页面: https: //docs.aws.amazon.com/appsync/latest /devguide/WAF-Integration.html)
如果您只想复制并粘贴到控制台,则规则:
{
"Name": "BodyRule",
"Priority": 5,
"Action": {
"Block": {}
},
"VisibilityConfig": {
"SampledRequestsEnabled": true,
"CloudWatchMetricsEnabled": true,
"MetricName": "BodyRule"
},
"Statement": {
"ByteMatchStatement": {
"FieldToMatch": {
"Body": {}
},
"PositionalConstraint": "CONTAINS",
"SearchString": "__schema",
"TextTransformations": [
{
"Type": "LOWERCASE",
"Priority": 0
}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
以及 CloudFormation 定义:
AppSyncIntrospectionWebACL:
Type: AWS::WAFv2::WebACL
Properties:
Name: BlockIntrospectionWebACL
DefaultAction:
Allow: {}
Description: Block GraphQL introspection queries
Scope: REGIONAL
VisibilityConfig:
SampledRequestsEnabled: true
CloudWatchMetricsEnabled: true
MetricName: BlockIntrospectionMetric
Rules:
- Name: BlockIntrospectionQueries
Priority: 0
Action:
Block: {}
VisibilityConfig:
SampledRequestsEnabled: true
CloudWatchMetricsEnabled: true
MetricName: BlockedIntrospection
Statement:
ByteMatchStatement:
FieldToMatch:
Body: {}
PositionalConstraint: CONTAINS
SearchString: __schema
TextTransformations:
- Type: LOWERCASE
Priority: 0
AppSyncIntrospectionWebACLAssociation:
Type: AWS::WAFv2::WebACLAssociation
Properties:
ResourceArn: !GetAtt AppSyncAPI.Arn
WebACLArn: !GetAtt AppSyncIntrospectionWebACL.Arn
Run Code Online (Sandbox Code Playgroud)
目前无法直接从 AppSync 禁用内省查询。您可以在其前面放置一个 API Gateway api,并拦截内省查询调用。不过,GraphQL 端点本质上是自记录的,因此禁用内省查询将使 API 不是符合 GraphQL 的端点。
您能否分享需要禁用内省查询的用例/合规性标准?试图通过模糊[类型和字段]来提高[API端点]的安全性似乎是一种代码味道和入侵的秘诀。拥有强大的细粒度(即每个字段)授权是防止任何人访问他们不应该知道的数据的唯一安全方法。
| 归档时间: |
|
| 查看次数: |
923 次 |
| 最近记录: |