Skip to content

Commit 3486470

Browse files
authored
Merge pull request #2829 from pi-hole/master
Sync master back into development
2 parents f2102a0 + a77c54c commit 3486470

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

src/api/teleporter.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,15 @@ static int api_teleporter_POST(struct ftl_conn *api)
229229
"The current app session is not allowed to modify Pi-hole config settings (webserver.api.app_sudo is false)");
230230
}
231231

232+
// Check if this is a CLI session and reject the request
233+
if(api->session != NULL && api->session->cli)
234+
{
235+
return send_json_error(api, 403,
236+
"forbidden",
237+
"Unable to change configuration (read-only)",
238+
"The current CLI session is not allowed to modify Pi-hole config settings");
239+
}
240+
232241
struct upload_data data;
233242
memset(&data, 0, sizeof(struct upload_data));
234243
const struct mg_request_info *req_info = mg_get_request_info(api->conn);

test/api/checkAPI.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from libs.responseVerifyer import ResponseVerifyer
1818

1919
TRACE = False
20+
CLI_PW_FILE = "/etc/pihole/cli_pw"
2021

2122
def main():
2223
# OpenAPI specs are split into multiple files, this script extracts the endpoints from them
@@ -101,6 +102,33 @@ def main():
101102
errs[2] += len(errors)
102103
print("")
103104

105+
# Verify that Teleporter import is blocked for CLI sessions
106+
print("Verifying FTL Teleporter import is blocked for CLI sessions...")
107+
try:
108+
with open(CLI_PW_FILE, "r", encoding="utf-8") as file:
109+
cli_password = file.read().strip()
110+
except FileNotFoundError:
111+
cli_password = None
112+
113+
if cli_password is None or len(cli_password) == 0:
114+
print(" Skipping (no CLI password available)")
115+
else:
116+
try:
117+
ftl_cli = FTLAPI("http://127.0.0.1", cli_password)
118+
response = ftl_cli.POST("/api/teleporter", json_data=None, files={"file": ('teleporter.zip', teleporter, 'application/zip')})
119+
if response is None:
120+
print(" Error: no response from FTL API")
121+
errs[2] += 1
122+
elif "error" not in response or response["error"].get("key") != "forbidden":
123+
print(" Error: expected forbidden error, got: " + str(response))
124+
errs[2] += 1
125+
else:
126+
print(" POST /api/teleporter (CLI session): OK (blocked)")
127+
except Exception as e:
128+
print(" Exception: " + str(e))
129+
errs[2] += 1
130+
print("")
131+
104132
# Print the number error (if any)
105133
if errs[0] > 0:
106134
print("Found " + str(errs[0]) + " non-implemented endpoints")

0 commit comments

Comments
 (0)