Skip to content

Commit

Permalink
[frontend] RegExs updated to validate more completely the Bulk add of…
Browse files Browse the repository at this point in the history
… Hash values (#4352)

Co-authored-by: daimyo007 <[email protected]>
  • Loading branch information
ParamConstructor and daimyo007 authored Sep 12, 2024
1 parent bab94af commit 59829af
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -527,31 +527,31 @@ const StixCyberObservableCreation = ({
initialValues['hashes_SHA-256'] = '';
initialValues['hashes_SHA-512'] = '';
// Dynamically include validation options for File Hash Options.
const md5Regex = /^([a-f0-9]{32}\n*)+$/i;
const sha1Regex = /^([a-f0-9]{40}\n*)+$/i;
const sha256Regex = /^([a-f0-9]{64}\n*)+$/i;
const sha512Regex = /^([a-f0-9]{128}\n*)+$/i;
const md5Regex = /(^[a-fA-F0-9]{32})(?:\n[a-fA-F0-9]{32}){0,49}$/i;
const sha1Regex = /(^[a-fA-F0-9]{40})(?:\n[a-fA-F0-9]{40}){0,49}$/i;
const sha256Regex = /(^[a-fA-F0-9]{64})(?:\n[a-fA-F0-9]{64}){0,49}$/i;
const sha512Regex = /(^[a-fA-F0-9]{128})(?:\n[a-fA-F0-9]{128}){0,49}$/i;
extraFieldsToValidate = {
hashes_MD5: Yup
.string()
.string().matches(md5Regex, t_i18n('MD5 values can only include A-F and 0-9, 32 characters'))
.when(['hashes_SHA-1', 'hashes_SHA-256', 'hashes_SHA-512', 'name'], {
is: (a, b, c, d) => !a && !b && !c && !d,
then: () => Yup.string().matches(md5Regex, t_i18n('MD5 values can only include A-F and 0-9, 32 characters')).required(t_i18n('MD5, SHA-1, SHA-256, SHA-512, or name is required')),
}),
'hashes_SHA-1': Yup
.string()
.string().matches(sha1Regex, t_i18n('SHA-1 values can only include A-F and 0-9, 40 characters'))
.when(['hashes_MD5', 'hashes_SHA-256', 'hashes_SHA-512', 'name'], {
is: (a, b, c, d) => !a && !b && !c && !d,
then: () => Yup.string().matches(sha1Regex, t_i18n('SHA-1 values can only include A-F and 0-9, 40 characters')).required(t_i18n('MD5, SHA-1, SHA-256, SHA-512, or name is required')),
}),
'hashes_SHA-256': Yup
.string()
.string().matches(sha256Regex, t_i18n('SHA-256 values can only include A-F and 0-9, 64 characters'))
.when(['hashes_MD5', 'hashes_SHA-1', 'hashes_SHA-512', 'name'], {
is: (a, b, c, d) => !a && !b && !c && !d,
then: () => Yup.string().matches(sha256Regex, t_i18n('SHA-256 values can only include A-F and 0-9, 64 characters')).required(t_i18n('MD5, SHA-1, SHA-256, SHA-512, or name is required')),
}),
'hashes_SHA-512': Yup
.string()
.string().matches(sha512Regex, t_i18n('SHA-512 values can only include A-F and 0-9, 128 characters'))
.when(['hashes_MD5', 'hashes_SHA-1', 'hashes_SHA-256', 'name'], {
is: (a, b, c, d) => !a && !b && !c && !d,
then: () => Yup.string().matches(sha512Regex, t_i18n('SHA-512 values can only include A-F and 0-9, 128 characters')).required(t_i18n('MD5, SHA-1, SHA-256, SHA-512, or name is required')),
Expand Down

0 comments on commit 59829af

Please sign in to comment.