Skip to content

Conversation

sakce
Copy link
Contributor

@sakce sakce commented Sep 12, 2025

Problem

Customers that want more flexibility and ability to run Python code on their PostHog data.

Changes

How did you test this code?

👉 Stay up-to-date with PostHog coding conventions for a smoother review.

Copy link
Contributor

Size Change: +568 B (+0.02%)

Total Size: 2.73 MB

ℹ️ View Unchanged
Filename Size Change
frontend/dist/toolbar.js 2.73 MB +568 B (+0.02%)

compressed-size-action

def _get_available_port(self) -> int:
"""Get an available port for the container"""
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind(('', 0))

Check warning

Code scanning / CodeQL

Binding a socket to all network interfaces Medium

'' binds a socket to all interfaces.

Copilot Autofix

AI 1 day ago

To fix the problem, the socket used to discover an available port should be bound to the loopback interface (127.0.0.1) instead of all interfaces (''). This change is very safe, because the intention is merely to discover a free port; restricting binding to localhost prevents any other machine from connecting to this temporary socket, even during its brief existence. The change is minimal: simply replace s.bind(('', 0)) with s.bind(('127.0.0.1', 0)) in the function _get_available_port within products/streamlit/backend/container_service.py. No other code changes or dependency updates are needed.

Suggested changeset 1
products/streamlit/backend/container_service.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/products/streamlit/backend/container_service.py b/products/streamlit/backend/container_service.py
--- a/products/streamlit/backend/container_service.py
+++ b/products/streamlit/backend/container_service.py
@@ -25,7 +25,7 @@
     def _get_available_port(self) -> int:
         """Get an available port for the container"""
         with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
-            s.bind(('', 0))
+            s.bind(('127.0.0.1', 0))
             s.listen(1)
             port = s.getsockname()[1]
         return port
EOF
@@ -25,7 +25,7 @@
def _get_available_port(self) -> int:
"""Get an available port for the container"""
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind(('', 0))
s.bind(('127.0.0.1', 0))
s.listen(1)
port = s.getsockname()[1]
return port
Copilot is powered by AI and may make mistakes. Always verify output.
Copy link
Contributor

Migration SQL Changes

Hey 👋, we've detected some migrations on this PR. Here's the SQL output for each migration, make sure they make sense:

products/streamlit/migrations/0001_initial_migration.py

BEGIN;
--
-- Create model StreamlitApp
--
CREATE TABLE "posthog_streamlitapp" ("id" uuid NOT NULL PRIMARY KEY, "name" varchar(200) NOT NULL, "description" text NOT NULL, "container_id" varchar(200) NOT NULL, "container_status" varchar(20) NOT NULL, "created_at" timestamp with time zone NOT NULL, "updated_at" timestamp with time zone NOT NULL, "created_by_id" integer NOT NULL, "team_id" integer NOT NULL);
ALTER TABLE "posthog_streamlitapp" ADD CONSTRAINT "posthog_streamlitapp_created_by_id_e1f488f8_fk_posthog_user_id" FOREIGN KEY ("created_by_id") REFERENCES "posthog_user" ("id") DEFERRABLE INITIALLY DEFERRED;
ALTER TABLE "posthog_streamlitapp" ADD CONSTRAINT "posthog_streamlitapp_team_id_4f44057a_fk_posthog_team_id" FOREIGN KEY ("team_id") REFERENCES "posthog_team" ("id") DEFERRABLE INITIALLY DEFERRED;
CREATE INDEX "posthog_streamlitapp_created_by_id_e1f488f8" ON "posthog_streamlitapp" ("created_by_id");
CREATE INDEX "posthog_streamlitapp_team_id_4f44057a" ON "posthog_streamlitapp" ("team_id");
COMMIT;

products/streamlit/migrations/0002_add_url_fields.py

BEGIN;
--
-- Add field port to streamlitapp
--
ALTER TABLE "posthog_streamlitapp" ADD COLUMN "port" integer NULL;
--
-- Add field internal_url to streamlitapp
--
ALTER TABLE "posthog_streamlitapp" ADD COLUMN "internal_url" varchar(500) DEFAULT '' NOT NULL;
ALTER TABLE "posthog_streamlitapp" ALTER COLUMN "internal_url" DROP DEFAULT;
--
-- Add field public_url to streamlitapp
--
ALTER TABLE "posthog_streamlitapp" ADD COLUMN "public_url" varchar(500) DEFAULT '' NOT NULL;
ALTER TABLE "posthog_streamlitapp" ALTER COLUMN "public_url" DROP DEFAULT;
--
-- Add field last_accessed to streamlitapp
--
ALTER TABLE "posthog_streamlitapp" ADD COLUMN "last_accessed" timestamp with time zone NULL;
COMMIT;

products/streamlit/migrations/0003_add_file_upload_fields.py

BEGIN;
--
-- Add field entrypoint_file to streamlitapp
--
ALTER TABLE "posthog_streamlitapp" ADD COLUMN "entrypoint_file" varchar(100) NULL;
--
-- Add field requirements_file to streamlitapp
--
ALTER TABLE "posthog_streamlitapp" ADD COLUMN "requirements_file" varchar(100) NULL;
--
-- Add field app_type to streamlitapp
--
ALTER TABLE "posthog_streamlitapp" ADD COLUMN "app_type" varchar(20) DEFAULT 'default' NOT NULL;
ALTER TABLE "posthog_streamlitapp" ALTER COLUMN "app_type" DROP DEFAULT;
COMMIT;

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

3 snapshot changes in total. 0 added, 3 modified, 0 deleted:

  • chromium: 0 added, 3 modified, 0 deleted (diff for shard 1)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants