-
Notifications
You must be signed in to change notification settings - Fork 397
Improve redirect uri validation #2883
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -350,6 +350,15 @@ private boolean validateCallbackURI(String callbackURI, OAuthAppDO oauthApp) { | |
registeredCallbackUrl = | ||
registeredCallbackUrl.replaceFirst(OAuthConstants.LOOPBACK_IP_PORT_REGEX, StringUtils.EMPTY); | ||
} | ||
return (regexp != null && callbackURI.matches(regexp)) || registeredCallbackUrl.equals(callbackURI); | ||
|
||
if (regexp == null) { | ||
return registeredCallbackUrl.equals(callbackURI); | ||
} | ||
/* | ||
Escape dots only when followed by a letter/digit (so .com, .org, etc. get escaped), | ||
but don't touch .* or .+ or .{n} . | ||
*/ | ||
regexp = regexp.replaceAll("(?<!\\\\)\\.(?=[A-Za-z0-9])", "\\\\."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The complex regex pattern with multiple escaped backslashes is difficult to read and maintain. Consider extracting this pattern to a named constant with clear documentation explaining its purpose and behavior. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
return callbackURI.matches(regexp); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The matches() method is vulnerable to ReDoS (Regular Expression Denial of Service) attacks with malicious regex patterns. Consider adding timeout limits or using a safer regex matching approach to prevent potential DoS attacks. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regex pattern modification could introduce security vulnerabilities. Modifying user-provided regex patterns at runtime can lead to unexpected behavior or bypass security checks. Consider validating the original regex pattern instead of modifying it, or use a whitelist of allowed patterns.
Copilot uses AI. Check for mistakes.