Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(decap-server): Allow the server to be run securely #7579

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
martinjagodic merged 5 commits into decaporg:main from palant:secure-decap-server
Oct 16, 2025

Conversation

Copy link
Contributor

@palant palant commented Aug 19, 2025
edited
Loading

Summary

The documentation currently says:

Note: decap-server runs an unauthenticated express server. As any client can send requests to the server, it should only be used for local development.

This is fair but it is also unnecessary. The server can be restricted in such a way that it is safe to use.

I introduced two optional environment variables to configure decap-server. The BIND_HOST variable allows binding to 127.0.0.1 rather than all IP addresses. And ORIGIN allows restricting CORS responses to a specific origin rather that allowing the API to be accessed from any server.

Note that I would have preferred making BIND_HOST=localhost the default. I didn’t want to introduce backwards incompatible changes however.

Test plan

Running npm run start still allows connecting to both http://localhost:8081/ and http://<public_ip>:8081>/. The responses contain the HTTP header Access-Content-Allow-Origin: * as before this change.

Running BIND_HOST=localhost npm run start allows connecting to http://localhost:8081/ but connections to http://<public_ip>:8081>/ are no longer possible. It’s a purely local server now.

Running ORIGIN=https://example.com npm run start changes the HTTP header in responses to Access-Content-Allow-Origin: https://example.com. The server can no longer be accessed by arbitrary websites.

Tests complain about port being number | string whereas number is expected. This is unrelated to my change but I’ve fixed it.

Checklist

Please add a x inside each checkbox:

(削除) I’ve also noticed that the script required for npm run format doesn’t actually exist. I guess npm run lint is meant here which for me errors out due to two warnings unrelated to my changes – but for some reason it succeeds in the CI runs (are these running an older lint version?). (削除ここまで)

🐈

@palant palant requested a review from a team as a code owner August 19, 2025 12:42
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds security configuration options to the decap-server to allow it to be run more securely by introducing host binding and CORS origin restrictions. The changes enable developers to restrict server access to localhost only and limit API requests to specific origins.

  • Added BIND_HOST environment variable to control which IP address the server binds to
  • Added ORIGIN environment variable to configure CORS origin restrictions instead of allowing all origins
  • Fixed type issue with port parsing to ensure it's always a number

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
packages/decap-server/src/index.ts Added host binding configuration and port parsing fix
packages/decap-server/src/middlewares/common/index.ts Updated CORS configuration to use ORIGIN environment variable
packages/decap-server/README.md Added documentation for new environment variables

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Member

@palant run npm run format to fix the formatting error

@martinjagodic martinjagodic merged commit eb9e8c5 into decaporg:main Oct 16, 2025
7 checks passed
martinjagodic added a commit to decaporg/decap-website that referenced this pull request Oct 16, 2025
Copy link
Member

@palant can you review the docs update about this PR? Is all info here correct, could something be better written? decaporg/decap-website#140

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot Copilot left review comments

@martinjagodic martinjagodic martinjagodic approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /