{"record":{"id":"dcdde18a726bc4c3","repo":"ruvnet/ruflo","slug":"invalid-gcs-bucket-name-config-bucket","errorCode":null,"errorMessage":"Invalid GCS bucket name: ${config.bucket}","messagePattern":"Invalid GCS bucket name: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/cli/src/transfer/storage/gcs.ts","lineNumber":130,"sourceCode":"      'GCS not configured. Set GCS_BUCKET environment variable.\\n' +\n      'Or authenticate: gcloud auth login && gcloud config set project YOUR_PROJECT'\n    );\n  }\n\n  const contentId = generateContentId(content);\n  const checksum = crypto.createHash('sha256').update(content).digest('hex');\n  const fileName = options.name || `${contentId}.cfp.json`;\n\n  // Validate filename to prevent path traversal\n  if (!/^[a-zA-Z0-9._\\-]+$/.test(fileName) || fileName.includes('..')) {\n    throw new Error(`Invalid filename: ${fileName}`);\n  }\n\n  const objectPath = config.prefix ? `${config.prefix}/${fileName}` : fileName;\n\n  // S-1: Validate bucket name and object path to prevent command injection\n  if (!isValidBucketName(config.bucket)) {\n    throw new Error(`Invalid GCS bucket name: ${config.bucket}`);\n  }\n  if (!isValidObjectPath(objectPath)) {\n    throw new Error(`Invalid GCS object path: ${objectPath}`);\n  }\n\n  console.log(`[GCS] Uploading to gs://${config.bucket}/${objectPath}...`);\n\n  // Write content to temp file\n  const tempDir = process.env.TMPDIR || '/tmp';\n  const tempFile = path.join(tempDir, `claude-flow-upload-${Date.now()}.json`);\n  fs.writeFileSync(tempFile, content);\n\n  try {\n    // Build gcloud args (array form prevents shell injection)\n    const uploadArgs = ['storage', 'cp', tempFile, `gs://${config.bucket}/${objectPath}`];\n    if (config.projectId) uploadArgs.push(`--project=${config.projectId}`);\n    uploadArgs.push(`--content-type=${options.contentType || 'application/json'}`);\n","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/cli/src/transfer/storage/gcs.ts#L112-L148","documentation":"Before invoking `gcloud storage cp`, uploadToGCS validates config.bucket through isValidBucketName(), which enforces GCS bucket naming rules (lowercase letters, digits, hyphens/underscores, length limits, no 'goog' prefix, etc.). A value failing those rules — uppercase letters, spaces, a 'gs://' scheme accidentally included, or a malformed name — is rejected. Comment 'S-1' marks this as command-injection hardening, since the bucket is interpolated into a gcloud argument.","triggerScenarios":"Setting GCS_BUCKET='gs://my-bucket' (scheme included); uppercase or spaced bucket names like 'My Bucket'; trailing slashes; bucket names copied from URLs; values under 3 or over 222 characters.","commonSituations":"Pasting the bucket URI from the GCP console instead of the bare name; case mismatches (GCS buckets are globally lowercase-unique); whitespace from shell config or .env quoting; names with dots beyond allowed patterns.","solutions":["Set GCS_BUCKET to the bare bucket name, lowercase, no scheme and no trailing slash — e.g. 'my-pattern-bucket' not 'gs://my-pattern-bucket/'","Trim whitespace/newlines from the env value (common with .env files and shell exports)","Rename to comply with GCS rules: 3-222 chars, lowercase letters/digits/hyphens/underscores, not starting with 'goog'","Cross-check with `gcloud storage ls gs://<name>` that the name resolves before rerunning the upload"],"exampleFix":"# before\nexport GCS_BUCKET=\"gs://My-Bucket/\" # scheme + uppercase -> Invalid GCS bucket name\n\n# after\nexport GCS_BUCKET=my-bucket\nnpx claude-flow hooks transfer store --storage gcs","handlingStrategy":"validation","validationCode":"function isValidBucketName(bucket: string): boolean {\n  return /^[a-z0-9][a-z0-9_-]{1,219}[a-z0-9]$/.test(bucket)\n    && !bucket.startsWith('goog');\n}\n\nconst bucket = process.env.GCS_BUCKET!;\nif (!isValidBucketName(bucket)) {\n  throw new Error(`GCS_BUCKET '${bucket}' violates GCS naming rules (lowercase, no gs:// scheme, 3-222 chars)`);\n}\nawait uploadToGCS(content, { config: { bucket } });","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Store the bare bucket name — never 'gs://...' URIs or trailing slashes — in GCS_BUCKET","Validate the env value at startup with a naming-rule regex rather than discovering it mid-upload","GCS bucket names are lowercase-only; uppercase values always fail both this guard and GCS itself"],"tags":["gcs","bucket-name","validation","cloud-storage","configuration"],"backgroundTag":"invalid-bucket-name","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}