fix: add consistent CORS security warnings to example servers#1728
Open
hhhashexe wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
fix: add consistent CORS security warnings to example servers#1728hhhashexe wants to merge 1 commit intomodelcontextprotocol:mainfrom
hhhashexe wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
Three example servers lacked the security warnings present in simpleStreamableHttp.ts and authServer.ts: - ssePollingExample.ts: used bare cors() with no origin restriction or warning. Now uses explicit origin: '*' with WARNING comments and exposes required MCP headers. - honoWebStandardStreamableHttp.ts: had origin: '*' but no WARNING comment indicating this is demo-only. - elicitationUrlExample.ts: had origin: '*' with credentials: true (rejected by browsers per CORS spec) and no warning. Added WARNING comments and a NOTE about the credentials/wildcard incompatibility. All three now match the comment pattern established in simpleStreamableHttp.ts for consistency. Closes modelcontextprotocol#1683
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three example server files lacked the CORS security warnings that are already present in
simpleStreamableHttp.tsandauthServer.ts. Example code is frequently copy-pasted into production, so insecure defaults without clear warnings pose a real risk.Closes #1683
Changes
ssePollingExample.tsapp.use(cors())— no origin restriction, no warning, no exposed headersorigin: '*'withWARNINGcomments andexposedHeadersmatching other exampleshonoWebStandardStreamableHttp.tsorigin: '*'with comment "Enable CORS for all origins" but no WARNINGsimpleStreamableHttp.tspatternelicitationUrlExample.tsorigin: '*'withcredentials: trueand no warning. Note:credentials: truewith wildcard origin is rejected by browsers per the CORS speccredentials/wildcard incompatibilityPattern
All three files now use the same comment pattern established in
simpleStreamableHttp.ts:Testing
No behavior changes — only comments and the bare
cors()→ explicitcors({ origin: '*' })inssePollingExample.ts(functionally equivalent).