diff --git a/components/dashboard/src/projects/ProjectVariables.tsx b/components/dashboard/src/projects/ProjectVariables.tsx index f219a84cd81fd1..abc3378ba48ca3 100644 --- a/components/dashboard/src/projects/ProjectVariables.tsx +++ b/components/dashboard/src/projects/ProjectVariables.tsx @@ -44,28 +44,26 @@ export default function () {

Environment Variables

-

Manage environment variables for your project.

+

Manage project-specific environment variables.

- {envVars.length > 0 && } + {envVars.length > 0 && }
{envVars.length === 0 ?

No Environment Variables

-

Here you can set project-specific environment variables that will be visible during prebuilds and (optionally) in workspaces for this project.

+

All project-specific environment variables will be visible in prebuilds and optionally in workspaces for this project.

: <> - + Name - Value - Visible in Workspaces? + Visibility in Workspaces {envVars.map(variable => { - return + return {variable.name} - **** {variable.censored ? 'Hidden' : 'Visible'} void }) { await getGitpodService().server.setProjectEnvironmentVariable(props.project.id, name, value, censored); props.onClose(); } catch (err) { + console.error(err); setError(err); } } return { addVariable(); return false; }}> -

Add Variable

+

New Variable

- Project variables might be accessible by anyone with read access to your repository.
Secret values can be exposed if they are printed in the logs, persisted to the file system, or made visible in workspaces.
- {error &&
- {error} -
} + + Project environment variables can be exposed.
+ Even if Hide Variable in Workspaces is enabled, anyone with read access to your repository can access secret values if they are printed in the terminal, logged, or persisted to the file system. +
+ {error && + {String(error).replace(/Error: Request \w+ failed with message: /, '')} + }

Name

setName(e.target.value)} /> @@ -118,10 +120,10 @@ function AddVariableModal(props: { project?: Project, onClose: () => void }) { setValue(e.target.value)} />
- setCensored(!censored)} /> + setCensored(!censored)} />
{!censored &&
- This value will be directly visible to anyone who can open your repository in Gitpod. + This variable will be visible to anyone who starts a Gitpod workspace for your repository.
}
diff --git a/components/gitpod-db/src/typeorm/project-db-impl.ts b/components/gitpod-db/src/typeorm/project-db-impl.ts index fb33d0676cda69..14d094cfc206c3 100644 --- a/components/gitpod-db/src/typeorm/project-db-impl.ts +++ b/components/gitpod-db/src/typeorm/project-db-impl.ts @@ -108,7 +108,13 @@ export class ProjectDBImpl implements ProjectDB { } } - public async setProjectEnvironmentVariable(projectId: string, name: string, value: string, censored: boolean): Promise{ + public async setProjectEnvironmentVariable(projectId: string, name: string, value: string, censored: boolean): Promise { + if (!name) { + throw new Error('Variable name cannot be empty'); + } + if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(name)) { + throw new Error('Please choose a variable name containing only letters, numbers, or _, and which doesn\'t start with a number'); + } const envVarRepo = await this.getProjectEnvVarRepo(); const envVarWithValue = await envVarRepo.findOne({ projectId, name, deleted: false }); if (envVarWithValue) {