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

Feature/VAPT issue- UUID format validation #14

Merged
merged 1 commit into from
Oct 15, 2021
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 @@ -10,6 +10,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.finarkein.aa.registry.RegistryService;
import io.finarkein.aa.validators.ArgsValidator;
import io.finarkein.api.aa.exception.Errors;
import io.finarkein.api.aa.exception.SystemException;
import io.finarkein.api.aa.notification.ConsentNotification;
Expand Down Expand Up @@ -83,9 +84,8 @@ public ResponseEntity<Mono<NotificationResponse>> consentResponseMono(@RequestBo
return ResponseEntity.badRequest().body(Mono.just(NotificationResponse.invalidResponse(consentNotification.getTxnid(), Timestamp.from(Instant.now()), e.getMessage())));
}

if (!NotificationValidator.isValidUUID(consentNotification.getTxnid())) {
return ResponseEntity.badRequest().body(Mono.just(NotificationResponse.invalidResponse(consentNotification.getTxnid(), Timestamp.from(Instant.now()), "Invalid TxnId")));
}
ArgsValidator.isValidUUID(consentNotification.getTxnid(), consentNotification.getTxnid(), "TxnId");

ConsentState consentState = consentService.getConsentStateByTxnId(consentNotification.getTxnid());

if (consentState == null)
Expand Down Expand Up @@ -129,10 +129,8 @@ public ResponseEntity<Mono<NotificationResponse>> fiNotification(@RequestBody FI
return ResponseEntity.badRequest().body(Mono.just(NotificationResponse.invalidResponse(fiNotification.getTxnid(),
Timestamp.from(Instant.now()), e.getMessage())));
}
if (!NotificationValidator.isValidUUID(fiNotification.getTxnid())) {
return ResponseEntity.badRequest().body(Mono.just(NotificationResponse.invalidResponse(fiNotification.getTxnid(),
Timestamp.from(Instant.now()), "Invalid TxnId")));
}
ArgsValidator.isValidUUID(fiNotification.getTxnid(), fiNotification.getTxnid(), "TxnId");

Optional<FIRequestState> optionalFIRequestState = dataFlowService.getFIRequestStateByTxnId(fiNotification.getTxnid());
if (optionalFIRequestState.isPresent()) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package io.finarkein.fiul.validator;

import io.finarkein.aa.registry.models.EntityInfo;
import io.finarkein.aa.validators.ArgsValidator;
import io.finarkein.aa.validators.BasicResponseValidator;
import io.finarkein.api.aa.exception.Errors;
import io.finarkein.api.aa.notification.ConsentNotification;
Expand All @@ -23,15 +24,6 @@
public class NotificationValidator {

private static final String REQUIRED_NOTIFIER_TYPE = "AA";
private static final Pattern UUID_REGEX_PATTERN =
Pattern.compile("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$");

public static boolean isValidUUID(String str) {
if (str == null || str.isEmpty()) {
return false;
}
return UUID_REGEX_PATTERN.matcher(str).matches();
}

public static void validateConsentNotification(ConsentNotification consentNotification, ConsentState consentState,
EntityInfo entityInfo, boolean test, AaApiKeyBody aaApiKeyBody) {
Expand All @@ -48,8 +40,8 @@ public static void validateConsentNotification(ConsentNotification consentNotifi
if (!consentNotification.getNotifier().getType().equals(REQUIRED_NOTIFIER_TYPE)) {
throw Errors.InvalidRequest.with(consentNotification.getTxnid(), "Invalid Notifier type");
}
if (!isValidUUID(consentNotification.getConsentStatusNotification().getConsentId()))
throw Errors.InvalidRequest.with(consentNotification.getTxnid(), "Consent Id is invalid");
ArgsValidator.isValidUUID(consentNotification.getTxnid(), consentNotification.getConsentStatusNotification().getConsentId(),
"ConsentId");

if (!consentNotification.getConsentStatusNotification().getConsentHandle().equals(consentState.getConsentHandle()))
throw Errors.InvalidRequest.with(consentNotification.getTxnid(), "ConsentHandle Id is invalid");
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<version.spring-webflux>5.3.8</version.spring-webflux>
<version.maven-dependency-plugin>3.1.1</version.maven-dependency-plugin>
<version.logger>2.14.0</version.logger>
<version.aa-commons>0.4.0</version.aa-commons>
<version.aa-commons>0.4.1</version.aa-commons>

<version.maven-compiler>3.8.1</version.maven-compiler>
<version.plugin-deploy>3.0.0-M1</version.plugin-deploy>
Expand Down