Skip to content

Commit

Permalink
Ingore regex pattern matching for inbound OAuth apps
Browse files Browse the repository at this point in the history
  • Loading branch information
sahandilshan committed Nov 14, 2024
1 parent d2b06cb commit 6d26ecf
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1962,7 +1962,7 @@ export const InboundOIDCForm: FunctionComponent<InboundOIDCFormPropsInterface> =
return false;
}
if (URLUtils.isURLValid(value)) {
if (URLUtils.isHttpUrl(value) || URLUtils.isHttpsUrl(value)) {
if (URLUtils.isHttpUrl(value, false) || URLUtils.isHttpsUrl(value, false)) {
setCallbackURLsErrorLabel(null);

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,14 +543,8 @@ export const OauthProtocolSettingsWizardForm: FunctionComponent<OAuthProtocolSet
}

if (URLUtils.isURLValid(value)) {
if (FormValidation.url(value, {
domain: {
allowUnicode: true,
minDomainSegments: 1,
tlds: false
},
scheme: [ "http", "https" ]
})) {
if (URLUtils.isHttpUrl(value, false) ||
URLUtils.isHttpsUrl(value, false)) {
setCallbackURLsErrorLabel(null);

return true;
Expand Down
30 changes: 16 additions & 14 deletions modules/core/src/utils/url-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,33 +34,35 @@ export class URLUtils {
private constructor() { }

/**
* Checks if the passed in url is a valid Http URL.
* Checks if the passed-in URL is a valid HTTP URL.
* If `forceRegexValidation` is false, it only checks if the URL starts with "http://".
*
* @param url - URL to evaluate.
*
* @returns True if the url is a http url.
* @param forceRegexValidation - Flag to use regex pattern validation (default: true).
* @returns True if the URL is a valid HTTP URL.
*/
public static isHttpUrl(url: string): boolean {
if (url.startsWith("http://")) {
return !!url.trim().match(PatternConstants.HTTP_URL_REGEX_PATTERN);
public static isHttpUrl(url: string, forceRegexValidation: boolean = true): boolean {
if (!forceRegexValidation) {
return url.trim().startsWith("http://");
}

return false;
return !!url.trim().match(PatternConstants.HTTP_URL_REGEX_PATTERN);
}

/**
* Checks if the passed in url is a valid Https URL.
* Checks if the passed-in URL is a valid HTTPS URL.
* If `forceRegexValidation` is false, it only checks if the URL starts with "https://".
*
* @param url - URL to evaluate.
*
* @returns True if the url is a https url.
* @param forceRegexValidation - Flag to use regex pattern validation (default: true).
* @returns True if the URL is a valid HTTPS URL.
*/
public static isHttpsUrl(url: string): boolean {
if (url.startsWith("https://")) {
return !!url.trim().match(PatternConstants.HTTPS_URL_REGEX_PATTERN);
public static isHttpsUrl(url: string, forceRegexValidation: boolean = true): boolean {
if (!forceRegexValidation) {
return url.trim().startsWith("https://");
}

return false;
return !!url.trim().match(PatternConstants.HTTPS_URL_REGEX_PATTERN);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions modules/react-components/src/components/input/url-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,8 @@ export const URLInput: FunctionComponent<URLInputPropsInterface> = (
const resolveCORSStatusLabel = (url: string) => {
const { origin, href } = URLUtils.urlComponents(url);
const positive: boolean = isOriginIsKnownAndAllowed(url);
const isValid: boolean = (URLUtils.isURLValid(url, true) && (URLUtils.isHttpUrl(url) ||
URLUtils.isHttpsUrl(url)));
const isValid: boolean = (URLUtils.isURLValid(url, true) && (URLUtils.isHttpUrl(url, false) ||
URLUtils.isHttpsUrl(url, false)));

/**
* TODO : React Components should not depend on the product
Expand Down

0 comments on commit 6d26ecf

Please sign in to comment.