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

Remove validateURL checks #13

Open
wants to merge 5 commits into
base: main
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
11 changes: 1 addition & 10 deletions src/main/java/org/openapitools/sdk/KindeClientSDK.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,11 @@ public KindeClientSDK(
if (domain == null || domain.isEmpty()) {
throw new IllegalArgumentException("Please provide domain");
}
if (!Utils.validateURL(domain)) {
throw new IllegalArgumentException("Please provide valid domain");
}
this.domain = domain;

if (redirectUri == null || redirectUri.isEmpty()) {
throw new IllegalArgumentException("Please provide redirect_uri");
}
if (!Utils.validateURL(redirectUri)) {
throw new IllegalArgumentException("Please provide valid redirect_uri");
}
this.redirectUri = redirectUri;

if (clientSecret == null || clientSecret.isEmpty()) {
Comment on lines 118 to 128
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [103-105]

Consider adding basic URL format validation for domain, redirectUri, and logoutRedirectUri parameters to ensure they are well-formed URLs.

+ import java.net.URL;
+ 
  if (domain == null || domain.isEmpty()) {
      throw new IllegalArgumentException("Please provide domain");
  }
+ try {
+     new URL(domain);
+ } catch (MalformedURLException e) {
+     throw new IllegalArgumentException("Domain must be a valid URL");
+ }

Repeat similar validation for redirectUri and logoutRedirectUri. This ensures that the URLs are syntactically valid, reducing the risk of errors or security vulnerabilities associated with malformed URLs.

Expand All @@ -149,9 +143,6 @@ public KindeClientSDK(
if (logoutRedirectUri == null || logoutRedirectUri.isEmpty()) {
throw new IllegalArgumentException("Please provide logout_redirect_uri");
}
if (!Utils.validateURL(logoutRedirectUri)) {
throw new IllegalArgumentException("Please provide valid logout_redirect_uri");
}

if (additionalParameters==null){
additionalParameters=new HashMap<>();
Expand Down Expand Up @@ -644,4 +635,4 @@ private String getGrantType(String grantType) {
}
}

}
}
8 changes: 1 addition & 7 deletions src/main/java/org/openapitools/sdk/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,6 @@ public static String generateCodeChallenge(String codeVerifier) {
}
}

public static boolean validateURL(String url) {
String pattern = "https?://(?:w{1,3}\\.)?[^\\s.]+(?:\\.[a-z]+)*(?::\\d+)?(?![^<]*(?:<\\/?\\w+>|\\/?>))";
// return Pattern.matches(pattern,url);
return url.matches(pattern);
}

public static Map<String, Object> parseJWT(String token) {
try {

Expand Down Expand Up @@ -184,4 +178,4 @@ public static String bytesToHex(byte[] bytes) {
return result.toString();
}

}
}
14 changes: 0 additions & 14 deletions src/test/java/org/openapitools/UtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,4 @@ public void testGenerateChallenge() {
() -> assertNotNull(result.get("codeChallenge"))
);
}

@Test
public void testValidationURL() {
String url = "https://test.com";
Boolean result = utils.validateURL(url);
assertEquals(Boolean.TRUE, result);
}

@Test
public void testValidationUrlInvalid() {
String urlInvalid = "test.c";
boolean result = utils.validateURL(urlInvalid);
assertNotEquals(result, true);
}
}