Skip to content
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 crash when we tried parsing a OATH URL without a path #168

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ - (instancetype)initWithURL:(NSURL *)url skipValidation:(YKFOATHCredentialTempla
*error = [YKFOATHCredentialTemplateError ykfErrorWithCode:YKFOATHCredentialTemplateErrorCodeLabel];
return nil;
}

if (urlComponents.path.length < 1) {
*error = [YKFOATHCredentialTemplateError ykfErrorWithCode:YKFOATHCredentialTemplateErrorCodeLabel];
return nil;
}

NSString *name = [urlComponents.path substringFromIndex:1];
NSString *issuer = [urlComponents queryParameterValueForName:YKFOATHCredentialURLParameterIssuer];
if ([name containsString:@":"]) {
Expand Down
8 changes: 8 additions & 0 deletions YubiKit/YubiKitTests/Tests/YKFOATHCredentialTemplateTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,14 @@ - (void)test_WhenValidatorIsRequestedToValidateWithoutSecret_SecretIsNotValidate
XCTAssertNil(error);
}

- (void)test_WhenNoPathIsSet_ErrorIsReturned {
NSError *error = nil;
NSString *url = @"otpauth://totp?secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ&issuer=ACME&algorithm=SHA1&digits=6&period=30";
YKFOATHCredentialTemplate *credential = [[YKFOATHCredentialTemplate alloc] initWithURL:[NSURL URLWithString:url] skipValidation:YKFOATHCredentialTemplateValidationLabel error:&error];
XCTAssertNotNil(error);
XCTAssertNil(credential);
}

#pragma mark - Large Key Tests

- (void)test_WhenValidatorReceivesInvalidCredentialKey_ErrorIsReturnedBack {
Expand Down
Loading