mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
feat: normalize domain and subdomain inputs by trimming and converting to lowercase in DomainService and StatusPageDomainService
This commit is contained in:
@@ -16,6 +16,12 @@ export class Service extends DatabaseService<Model> {
|
||||
protected override async onBeforeCreate(
|
||||
createBy: CreateBy<Model>,
|
||||
): Promise<OnCreate<Model>> {
|
||||
if (createBy.data.domain) {
|
||||
createBy.data.domain.domain = createBy.data.domain.domain
|
||||
.trim()
|
||||
.toLowerCase();
|
||||
}
|
||||
|
||||
createBy.data.domainVerificationText =
|
||||
"oneuptime-verification-" + Text.generateRandomText(20);
|
||||
return Promise.resolve({ createBy, carryForward: null });
|
||||
|
||||
@@ -48,8 +48,19 @@ export class Service extends DatabaseService<StatusPageDomain> {
|
||||
);
|
||||
}
|
||||
|
||||
if (createBy.data.subdomain) {
|
||||
// trim and lowercase the subdomain.
|
||||
createBy.data.subdomain = createBy.data.subdomain.trim().toLowerCase();
|
||||
}
|
||||
|
||||
if (domain) {
|
||||
createBy.data.fullDomain = createBy.data.subdomain + "." + domain.domain;
|
||||
createBy.data.fullDomain = (
|
||||
createBy.data.subdomain +
|
||||
"." +
|
||||
domain.domain?.toString()
|
||||
)
|
||||
.toLowerCase()
|
||||
.trim();
|
||||
}
|
||||
|
||||
createBy.data.cnameVerificationToken = ObjectID.generate().toString();
|
||||
|
||||
@@ -45,16 +45,18 @@ export default class Jobs {
|
||||
|
||||
// Write to disk.
|
||||
await LocalFile.write(
|
||||
`/etc/nginx/certs/StatusPageCerts/${cert.domain}.crt`,
|
||||
`/etc/nginx/certs/StatusPageCerts/${cert.domain?.toString().trim().toLocaleLowerCase()}.crt`,
|
||||
cert.certificate?.toString() || "",
|
||||
);
|
||||
|
||||
await LocalFile.write(
|
||||
`/etc/nginx/certs/StatusPageCerts/${cert.domain}.key`,
|
||||
`/etc/nginx/certs/StatusPageCerts/${cert.domain?.toString().trim().toLocaleLowerCase()}.key`,
|
||||
cert.certificateKey?.toString() || "",
|
||||
);
|
||||
|
||||
logger.debug(`Wrote custom certs to disk for domain: ${cert.domain}`);
|
||||
logger.debug(
|
||||
`Wrote custom certs to disk for domain: ${cert.domain?.toString().trim().toLocaleLowerCase()}`,
|
||||
);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
@@ -58,17 +58,17 @@ export default class Jobs {
|
||||
|
||||
// Write to disk.
|
||||
await LocalFile.write(
|
||||
`/etc/nginx/certs/StatusPageCerts/${cert.fullDomain}.crt`,
|
||||
`/etc/nginx/certs/StatusPageCerts/${cert.fullDomain?.toString().trim().toLocaleLowerCase()}.crt`,
|
||||
cert.customCertificate?.toString() || "",
|
||||
);
|
||||
|
||||
await LocalFile.write(
|
||||
`/etc/nginx/certs/StatusPageCerts/${cert.fullDomain}.key`,
|
||||
`/etc/nginx/certs/StatusPageCerts/${cert.fullDomain?.toString().trim().toLocaleLowerCase()}.key`,
|
||||
cert.customCertificateKey?.toString() || "",
|
||||
);
|
||||
|
||||
logger.debug(
|
||||
`Wrote custom certs to disk for domain: ${cert.fullDomain}`,
|
||||
`Wrote custom certs to disk for domain: ${cert.fullDomain?.toString().trim().toLocaleLowerCase()}`,
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user