mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Frontend Monitoring: Only write to custom Faro endpoint if origins are the same in iframe (#95381)
* Only enable Faro if origins are the same in iframe * Handle non-iframe case * Remove console logs * Use try catch to identify cross origin iframe * Only disable transport
This commit is contained in:
parent
712974b26c
commit
187111368a
@ -17,6 +17,14 @@ import { EchoBackend, EchoEvent, EchoEventType } from '@grafana/runtime';
|
||||
import { EchoSrvTransport } from './EchoSrvTransport';
|
||||
import { GrafanaJavascriptAgentEchoEvent, User } from './types';
|
||||
|
||||
function isCrossOriginIframe() {
|
||||
try {
|
||||
return document.location.hostname !== window.parent.location.hostname;
|
||||
} catch (e) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
export interface GrafanaJavascriptAgentBackendOptions extends BrowserConfig {
|
||||
buildInfo: BuildInfo;
|
||||
customEndpoint: string;
|
||||
@ -40,7 +48,8 @@ export class GrafanaJavascriptAgentBackend
|
||||
|
||||
const transports: BaseTransport[] = [new EchoSrvTransport()];
|
||||
|
||||
if (options.customEndpoint) {
|
||||
// If in cross origin iframe, default to writing to instance logging endpoint
|
||||
if (options.customEndpoint && !isCrossOriginIframe()) {
|
||||
transports.push(new FetchTransport({ url: options.customEndpoint, apiKey: options.apiKey }));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user