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

fix: validating firstFactors not to contain special chars #1050

Merged
merged 5 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

- Adds validation to firstFactors and requiredSecondaryFactors names while creating tenants/apps/etc. to not allow
special chars.

## [9.2.2] - 2024-09-04

- Adds index on `last_active_time` for `user_last_active` table to improve the performance of MAU computation.
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ compileTestJava { options.encoding = "UTF-8" }
// }
//}

version = "9.2.2"
version = "9.2.3"


repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ protected void handle(HttpServletRequest req, HttpServletResponse resp, TenantId

// Apply updates based on CDI version
tenantConfig = applyTenantUpdates(tenantConfig, getVersionFromRequest(req), isV2, input);
validateFactorsName(tenantConfig);

// Write tenant config to db
createOrUpdate(req, sourceTenantIdentifier, tenantConfig);
Expand Down Expand Up @@ -938,6 +939,27 @@ private static TenantConfig applyTenantUpdates_5_0(TenantConfig tenantConfig, Js
return tenantConfig;
}

private static void validateFactorsName(TenantConfig tenantConfig) throws ServletException{
if(!areFactorNamesValid(tenantConfig.firstFactors)){
throw new ServletException(new BadRequestException("firstFactors should contain only 0-9,a-z,A-Z,_,- characters"));
}
if(!areFactorNamesValid(tenantConfig.requiredSecondaryFactors)){
throw new ServletException(new BadRequestException("requiredSecondaryFactors should contain only 0-9,a-z,A-Z,_,- characters"));
}
}

private static boolean areFactorNamesValid(String[] factors) {
if(factors != null && factors.length > 0) {
String allowedPattern = "^[0-9a-zA-Z_-]+$";
sattvikc marked this conversation as resolved.
Show resolved Hide resolved
for(String factor: factors){
if(factor != null && !factor.matches(allowedPattern)){
return false;
}
}
}
return true;
}

private static TenantConfig applyV2TenantUpdates_5_1(TenantConfig tenantConfig, JsonObject input)
throws ServletException {
if (input.has("emailPasswordEnabled")) {
Expand Down
Loading