In GitHub Codespaces, a forwarded port is private by default, meaning only the codespace's creator can reach it after authenticating. Organization visibility opens it to org members, and public opens it to anyone with the link and no sign-in. Keep ports private unless you have a specific reason, and close them when done.
Why this matters when you code from anywhere
Working in a browser based environment is attractive from a tablet or a borrowed laptop, because the code and tools stay in the cloud. The risk moves too. A dev server you start on port 3000 is reachable from the internet through a forwarding URL, and its visibility setting decides how open that URL is.
GitHub's documentation on Codespaces security describes three visibility levels.
- Private, the default. Accessible only to the creator, after GitHub authentication. Auth cookies expire after 3 hours.
- Organization. Accessible to members of the same organization, after authentication.
- Public. Accessible to anyone, without authentication.
The same page notes that ports revert to private when removed and re-added, or when the codespace restarts. Organization owners can restrict which options are available.
What can go wrong with a public port
A public port is a public web server on your dev machine. Consider what it might serve.
- A development database admin page with default credentials.
- An app with debug mode on that prints stack traces and environment values.
- A mock service that accepts any request, now open to traffic you did not expect.
- Source maps and unminified code you were not ready to share.
Dev servers are not built for the internet. They often skip rate limits, authentication and input checks,.
When public is reasonable
Sharing a preview with a teammate, a designer or a webhook sender is a common need. If you must use public:
- Use it for a demo app with fake data only.
- Check what routes the server exposes first.
- Set it back to private as soon as you are done.
- Prefer organization visibility when the audience is colleagues. It adds authentication at no cost.
A webhook receiver is the usual reason for public. Use a test endpoint with a signature check, and rotate the secret after.
Secrets and the environment
The same Codespaces page says development environment secrets are exposed as environment variables, refreshed on creation and resume. A server that dumps environment variables on an error page, exposed on a public port, would leak them. Do not run a debug server with secrets loaded on a public port. See also cloud dev secrets on fork pull requests.
Team settings
- Restrict public port visibility at the organization level unless a team needs it.
- Review who can create environments and from which repositories.
- Remind people that opening a repository in a cloud environment runs its dev container configuration. GitHub advises opening only repositories you know and trust, since devcontainer.json can install extensions and run arbitrary commands through postCreateCommand.
For a wider decision guide, read remote dev environment or local laptop.
Quick check
Who can open a private forwarded port?
Only the codespace's creator, after GitHub authentication. GitHub's documentation says the auth cookies for private ports expire after 3 hours.
Does a public port stay public after a restart?
No. According to GitHub's documentation, ports revert to private when removed and re-added, or when the codespace restarts.
Sources
Last reviewed: 19 October 2026.