-
Notifications
You must be signed in to change notification settings - Fork 76
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
Add validation for threat intel source config #1393
Changes from 2 commits
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 |
---|---|---|
|
@@ -24,7 +24,19 @@ public class SourceConfigDtoValidator { | |
public List<String> validateSourceConfigDto(SATIFSourceConfigDto sourceConfigDto) { | ||
List<String> errorMsgs = new ArrayList<>(); | ||
|
||
if (sourceConfigDto.getIocTypes().isEmpty()) { | ||
if (sourceConfigDto.getName() == null || sourceConfigDto.getName().isEmpty()) { | ||
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. @jowg-amazon could we add length restrictions? The frontend uses this validation for names. 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. added validation for names based on how frontend currently validates the name |
||
errorMsgs.add("Name must not be empty"); | ||
} | ||
|
||
if (sourceConfigDto.getFormat() == null || sourceConfigDto.getFormat().isEmpty()) { | ||
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. We may need to add length validation for this as well. Unless this gets validated somewhere downstream, the config could be created via backend API with something like 300k characters; which could disrupt functionality. 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. Added length validation |
||
errorMsgs.add("Format must not be empty"); | ||
} | ||
|
||
if (sourceConfigDto.getSource() == null) { | ||
errorMsgs.add("Source must not be empty"); | ||
} | ||
|
||
if (sourceConfigDto.getIocTypes() == null || sourceConfigDto.getIocTypes().isEmpty()) { | ||
errorMsgs.add("Must specify at least one IOC type"); | ||
} else { | ||
for (String s: sourceConfigDto.getIocTypes()) { | ||
|
@@ -34,34 +46,41 @@ public List<String> validateSourceConfigDto(SATIFSourceConfigDto sourceConfigDto | |
} | ||
} | ||
|
||
switch (sourceConfigDto.getType()) { | ||
case IOC_UPLOAD: | ||
if (sourceConfigDto.isEnabled()) { | ||
errorMsgs.add("Job Scheduler cannot be enabled for IOC_UPLOAD type"); | ||
} | ||
if (sourceConfigDto.getSchedule() != null) { | ||
errorMsgs.add("Cannot pass in schedule for IOC_UPLOAD type"); | ||
} | ||
if (sourceConfigDto.getSource() != null && sourceConfigDto.getSource() instanceof IocUploadSource == false) { | ||
errorMsgs.add("Source must be IOC_UPLOAD type"); | ||
} | ||
break; | ||
case S3_CUSTOM: | ||
if (sourceConfigDto.getSchedule() == null) { | ||
errorMsgs.add("Must pass in schedule for S3_CUSTOM type"); | ||
} | ||
if (sourceConfigDto.getSource() != null && sourceConfigDto.getSource() instanceof S3Source == false) { | ||
errorMsgs.add("Source must be S3_CUSTOM type"); | ||
} | ||
break; | ||
case URL_DOWNLOAD: | ||
if (sourceConfigDto.getSchedule() == null) { | ||
errorMsgs.add("Must pass in schedule for URL_DOWNLOAD source type"); | ||
} | ||
if (sourceConfigDto.getSource() != null && sourceConfigDto.getSource() instanceof UrlDownloadSource == false) { | ||
errorMsgs.add("Source must be URL_DOWNLOAD source type"); | ||
} | ||
break; | ||
if (sourceConfigDto.getType() == null) { | ||
errorMsgs.add("Type must not be empty"); | ||
} else { | ||
switch (sourceConfigDto.getType()) { | ||
case IOC_UPLOAD: | ||
if (sourceConfigDto.isEnabled()) { | ||
errorMsgs.add("Job Scheduler cannot be enabled for IOC_UPLOAD type"); | ||
} | ||
if (sourceConfigDto.getSchedule() != null) { | ||
errorMsgs.add("Cannot pass in schedule for IOC_UPLOAD type"); | ||
} | ||
if (sourceConfigDto.getSource() != null && sourceConfigDto.getSource() instanceof IocUploadSource == false) { | ||
errorMsgs.add("Source must be IOC_UPLOAD type"); | ||
} | ||
if (sourceConfigDto.getSource() instanceof IocUploadSource && ((IocUploadSource) sourceConfigDto.getSource()).getIocs() == null) { | ||
errorMsgs.add("Ioc list must include at least one ioc"); | ||
} | ||
break; | ||
case S3_CUSTOM: | ||
if (sourceConfigDto.getSchedule() == null) { | ||
errorMsgs.add("Must pass in schedule for S3_CUSTOM type"); | ||
} | ||
if (sourceConfigDto.getSource() != null && sourceConfigDto.getSource() instanceof S3Source == false) { | ||
errorMsgs.add("Source must be S3_CUSTOM type"); | ||
} | ||
break; | ||
case URL_DOWNLOAD: | ||
if (sourceConfigDto.getSchedule() == null) { | ||
errorMsgs.add("Must pass in schedule for URL_DOWNLOAD source type"); | ||
} | ||
if (sourceConfigDto.getSource() != null && sourceConfigDto.getSource() instanceof UrlDownloadSource == false) { | ||
errorMsgs.add("Source must be URL_DOWNLOAD source type"); | ||
} | ||
break; | ||
} | ||
} | ||
return errorMsgs; | ||
} | ||
|
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.
As a follow-up item, let's add validation for the refresh frequency.