-
Notifications
You must be signed in to change notification settings - Fork 249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: do not sign requests that have optional auth #3671
Changes from all commits
0f6d4a9
c9634fb
2aeded7
e3399bb
a3294c0
8755015
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -31,16 +31,13 @@ class WithSigV4 extends HttpRequestInterceptor { | |||||||||||||
|
||||||||||||||
@override | ||||||||||||||
Future<AWSBaseHttpRequest> intercept(AWSBaseHttpRequest request) async { | ||||||||||||||
// Try to retrieve credentials. If it fails, continue without authentication | ||||||||||||||
// for optional auth requests only. | ||||||||||||||
try { | ||||||||||||||
await credentialsProvider.retrieve(); | ||||||||||||||
} on Exception { | ||||||||||||||
if (isOptional) { | ||||||||||||||
return request; | ||||||||||||||
} | ||||||||||||||
rethrow; | ||||||||||||||
} | ||||||||||||||
// Do not attempt to sign requests where auth is optional. | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Wondering if we should put a check in place in smithy_codegen which throws if we encounter an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For example, we could add this to /// Asserts that the `@optionalAuth` trait is only present in Cognito and SSO
/// services, where we know the behavior is that signing is strictly unnecessary.
///
/// Any other services which onboard this trait must be validated for the same behavior
/// before we can generate for them.
class _AssertOptionalAuthVisitor extends CategoryShapeVisitor<Shape> {
const _AssertOptionalAuthVisitor();
/// The list of known services where `@optionalAuth` is present and its behavior has
/// been verified.
static const _knownServices = [
'com.amazonaws.cognitoidentity',
'com.amazonaws.cognitoidentityprovider',
'com.amazonaws.sso',
'com.amazonaws.ssooidc',
];
@override
EnumShape enumShape(EnumShape shape, [Shape? parent]) => shape;
@override
ListShape listShape(ListShape shape, [Shape? parent]) => shape;
@override
MapShape mapShape(MapShape shape, [Shape? parent]) => shape;
@override
MemberShape memberShape(MemberShape shape, [Shape? parent]) => shape;
@override
OperationShape operationShape(OperationShape shape, [Shape? parent]) {
if (shape.hasTrait<OptionalAuthTrait>() &&
!_knownServices.contains(shape.shapeId.namespace)) {
throw StateError(
'Shape has @optionalAuth but it is not from a validated service: '
'${shape.shapeId}',
);
}
return shape;
}
@override
ResourceShape resourceShape(ResourceShape shape, [Shape? parent]) => shape;
@override
ServiceShape serviceShape(ServiceShape shape, [Shape? parent]) => shape;
@override
SetShape setShape(SetShape shape, [Shape? parent]) => shape;
@override
SimpleShape simpleShape(SimpleShape shape, [Shape? parent]) => shape;
@override
StructureShape structureShape(StructureShape shape, [Shape? parent]) => shape;
@override
UnionShape unionShape(UnionShape shape, [Shape? parent]) => shape;
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated the comment. As for the check, I think we have to be able to assume traits mean the same thing across services. In this case "optionalAuth" means that signing the request is not required, has no impact on the behavior. |
||||||||||||||
// | ||||||||||||||
// This is only set in Cognito and SSO services where the trait indicates | ||||||||||||||
// that signing is strictly unnecessary and that signing the request does | ||||||||||||||
// not impact the behavior of the APIs. | ||||||||||||||
if (isOptional) return request; | ||||||||||||||
|
||||||||||||||
final signer = AWSSigV4Signer( | ||||||||||||||
credentialsProvider: credentialsProvider, | ||||||||||||||
algorithm: algorithm, | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this throws if it can't get the user?