Skip to content

Commit 9b8cb9a

Browse files
committed
Protect against symlink attacks
Update embedded launch script to no longer change ownership of files or folders that already exist. Fixes spring-projectsgh-11397
1 parent 604ec07 commit 9b8cb9a

File tree

5 files changed

+78
-4
lines changed

5 files changed

+78
-4
lines changed

spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/java/org/springframework/boot/launchscript/SysVinitLaunchScriptIT.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,25 @@ public void launchWithRelativePidFolder() throws Exception {
220220
coloredString(AnsiColor.GREEN, "Stopped [" + extractPid(output) + "]"));
221221
}
222222

223+
@Test
224+
public void pidFolderOwnership() throws Exception {
225+
String output = doTest("pid-folder-ownership.sh");
226+
System.err.println(output);
227+
assertThat(output).contains("phil root");
228+
}
229+
230+
@Test
231+
public void pidFileOwnership() throws Exception {
232+
String output = doTest("pid-file-ownership.sh");
233+
assertThat(output).contains("phil root");
234+
}
235+
236+
@Test
237+
public void logFileOwnership() throws Exception {
238+
String output = doTest("log-file-ownership.sh");
239+
assertThat(output).contains("phil root");
240+
}
241+
223242
@Test
224243
public void launchWithRelativeLogFolder() throws Exception {
225244
String output = doTest("launch-with-relative-log-folder.sh");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
source ./test-functions.sh
2+
install_service
3+
4+
chmod o+w /var/log
5+
6+
useradd phil
7+
mkdir /phil-files
8+
chown phil /phil-files
9+
10+
useradd andy
11+
chown andy /test-service/spring-boot-app.jar
12+
13+
start_service
14+
stop_service
15+
16+
su - andy -c "ln -s -f /phil-files /var/log/spring-boot-app.log"
17+
18+
start_service
19+
20+
ls -ld /phil-files
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
source ./test-functions.sh
2+
install_service
3+
4+
useradd phil
5+
mkdir /phil-files
6+
chown phil /phil-files
7+
8+
useradd andy
9+
chown andy /test-service/spring-boot-app.jar
10+
11+
start_service
12+
stop_service
13+
14+
su - andy -c "ln -s /phil-files /var/run/spring-boot-app/spring-boot-app.pid"
15+
16+
start_service
17+
18+
ls -ld /phil-files
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
source ./test-functions.sh
2+
install_service
3+
4+
chmod o+w /var/run
5+
6+
useradd phil
7+
mkdir /phil-files
8+
chown phil /phil-files
9+
10+
useradd andy
11+
chown andy /test-service/spring-boot-app.jar
12+
13+
su - andy -c "ln -s -f /phil-files /var/run/spring-boot-app"
14+
15+
start_service
16+
17+
ls -ld /phil-files

spring-boot-tools/spring-boot-loader-tools/src/main/resources/org/springframework/boot/loader/tools/launch.script

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,12 @@ start() {
146146
do_start() {
147147
working_dir=$(dirname "$jarfile")
148148
pushd "$working_dir" > /dev/null
149-
mkdir -p "$PID_FOLDER" &> /dev/null
149+
if [[ ! -e "$PID_FOLDER" ]]; then
150+
mkdir -p "$PID_FOLDER" &> /dev/null
151+
chown "$run_user" "$PID_FOLDER"
152+
fi
150153
if [[ -n "$run_user" ]]; then
151154
checkPermissions || return $?
152-
chown "$run_user" "$PID_FOLDER"
153-
chown "$run_user" "$pid_file"
154-
chown "$run_user" "$log_file"
155155
if [ $USE_START_STOP_DAEMON = true ] && type start-stop-daemon > /dev/null 2>&1; then
156156
start-stop-daemon --start --quiet \
157157
--chuid "$run_user" \

0 commit comments

Comments
 (0)