Skip to content

Commit 314da2c

Browse files
committed
feat: add sanitizeSubdomainInput
1 parent 60d5c13 commit 314da2c

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

projects/lib/organization/components/organization-management/organization-management.component.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,38 @@ export class OrganizationManagementComponent implements OnInit {
166166
};
167167
}
168168

169+
/**
170+
* Allows only valid subdomain values: alphanumeric, hyphens, no periods, cannot start/end with hyphen, min 1 character.
171+
* Returns sanitized string or null if invalid.
172+
*/
173+
private sanitizeSubdomainInput(input: string): string | null {
174+
// RFC 1034/1123: subdomain labels are 1-63 chars, start/end with alphanum, can contain '-'
175+
if (typeof input !== 'string') return null;
176+
const sanitized = input.trim();
177+
if (/^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$/.test(sanitized)) {
178+
return sanitized;
179+
}
180+
return null;
181+
}
182+
169183
async switchOrganization() {
170184
const { baseDomain } = await this.envConfigService.getEnvConfig();
171185
const protocol = window.location.protocol;
172-
const fullSubdomain = `${this.organizationToSwitch}.${baseDomain}`;
186+
const sanitizedOrg = this.sanitizeSubdomainInput(this.organizationToSwitch);
187+
188+
if (!sanitizedOrg) {
189+
this.luigiCoreService.showAlert({
190+
text: 'Organization name is not valid for subdomain usage, accrording to RFC 1034/1123.',
191+
type: 'error',
192+
});
193+
return;
194+
}
195+
196+
const fullSubdomain = `${sanitizedOrg}.${baseDomain}`;
173197
const port = window.location.port ? `:${window.location.port}` : '';
174198

199+
console.log(`Switching to organization ${this.organizationToSwitch}`);
200+
console.log(`Redirecting to ${protocol}//${fullSubdomain}${port}`);
175201
window.location.href = `${protocol}//${fullSubdomain}${port}`;
176202
}
177203
}

0 commit comments

Comments
 (0)