Skip to content

Commit 397e42f

Browse files
committed
check corr_id in correct format.
1 parent 04f1404 commit 397e42f

File tree

4 files changed

+57
-2
lines changed

4 files changed

+57
-2
lines changed

IdentityCore/src/broker_operation/request/browser_native_message_request/MSIDBrowserNativeMessageGetTokenRequest.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,13 @@ - (instancetype)initWithJSONDictionary:(NSDictionary *)json error:(NSError *__au
159159

160160
if (![requestJson msidAssertType:NSString.class ofKey:MSID_BROWSER_NATIVE_MESSAGE_CORRELATION_KEY required:NO error:error]) return nil;
161161
NSString *uuidString = requestJson[MSID_BROWSER_NATIVE_MESSAGE_CORRELATION_KEY];
162-
_correlationId = uuidString ? [[NSUUID alloc] initWithUUIDString:uuidString] : [NSUUID UUID];
162+
_correlationId = [[NSUUID alloc] initWithUUIDString:uuidString];
163+
if (!_correlationId)
164+
{
165+
_correlationId = [NSUUID UUID];
166+
MSID_LOG_WITH_CTX_PII(MSIDLogLevelWarning, nil, @"CorrelationID is invalid or not in UUID format: %@. Use new correlationId: %@", uuidString, _correlationId);
167+
}
168+
163169
_platformSequence = [requestJson msidStringObjectForKey:MSID_BROWSER_NATIVE_MESSAGE_PLATFORM_SEQUENCE_KEY];
164170

165171
id canShowUIValue = requestJson[MSID_BROWSER_NATIVE_MESSAGE_CAN_SHOW_UI_KEY];

IdentityCore/src/broker_operation/request/browser_native_message_request/MSIDBrowserNativeMessageSignOutRequest.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,12 @@ - (instancetype)initWithJSONDictionary:(NSDictionary *)json error:(NSError *__au
6262
// Parse correlationId from JSON - optional field
6363
if (![json msidAssertType:NSString.class ofKey:MSID_BROWSER_NATIVE_MESSAGE_CORRELATION_KEY required:NO error:error]) return nil;
6464
NSString *uuidString = [json msidStringObjectForKey:MSID_BROWSER_NATIVE_MESSAGE_CORRELATION_KEY];
65-
_correlationId = uuidString ? [[NSUUID alloc] initWithUUIDString:uuidString] : [NSUUID UUID];
65+
_correlationId = [[NSUUID alloc] initWithUUIDString:uuidString];
66+
if (!_correlationId)
67+
{
68+
_correlationId = [NSUUID UUID];
69+
MSID_LOG_WITH_CTX_PII(MSIDLogLevelWarning, nil, @"CorrelationID is invalid or not in UUID format: %@. Use new correlationId: %@", uuidString, _correlationId);
70+
}
6671

6772
return self;
6873
}

IdentityCore/tests/MSIDBrowserNativeMessageGetTokenRequestTests.m

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,30 @@ - (void)testInitWithJSONDictionary_whenJsonValidAndRequiredOnlyFieldsProvided_sh
126126
XCTAssertNotNil(request.correlationId.UUIDString);
127127
}
128128

129+
- (void)testInitWithJSONDictionary_whenCorrelationIdProvidedInWrongFormat_shouldGenerateCorrelationId
130+
{
131+
__auto_type json = @{
132+
@"sender": @"https://login.microsoft.com",
133+
@"request": @{
134+
@"clientId": @"29a788ca-7bcf-4732-b23c-c8d294347e5b",
135+
@"scope": @"user.read openid profile offline_access",
136+
@"redirectUri": @"https://login.microsoft.com",
137+
@"correlationId": @"abc",
138+
}
139+
};
140+
141+
NSError *error;
142+
__auto_type request = [[MSIDBrowserNativeMessageGetTokenRequest alloc] initWithJSONDictionary:json error:&error];
143+
144+
XCTAssertNil(error);
145+
XCTAssertNotNil(request);
146+
XCTAssertEqualObjects(@"29a788ca-7bcf-4732-b23c-c8d294347e5b", request.clientId);
147+
XCTAssertEqualObjects(@"user.read openid profile offline_access", request.scopes);
148+
XCTAssertEqualObjects(@"https://login.microsoft.com", request.redirectUri);
149+
XCTAssertTrue(request.canShowUI);
150+
XCTAssertNotNil(request.correlationId.UUIDString);
151+
}
152+
129153
- (void)testInitWithJSONDictionary_whenAuthorityInvalid_shouldFail
130154
{
131155
__auto_type json = @{

IdentityCore/tests/MSIDBrowserNativeMessageSignOutRequestTests.m

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,24 @@ - (void)testInitWithJSONDictionary_whenCorrelationIdNotProvided_shouldGenerateCo
113113
XCTAssertNotNil(request.correlationId.UUIDString);
114114
}
115115

116+
- (void)testInitWithJSONDictionary_whenCorrelationIdProvidedInWrongFormat_shouldGenerateCorrelationId
117+
{
118+
__auto_type json = @{
119+
@"method": @"SignOut",
120+
@"accountId": @"uid.utid",
121+
@"correlationId": @"abc",
122+
@"sender": @"https://localhost:8000"
123+
};
124+
125+
NSError *error;
126+
__auto_type request = [[MSIDBrowserNativeMessageSignOutRequest alloc] initWithJSONDictionary:json error:&error];
127+
128+
XCTAssertNil(error);
129+
XCTAssertNotNil(request);
130+
XCTAssertEqualObjects(@"https://localhost:8000", request.sender.absoluteString);
131+
XCTAssertEqualObjects(@"uid", request.accountId.uid);
132+
XCTAssertEqualObjects(@"utid", request.accountId.utid);
133+
XCTAssertNotNil(request.correlationId.UUIDString);
134+
}
135+
116136
@end

0 commit comments

Comments
 (0)