Skip to content

Commit 390b21a

Browse files
committed
Adding setvariable for commands
1 parent 267ee22 commit 390b21a

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

docs/pipelines/security/templates.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Security through templates
33
description: Using template features to improve pipeline security.
44
ms.assetid: 73d26125-e3ab-4e18-9bcd-387fb21d3568
55
ms.reviewer: macoope
6-
ms.date: 08/03/2020
6+
ms.date: 02/24/2021
77
monikerRange: '> azure-devops-2019'
88
---
99

@@ -93,6 +93,22 @@ In restricted mode, most of the agent's services such as uploading artifacts and
9393
commands: restricted
9494
```
9595
96+
One of the commands still allowed in restricted mode is the `setvariable` command. Because pipeline variables are exported as environment variables to subsequent tasks, tasks that output user-provided data (for example, the contents of open issues retrieved from a REST API) can be vulnerable to injection attacks. Such user content can set environment variables that can in turn be used to exploit the agent host. To disallow this, pipeline authors can explicitly declare which variables are settable via the `setvariable` logging command. Specifying an empty list disallows setting all variables.
97+
98+
```yaml
99+
# this task will fail because the task is only allowed to set the 'expectedVar' variable, or a variable prefixed with "ok"
100+
- task: PowerShell@2
101+
target:
102+
commands: restricted
103+
settableVariables:
104+
- expectedVar
105+
- ok*
106+
inputs:
107+
targetType: 'inline'
108+
script: |
109+
Write-Host "##vso[task.setvariable variable=BadVar]myValue"
110+
```
111+
96112
### Conditional insertion of stages or jobs
97113

98114
Restrict stages and jobs to run under specific conditions.

0 commit comments

Comments
 (0)