@peopl-health/nexus 5.57.8 → 5.57.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -115,9 +115,13 @@ function officeDocumentUrl(fileUrl) {
|
|
|
115
115
|
} catch {
|
|
116
116
|
url = null;
|
|
117
117
|
}
|
|
118
|
-
// The approved document template pins the
|
|
119
|
-
|
|
120
|
-
|
|
118
|
+
// The approved document template pins the S3 host and takes the rest of the URL as a variable. A bucket name
|
|
119
|
+
// with dots (whatsapp.prod) is presigned path-style, so the bucket is then the first path segment.
|
|
120
|
+
const bucket = escapeRegExp(bucketName ?? '');
|
|
121
|
+
const isVirtualHosted = new RegExp(`^${bucket}\\.s3(\\.[a-z0-9-]+)?\\.amazonaws\\.com$`).test(url?.hostname ?? '');
|
|
122
|
+
const isPathStyle = /^s3(\.[a-z0-9-]+)?\.amazonaws\.com$/.test(url?.hostname ?? '')
|
|
123
|
+
&& url.pathname.startsWith(`/${bucketName}/`);
|
|
124
|
+
if (!bucketName || url?.protocol !== 'https:' || !(isVirtualHosted || isPathStyle)) {
|
|
121
125
|
throw httpError(400, 'The document must be uploaded before it is sent');
|
|
122
126
|
}
|
|
123
127
|
return url;
|