Skip to content

Fix input validation to support both domain and GUID #1670

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

Merged
merged 1 commit into from
Aug 3, 2023
Merged
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
18 changes: 11 additions & 7 deletions src/views/tenant/administration/TenantLookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ import { CippContentCard } from 'src/components/layout'
import Skeleton from 'react-loading-skeleton'
import { domainsApi } from 'src/store/api/domains'

const isValidTenantInput = (value) => {
// Regular expression for validating GUID
const guidRegex = /^[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}$/
// Regular expression for validating domain
const domainRegex = /^([a-zA-Z0-9](-?[a-zA-Z0-9])*\.)+[a-zA-Z]{2,}$/

// Check if the input is a valid GUID or domain
return !(guidRegex.test(value) || domainRegex.test(value))
}

const GraphExplorer = () => {
let navigate = useNavigate()
const tenant = useSelector((state) => state.app.currentTenant)
Expand Down Expand Up @@ -57,12 +67,6 @@ const GraphExplorer = () => {
})
}
}, [execGraphRequest, tenant.defaultDomainName, query, tenantdomain])
const isValidDomain = (value) =>
/^(((?!-))(xn--|_{1,1})?[a-z0-9-]{0,61}[a-z0-9]{1,1}\.)*(xn--)?([a-z0-9][a-z0-9-]{0,60}|[a-z0-9-]{1,30}\.[a-z]{2,})$/i.test(
value,
)
? undefined
: value

return (
<CRow>
Expand All @@ -80,7 +84,7 @@ const GraphExplorer = () => {
render={({ handleSubmit, submitting, pristine }) => {
return (
<CForm onSubmit={handleSubmit}>
<Field name="domain" validate={isValidDomain}>
<Field name="domain" validate={isValidTenantInput}>
{({ input, meta }) => {
return (
<>
Expand Down