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

Ingore regex pattern matching for inbound OAuth apps #7123

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions .changeset/cold-doors-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@wso2is/admin.applications.v1": patch
"@wso2is/react-components": patch
"@wso2is/core": patch
---

Ingore regex pattern matching for inbound OAuth apps
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 @@ -21,7 +21,6 @@ import { TestableComponentInterface } from "@wso2is/core/models";
import { URLUtils } from "@wso2is/core/utils";
import { Field, FormValue, Forms } from "@wso2is/forms";
import { ContentLoader, Hint, LinkButton, Message, URLInput } from "@wso2is/react-components";
import { FormValidation } from "@wso2is/validation";
import intersection from "lodash-es/intersection";
import isEmpty from "lodash-es/isEmpty";
import React, { FunctionComponent, ReactElement, useEffect, useState } from "react";
Expand Down Expand Up @@ -543,14 +542,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 @@
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://");

Check warning on line 46 in modules/core/src/utils/url-utils.ts

View check run for this annotation

Codecov / codecov/patch

modules/core/src/utils/url-utils.ts#L46

Added line #L46 was not covered by tests
}

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://");

Check warning on line 62 in modules/core/src/utils/url-utils.ts

View check run for this annotation

Codecov / codecov/patch

modules/core/src/utils/url-utils.ts#L62

Added line #L62 was not covered by tests
}

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
Loading