Skip to content
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

Limit Webpack dev server allowed CORS origins #11866

Merged
merged 2 commits into from
Feb 11, 2025
Merged

Limit Webpack dev server allowed CORS origins #11866

merged 2 commits into from
Feb 11, 2025

Conversation

aduth
Copy link
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.

@@ -1,4 +1,4 @@
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
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
2 checks passed
@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