Skip to content

Commit 31a45e5

Browse files
authored
Add blocklist of environment variables who could alter execution of plugins (#3934)
1 parent 764329e commit 31a45e5

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

flake.nix

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
gnumake
1919
gnutar
2020
zip
21+
tree
2122

2223
# frontend
2324
nodejs_20

pipeline/frontend/yaml/compiler/convert.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,14 @@ func (c *Compiler) createProcess(container *yaml_types.Container, stepType backe
131131
return nil, err
132132
}
133133

134+
toUpperTarget := strings.ToUpper(requested.Target)
135+
if !environmentAllowed(toUpperTarget, stepType) {
136+
continue
137+
}
138+
134139
environment[requested.Target] = secretValue
135140
// TODO: deprecated, remove in 3.x
136-
environment[strings.ToUpper(requested.Target)] = secretValue
141+
environment[toUpperTarget] = secretValue
137142
}
138143

139144
if utils.MatchImage(container.Image, c.escalated...) && container.IsPlugin() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright 2024 Woodpecker Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package compiler
16+
17+
import backend_types "go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/types"
18+
19+
/* cSpell:disable */
20+
21+
var binaryVars = []string{
22+
"PATH", // Specifies directories to search for executable files
23+
"PATH_SEPARATOR", // Defines the separator used in the PATH variable
24+
"COMMAND_MODE", // (macOS): Can affect how certain commands are interpreted
25+
"DYLD_FALLBACK_FRAMEWORK_PATH", // (macOS): Specifies additional locations to search for frameworks
26+
"DYLD_FALLBACK_LIBRARY_PATH", // (macOS): Specifies additional locations to search for libraries
27+
}
28+
29+
var libraryVars = []string{
30+
"LD_PRELOAD", // Specifies shared libraries to be loaded before all others
31+
"LD_LIBRARY_PATH", // Specifies directories to search for shared libraries before the standard locations
32+
"LD_AUDIT", // Specifies a shared object to be used for auditing
33+
"LD_BIND_NOW", // Forces all relocations to be processed immediately
34+
"LD_PROFILE", // Specifies a shared object to be used for profiling
35+
"LIBPATH", // (AIX): Similar to LD_LIBRARY_PATH on AIX systems
36+
"DYLD_INSERT_LIBRARIES", // (macOS): Similar to LD_PRELOAD on macOS
37+
"DYLD_LIBRARY_PATH", // (macOS): Similar to LD_LIBRARY_PATH on macOS
38+
}
39+
40+
/* cSpell:enable */
41+
42+
func environmentAllowed(envKey string, stepType backend_types.StepType) bool {
43+
switch stepType {
44+
case backend_types.StepTypePlugin,
45+
backend_types.StepTypeClone:
46+
for _, v := range append(binaryVars, libraryVars...) {
47+
if envKey == v {
48+
return false
49+
}
50+
}
51+
}
52+
return true
53+
}

0 commit comments

Comments
 (0)