Skip to content

🎥 Make videos programmatically with React

`@remotion/cloudrun`: Validate full site names (#9476)

Santhi Prakash153fb1e4c6ae
diff --git a/packages/cloudrun/src/shared/validate-site-name.ts b/packages/cloudrun/src/shared/validate-site-name.ts
index 0373a800eb..8faea6d110 100644
--- a/packages/cloudrun/src/shared/validate-site-name.ts
+++ b/packages/cloudrun/src/shared/validate-site-name.ts
@@ -1,3 +1,5 @@
+const VALID_SITE_NAME_RE = /^[-0-9a-zA-Z!_.*'()]+$/;
+
export const validateSiteName = (siteName: unknown) => {
if (typeof siteName === 'undefined') {
return;
@@ -5,15 +7,23 @@ export const validateSiteName = (siteName: unknown) => {
if (typeof siteName !== 'string') {
throw new TypeError(
- `The 'projectName' argument must be a string if provided, but is ${JSON.stringify(
+ `The 'siteName' argument must be a string if provided, but is ${JSON.stringify(
siteName,
)}`,
);
}
- if (!siteName.match(/([0-9a-zA-Z-!_.*'()]+)/g)) {
+ if (siteName === '.' || siteName === '..') {
+ throw new Error(
+ 'The `siteName` must not be `.` or `..`. You passed: ' + siteName + '.',
+ );
+ }
+
+ if (!VALID_SITE_NAME_RE.test(siteName)) {
throw new Error(
- "The `siteName` must match the RegExp `/([0-9a-zA-Z-!_.*'()]+)/g`. You passed: " +
+ 'The `siteName` must match the RegExp `/' +
+ VALID_SITE_NAME_RE.source +
+ '/`. You passed: ' +
siteName +
'. Check for invalid characters.',
);
diff --git a/packages/cloudrun/src/test/validate-site-name.test.ts b/packages/cloudrun/src/test/validate-site-name.test.ts
new file mode 100644
index 0000000000..1eebef5948
--- /dev/null
+++ b/packages/cloudrun/src/test/validate-site-name.test.ts
@@ -0,0 +1,38 @@
+import {expect, test} from 'bun:test';
+import {validateSiteName} from '../shared/validate-site-name';
+
+test('allows valid site names', () => {
+ expect(() => validateSiteName('my-site')).not.toThrow();
+ expect(() => validateSiteName('my_site.v1')).not.toThrow();
+ expect(() => validateSiteName("my-site-!'()*")).not.toThrow();
+});
+
+test('rejects invalid characters', () => {
+ expect(() => validateSiteName('my site')).toThrow(/Check for invalid characters/);
+ expect(() => validateSiteName('my@site')).toThrow(/Check for invalid characters/);
+ expect(() => validateSiteName('my#site')).toThrow(/Check for invalid characters/);
+});
+
+test('rejects dot segments and empty strings', () => {
+ expect(() => validateSiteName('.')).toThrow(
+ 'The `siteName` must not be `.` or `..`.',
+ );
+ expect(() => validateSiteName('..')).toThrow(
+ 'The `siteName` must not be `.` or `..`.',
+ );
+ expect(() => validateSiteName('')).toThrow(/Check for invalid characters/);
+});
+
+test('rejects substrings and suffixes that contain invalid characters', () => {
+ expect(() => validateSiteName('valid/name')).toThrow(/Check for invalid characters/);
+ expect(() => validateSiteName('valid name')).toThrow(/Check for invalid characters/);
+});
+
+test('allows undefined', () => {
+ expect(() => validateSiteName(undefined)).not.toThrow();
+});
+
+test('throws a TypeError for non-string types', () => {
+ expect(() => validateSiteName(123)).toThrow(TypeError);
+ expect(() => validateSiteName(null)).toThrow(TypeError);
+});