-
Notifications
You must be signed in to change notification settings - Fork 5
Legg til vitest browser mode #6429
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
base: master
Are you sure you want to change the base?
Conversation
event.waitUntil(self.clients.claim()) | ||
}) | ||
|
||
self.addEventListener('message', async function (event) { | ||
const clientId = event.source.id | ||
addEventListener('message', async function (event) { |
Check warning
Code scanning / CodeQL
Missing origin verification in `postMessage` handler Medium
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 8 days ago
To fix the issue, we need to verify the origin
of the incoming message
event to ensure it comes from a trusted source. This involves adding a check for the event.origin
property against a list of allowed origins. If the origin is not trusted, the handler should return early without processing the message.
The fix will involve:
- Defining a list of trusted origins (e.g.,
const TRUSTED_ORIGINS = ['https://www.example.com'];
). - Adding a conditional check at the beginning of the
message
event handler to verify theevent.origin
against the trusted origins. - If the origin is not in the trusted list, the handler will return early.
-
Copy modified lines R24-R28
@@ -23,2 +23,7 @@ | ||
addEventListener('message', async function (event) { | ||
const TRUSTED_ORIGINS = ['https://www.example.com']; | ||
if (!TRUSTED_ORIGINS.includes(event.origin)) { | ||
return; | ||
} | ||
|
||
const clientId = Reflect.get(event.source || {}, 'id') |
|
mswTest må no brukast for testar som krev msw-handlers. Denne wrappar applyRequestHandlers som blir brukt av jsdom-testar, og setupWorker som må brukast for browser-mode.
Det er rundt 20-30 testar som feilar av ukjent årsak. Mange av desse køyrer ok om ein rekøyrer dei, så usikker på årsak. Håpar det ligg i vitest, men skal få sett meir på det etterkvart. Per no brukar me ikkje browser-mode i CI så det er ikkje krise at nokre testar feilar.
Så får me sjå om browser-mode blir nyttig. Forhåpentlegvis så vil det komme forbedringar i UI'et og kanskje ein bedre integrasjon i storybook. Evt bør me kanskje heller sjå på playwright eller play-funksjonaliteten i storybook