Skip to content

Commit 10eefd4

Browse files
authored
Merge pull request #14 from DataDog/aless-fix-images
Updated python build to bullseye & disabled authentication on submission endpoint.
2 parents 5e774c8 + 2df9ac3 commit 10eefd4

8 files changed

Lines changed: 42 additions & 21 deletions

File tree

CTFd/auth.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,14 @@ def register():
203203
email_address = request.form.get("email", "").strip().lower()
204204
password = request.form.get("password", "").strip()
205205
auto_register_team = request.form.get("auto_register_team", default=False)
206+
# Coerce potential string form values to a real boolean
207+
if isinstance(auto_register_team, str):
208+
auto_register_team = auto_register_team.strip().lower() in (
209+
"1",
210+
"true",
211+
"on",
212+
"yes",
213+
)
206214

207215
website = request.form.get("website")
208216
affiliation = request.form.get("affiliation")

CTFd/plugins/datadog_logs/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def wrapper(*args, **kwargs):
4141

4242
message = (
4343
f"source=ctfd, event={ctfd_config.ctf_name()},type=hint,success={result.json['success']},"
44-
f"challenge={challenge.name},category='{challenge.category}',team={team.name},"
44+
f"challenge={challenge.name},category='{challenge.category}',team={(team.name if team else 'N/A')},"
4545
f"user={user.name},points={hint.cost * -1},"
4646
f"msg=Player {user.name} just traded {hint.cost} points for a hint on challenge {challenge.name}"
4747
)
@@ -72,8 +72,8 @@ def wrapper(*args, **kwargs):
7272
if result.json["data"]["status"] == "incorrect":
7373
message = (
7474
f"source=ctfd, event={ctfd_config.ctf_name()},type=challenge,status=incorrect,"
75-
f"challenge='{challenge.name}',category={challenge.category},team={team.name},"
76-
f"user={user.name},points=0,msg='Team {team.name} provided an incorrect answer "
75+
f"challenge='{challenge.name}',category={challenge.category},team={(team.name if team else 'N/A')},"
76+
f"user={user.name},points=0,msg='Team {(team.name if team else 'N/A')} provided an incorrect answer "
7777
f"for challenge {challenge.name}'"
7878
)
7979
log("submissions", message)
@@ -85,9 +85,9 @@ def wrapper(*args, **kwargs):
8585

8686
message = (
8787
f"source=ctfd, event={ctfd_config.ctf_name()},type=challenge,status=correct,"
88-
f"challenge='{challenge.name}',category={challenge.category},team={team.name},"
88+
f"challenge='{challenge.name}',category={challenge.category},team={(team.name if team else 'N/A')},"
8989
f"user={user.name},points={challenge.value},"
90-
f"msg='Team {team.name} is the {num_solves} to solve challenge {challenge.name}'"
90+
f"msg='Team {(team.name if team else 'N/A')} is the {num_solves} to solve challenge {challenge.name}'"
9191
)
9292
log("submissions", message)
9393

CTFd/teams.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ def join():
158158

