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

Check for secure context before installing web app #421

Merged
merged 1 commit into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions extension/src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ browser.notifications.onClicked.addListener(async notification => {
// == CONTENT SCRIPT HANDLING

// Detect manifest sent from content script
browser.runtime.onMessage.addListener(async ({ manifestUrl, documentUrl }, { tab }) => {
browser.runtime.onMessage.addListener(async ({ manifestUrl, documentUrl, isSecureContext }, { tab }) => {
manifestUrl = manifestUrl ? new URL(manifestUrl) : undefined
documentUrl = documentUrl ? new URL(documentUrl) : undefined

Expand All @@ -56,8 +56,8 @@ browser.runtime.onMessage.addListener(async ({ manifestUrl, documentUrl }, { tab
return
}

// If both manifest and the page are loaded over HTTPS, site is a valid web app
let isValidPwa = manifestUrl && manifestUrl.protocol === 'https:' && documentUrl.protocol === 'https:'
// If both manifest and the page are loaded over HTTPS, and we are in a secure context, site is a valid web app
let isValidPwa = manifestUrl && manifestUrl.protocol === 'https:' && documentUrl.protocol === 'https:' && isSecureContext

// Force show or hide the page action depending on user preference
const settingsDisplayPageAction = (await browser.storage.local.get(PREF_DISPLAY_PAGE_ACTION))[PREF_DISPLAY_PAGE_ACTION]
Expand Down
4 changes: 2 additions & 2 deletions extension/src/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const isAppleMaskIcon = link => link.getAttribute('rel').toLowerCase().includes(
const manifestElement = document.querySelector('link[rel=manifest]')
const manifestUrl = manifestElement ? new URL(manifestElement.getAttribute('href'), document.baseURI) : null

// Send the initial manifest and document URLs on the page load
browser.runtime.sendMessage({ manifestUrl: manifestUrl?.href, documentUrl: document.location.href })
// Send the secure context state, initial manifest and document URLs on the page load
browser.runtime.sendMessage({ manifestUrl: manifestUrl?.href, documentUrl: document.location.href, isSecureContext })

// Send the current manifest and document URLs on request
browser.runtime.onMessage.addListener((message, _, sendResponse) => {
Expand Down