Skip to content

Commit ec9d5af

Browse files
authored
Merge pull request #925 from 0x4ndy/main
2 parents 541ee9f + 4901496 commit ec9d5af

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed

compiler/base/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ RUN apt-get update && apt-get install -y \
2020

2121
RUN useradd -m playground -d /playground
2222
RUN usermod -p '!!' root # Disable all passwords for root
23+
24+
# Attach the security note
25+
ADD --chown=playground attach_notice.sh security_notice.txt /playground/
26+
RUN /playground/attach_notice.sh /playground/security_notice.txt /etc/passwd && \
27+
/playground/attach_notice.sh /playground/security_notice.txt /etc/shadow && \
28+
rm -f /playground/attach_notice.sh
29+
2330
USER playground
2431
ENV USER=playground
2532
ENV PATH=/playground/.cargo/bin:$PATH

compiler/base/attach_notice.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
3+
set -eu
4+
5+
NOTICE_FILE=$1 # full path to the notice file
6+
TARGET_FILE=$2 # full patch to the target file
7+
8+
POSITION=${3:-"top"} # possible values: top or bottom; default value: top
9+
10+
function attach_notice() {
11+
echo "Attaching ${NOTICE_FILE} to ${TARGET_FILE} (position: ${POSITION})"
12+
13+
if [[ "${POSITION}" == "bottom" ]]; then
14+
cat "${NOTICE_FILE}" >> "${TARGET_FILE}"
15+
else
16+
combined=$(mktemp)
17+
cat "${NOTICE_FILE}" "${TARGET_FILE}" >> "${combined}"
18+
chmod --reference "${TARGET_FILE}" "${combined}"
19+
mv "${combined}" "${TARGET_FILE}"
20+
fi
21+
22+
echo "Done."
23+
}
24+
25+
if [[ -f "${NOTICE_FILE}" ]] && [[ -f "${TARGET_FILE}" ]]; then
26+
attach_notice
27+
fi

compiler/base/security_notice.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Hello, and thanks for looking into the Rust Playground's security!
2+
#
3+
# This build is running on an unprivileged, sandboxed Docker container with no
4+
# network access, so while you can technically run arbitrary code on the
5+
# Playground you shouldn't be able to do any damage with it.
6+
#
7+
# Nothing is perfect though: if you find a way to escape the sandbox, please
8+
# disclose it following our security policy! You can find the policy at:
9+
#
10+
# https://www.rust-lang.org/policies/security
11+
#

tests/spec/features/security_spec.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
require 'spec_helper'
2+
require 'support/editor'
3+
require 'support/playground_actions'
4+
5+
RSpec.feature "Security concerns", type: :feature, js: true do
6+
include PlaygroundActions
7+
8+
before do
9+
visit '/'
10+
editor.set(code)
11+
end
12+
13+
scenario "a notice is present for filesystem snoopers" do
14+
within(:header) { click_on("Run") }
15+
within(:output, :stdout) do
16+
expect(page).to have_content 'www.rust-lang.org/policies/security'
17+
end
18+
end
19+
20+
def editor
21+
Editor.new(page)
22+
end
23+
24+
def code
25+
<<~EOF
26+
fn main() {
27+
println!("{}", std::fs::read_to_string("/etc/passwd").unwrap());
28+
}
29+
EOF
30+
end
31+
end

0 commit comments

Comments
 (0)