159159
if team and verify_password(passphrase, team.password):
160160
team_size_limit = get_config("team_size", default=0)
161+
# Refresh team object to ensure members are up-to-date
162+
db.session.refresh(team)
161163
if team_size_limit and len(team.members) >= team_size_limit:
162164
errors.append(
163165
"{name} has already reached the team size limit of {limit}".format(

Dockerfile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.9-slim-buster as build
1+
FROM python:3.9-slim-bullseye as build
22

33
WORKDIR /opt/CTFd
44

@@ -9,6 +9,9 @@ RUN apt-get update \
99
libffi-dev \
1010
libssl-dev \
1111
git \
12+
pkg-config \
13+
libev-dev \
14+
python3-dev \
1215
&& apt-get clean \
1316
&& rm -rf /var/lib/apt/lists/* \
1417
&& python -m venv /opt/venv
@@ -25,14 +28,15 @@ RUN pip install --no-cache-dir -r requirements.txt \
2528
done;
2629

2730

28-
FROM python:3.9-slim-buster as release
31+
FROM python:3.9-slim-bullseye as release
2932
WORKDIR /opt/CTFd
3033

3134
# hadolint ignore=DL3008
3235
RUN apt-get update \
3336
&& apt-get install -y --no-install-recommends \
34-
libffi6 \
37+
libffi7 \
3538
libssl1.1 \
39+
libev4 \
3640
&& apt-get clean \
3741
&& rm -rf /var/lib/apt/lists/*
3842

development.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ coverage==7.2.3
66
psycopg2-binary==2.9.6
77
moto==4.1.11
88
bandit==1.6.2
9+
pbr==5.11.1
910
flask_profiler==1.8.1
1011
pytest-xdist==3.2.1
1112
pytest-cov==4.0.0

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ flask-sqlalchemy==2.5.1
7575
# flask-migrate
7676
freezegun==1.2.2
7777
# via -r requirements.in
78-
gevent==23.9.1
78+
gevent==24.11.1
7979
# via -r requirements.in
80-
greenlet==2.0.1
80+
greenlet==3.1.1
8181
# via
8282
# gevent
8383
# sqlalchemy

tests/teams/test_teams.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ def test_accessing_hidden_teams():
4444
user.team_id = team.id
4545
app.db.session.commit()
4646

47-
assert client.get("/teams/1").status_code == 404
48-
assert client.get("/api/v1/teams/1").status_code == 404
49-
assert client.get("/api/v1/teams/1/solves").status_code == 404
50-
assert client.get("/api/v1/teams/1/fails").status_code == 404
51-
assert client.get("/api/v1/teams/1/awards").status_code == 404
47+
assert client.get(f"/teams/{team.id}").status_code == 404
48+
assert client.get(f"/api/v1/teams/{team.id}").status_code == 404
49+
assert client.get(f"/api/v1/teams/{team.id}/solves").status_code == 404
50+
assert client.get(f"/api/v1/teams/{team.id}/fails").status_code == 404
51+
assert client.get(f"/api/v1/teams/{team.id}/awards").status_code == 404
5252
destroy_ctfd(app)
5353

5454

@@ -96,9 +96,13 @@ def test_hidden_teams_visibility():
9696
# Team should re-appear after disabling hiding
9797
# Use an API call to cause a cache clear
9898
with login_as_user(app, name="admin") as admin:
99-
r = admin.patch("/api/v1/teams/1", json={"hidden": False})
99+
r = admin.patch(f"/api/v1/teams/{team_id}", json={"hidden": False})
100100
assert r.status_code == 200
101101

102+
# Re-fetch team from the database to avoid detached instance issues
103+
team = Teams.query.filter_by(id=team_id).first()
104+
assert team.hidden is False # Verify the team is actually unhidden
105+
102106
r = client.get("/teams")
103107
response = r.get_data(as_text=True)
104108
assert team_name in response
@@ -148,8 +152,10 @@ def test_teams_id_get():
148152
team.members.append(user)
149153
user.team_id = team.id
150154
app.db.session.commit()
155+
# Capture the team id now and avoid accessing ORM instances later
156+
team_id = team.id
151157
with login_as_user(app, name="user_name", password="password") as client:
152-
r = client.get("/teams/1")
158+
r = client.get(f"/teams/{team_id}")
153159
assert r.status_code == 200
154160
destroy_ctfd(app)
155161

tests/utils/test_updates.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ def test_update_check_notifies_user():
6060
destroy_ctfd(app)
6161

6262

63-
@patch.object(requests, "post")
64-
def test_update_check_ignores_downgrades(fake_post_request):
63+
@patch.object(requests, "get")
64+
def test_update_check_ignores_downgrades(fake_get_request):
6565
"""Update checks do nothing on old or same versions"""
6666
app = create_ctfd()
6767
with app.app_context():
6868
app.config["UPDATE_CHECK"] = True
6969
fake_response = Mock()
70-
fake_post_request.return_value = fake_response
70+
fake_get_request.return_value = fake_response
7171
fake_response.json = lambda: {
7272
"resource": {
7373
"html_url": "https://github.com/CTFd/CTFd/releases/tag/0.0.1",
@@ -83,7 +83,7 @@ def test_update_check_ignores_downgrades(fake_post_request):
8383
assert get_config("version_latest") is None
8484

8585
fake_response = Mock()
86-
fake_post_request.return_value = fake_response
86+
fake_get_request.return_value = fake_response
8787
fake_response.json = lambda: {
8888
"resource": {
8989
"html_url": "https://github.com/CTFd/CTFd/releases/tag/{}".format(

0 commit comments

Comments
 (0)