Skip to content

Commit 67c8889

Browse files
ivolivol
authored andcommitted
fix: gate getLastARC and strictly enforce config initialization
1 parent 41da521 commit 67c8889

2 files changed

Lines changed: 32 additions & 17 deletions

File tree

android/src/main/java/io/approov/reactnative/ApproovService.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -673,19 +673,22 @@ public void initialize(String config, String comment, Promise promise) {
673673
boolean allowEnableAfterEmptyInitialization = isInitialized && (initialConfig != null)
674674
&& initialConfig.isEmpty() && !config.isEmpty();
675675

676-
if (isInitialized && !allowReinitialize && !allowEnableAfterEmptyInitialization) {
676+
if (isInitialized && !allowEnableAfterEmptyInitialization) {
677677
// if the SDK is previously initialized then the config should be the same
678678
if (!config.equals(initialConfig)) {
679679
log(LOG_ERROR, TAG, "attempt to reinitialize with a different config");
680680
promise.reject("initialize", "attempt to reinitialize with a different config",
681681
getErrorUserInfo(false));
682-
} else {
682+
return;
683+
}
684+
if (!allowReinitialize) {
683685
promise.resolve(null);
686+
return;
684687
}
685-
} else {
686-
// initialize the Approov SDK and notify any pin change listeners since pins may
687-
// now
688-
// be available
688+
}
689+
690+
// initialize the Approov SDK and notify any pin change listeners since pins may
691+
// now be available
689692
try {
690693
if (!config.isEmpty()) {
691694
Approov.initialize(applicationContext, config, "auto", effectiveComment);
@@ -712,7 +715,6 @@ public void initialize(String config, String comment, Promise promise) {
712715
log(LOG_ERROR, TAG, "initialization failed with IllegalState: " + e.getMessage());
713716
promise.reject("initialize", "initialize IllegalState: " + e.getMessage(), getErrorUserInfo(false));
714717
}
715-
}
716718
}
717719

718720
/**
@@ -768,6 +770,11 @@ public void isApproovEnabled(Promise promise) {
768770
@ReactMethod
769771
public void getLastARC(Promise promise) {
770772
log(LOG_INFO, TAG, "ApproovService: getLastARC");
773+
if (!isInitialized || !isApproovEnabled()) {
774+
promise.resolve("");
775+
return;
776+
}
777+
771778
// Get the dynamic pins from Approov
772779
Map<String, List<String>> approovPins = Approov.getPins("public-key-sha256");
773780
if (approovPins == null || approovPins.isEmpty()) {

ios/ApproovService.m

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,8 @@ - (instancetype)init {
345345
BOOL allowEnableAfterEmptyInitialization =
346346
isInitialized && initialConfigString != nil &&
347347
[initialConfigString length] == 0 && [config length] != 0;
348-
if (isInitialized && !allowReinitialize && !allowEnableAfterEmptyInitialization) {
349-
// if the SDK is previously initialized then check the config string is
350-
// the same
348+
if (isInitialized && !allowEnableAfterEmptyInitialization) {
349+
// if the SDK is previously initialized then check the config string is the same
351350
if (![initialConfigString isEqualToString:config]) {
352351
NSError *error =
353352
[[NSError alloc] initWithDomain:@"io.approov.reactnative"
@@ -356,14 +355,19 @@ - (instancetype)init {
356355
reject(@"initialize",
357356
@"attempt to reinitialize Approov SDK with a different config",
358357
error);
359-
} else {
358+
return;
359+
}
360+
361+
if (!allowReinitialize) {
360362
resolve(nil);
363+
return;
361364
}
362-
} else {
363-
// initialize the Approov SDK
364-
NSError *initializationError = nil;
365-
BOOL initializationResult = YES;
366-
if ([config length] != 0) {
365+
}
366+
367+
// initialize the Approov SDK
368+
NSError *initializationError = nil;
369+
BOOL initializationResult = YES;
370+
if ([config length] != 0) {
367371
initializationResult = [Approov initialize:config
368372
updateConfig:@"auto"
369373
comment:comment
@@ -417,7 +421,6 @@ - (instancetype)init {
417421
}
418422
resolve(nil);
419423
}
420-
}
421424
}
422425
}
423426

@@ -444,6 +447,11 @@ + (id)networkRequestLock {
444447
*/
445448
RCT_EXPORT_METHOD(getLastARC : (RCTPromiseResolveBlock)
446449
resolve rejecter : (RCTPromiseRejectBlock)reject) {
450+
if (!isInitialized || !ApproovIsEnabled()) {
451+
resolve(@"");
452+
return;
453+
}
454+
447455
// Get the dynamic pins from Approov
448456
NSDictionary<NSString *, NSArray<NSString *> *> *approovPins =
449457
[Approov getPins:@"public-key-sha256"];

0 commit comments

Comments
 (0)