Skip to content

fix: rewrite Origin header to bypass CORS restriction on Screenly API#216

Open
nicomiguelino wants to merge 2 commits into
masterfrom
fix/cors-origin-header
Open

fix: rewrite Origin header to bypass CORS restriction on Screenly API#216
nicomiguelino wants to merge 2 commits into
masterfrom
fix/cors-origin-header

Conversation

@nicomiguelino
Copy link
Copy Markdown
Collaborator

@nicomiguelino nicomiguelino commented May 11, 2026

Summary

  • The Screenly API rejects requests from chrome-extension:// and moz-extension:// origins with a 403, blocking all API calls from the extension
  • Uses declarativeNetRequest to rewrite the Origin header to https://app.screenlyapp.com on all requests to api.screenlyapp.com
  • Adds rules.json static ruleset and wires it into both browser manifests and the webpack build

Notes

  • This is a temporary fix pending a backend CORS allowlist update to include browser extension origins

Test plan

  • Rebuild extension (generate_manifest chrome && npx webpack --config webpack.prod.js)
  • Load unpacked extension in Chrome, sign in with a valid token; should succeed
  • Navigate to a web page and click "Add to Screenly"; asset should be created successfully

The Screenly API's nginx CORS config only allows requests from
*.screenlyapp.com origins. Browser extension requests carry a
chrome-extension:// or moz-extension:// origin, which nginx rejects
with a 403 before the request reaches the application.

Uses declarativeNetRequest to rewrite the Origin header to
https://app.screenlyapp.com on all requests to api.screenlyapp.com,
unblocking asset creation and all other API calls from the extension.

Temporary fix until the backend CORS allowlist is updated to include
browser extension origins.
Copy link
Copy Markdown

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 addresses Screenly API requests being blocked from browser extension origins by adding a Manifest V3 declarativeNetRequest ruleset that rewrites the Origin header for requests to api.screenlyapp.com, and wires the ruleset into the build + platform manifests.

Changes:

  • Add a static DNR ruleset (src/assets/rules.json) that sets Origin: https://app.screenlyapp.com for requests to api.screenlyapp.com.
  • Update both Chrome and Firefox MV3 manifests to enable the ruleset and request declarativeNetRequest permission.
  • Update the webpack build to copy the ruleset JSON into the packaged extension under assets/.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
webpack.common.js Copies the new DNR ruleset into the build output so manifests can reference it.
src/manifest-chrome.json Enables the DNR ruleset and adds declarativeNetRequest permission for Chrome MV3.
src/manifest-firefox.json Enables the DNR ruleset and adds declarativeNetRequest permission for Firefox MV3.
src/assets/rules.json Implements the header rewrite rule to spoof Origin for Screenly API calls.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/assets/rules.json
Comment thread src/assets/rules.json Outdated
Copy link
Copy Markdown

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

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Copy link
Copy Markdown

@rusko124 rusko124 left a comment

Choose a reason for hiding this comment

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

Let's fix it on the backend side

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.

3 participants