Skip to content

Limit Webpack dev server allowed CORS origins#11866

Merged
aduth merged 2 commits intomainfrom
aduth-rm-cors
Feb 11, 2025
Merged

Limit Webpack dev server allowed CORS origins#11866
aduth merged 2 commits intomainfrom
aduth-rm-cors

Conversation

@aduth
Copy link
Copy Markdown
Contributor

@aduth aduth commented Feb 11, 2025

🛠 Summary of changes

Updates local Webpack development server to limit allowed origins for CORS to the expected local web server origin (usually http://localhost:3000).

This is motivated by a security advisory GHSA-67mh-4wv8-2f99 which addresses a similar issue in a package that we don't use in the IdP.

The risk here is fairly minimal, since the dev server only serves files out of the public/ directory.

An original approach considered disabling CORS altogether. CORS is enabled because we specify the crossorigin attribute on script assets in local development, and we specify this attribute because it allows for better error messages in pages using React.js (see #6126).

📜 Testing Plan

Verify in local development that there are no issues loading JavaScript. It should be pretty evident if JavaScript is not working, because the "Here's how you know" USA banner will display as expanded by default.

web: WEBPACK_PORT=${WEBPACK_PORT:-3035} bundle exec rackup config.ru --port ${PORT:-3000} --host ${FOREMAN_HOST:-${HOST:-localhost}}
worker: bundle exec good_job start
js: WEBPACK_PORT=${WEBPACK_PORT:-3035} yarn webpack --watch
js: WEBPACK_PORT=${WEBPACK_PORT:-3035} ORIGIN_PORT=${ORIGIN_PORT:-3000} yarn webpack --watch
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The reason for creating a separate environment variable copying PORT is that the behavior of Foreman is to assign a different port value for each process (see ddollar/foreman#110, ddollar/foreman#714). If we just passed PORT, it would actually assign 3200, since this is the third process in the Procfile.

@aduth aduth merged commit 680134d into main Feb 11, 2025
@aduth aduth deleted the aduth-rm-cors branch February 11, 2025 16:54
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