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

[main] support adding cross origin resource policy for #1851 #2423

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -2716,14 +2716,12 @@ export class SenderTests extends AITestClass {
let id = this._sender.identifier;
let coreConfig = {
instrumentationKey: 'abc',
crossOriginResourcePolicy: "cross-origin",
isBeaconApiDisabled: true,
customHeaders: [
{
header: 'testHeader',
value: 'testValue'
extensionConfig: {
[this._sender.identifier]: {
corsPolicy: "cross-origin",
}
]
}
}
core.initialize(coreConfig, [this._sender]);

Expand Down Expand Up @@ -2754,7 +2752,7 @@ export class SenderTests extends AITestClass {
QUnit.assert.notOk(this._getXhrRequests()[0].requestHeaders.hasOwnProperty('testHeader'));

// dynamic change
core.config.crossOriginResourcePolicy = "same-origin";
core.config.extensionConfig[this._sender.identifier].corsPolicy = "same-origin";
this.clock.tick(1);
try {
this._sender.processTelemetry(telemetryItem, null);
Expand Down
2 changes: 1 addition & 1 deletion channels/applicationinsights-channel-js/src/Interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export interface ISenderConfig {
*
* @since 3.3.3
*/
crossOriginResourcePolicy?: string;
corsPolicy?: string;
}

export interface IBackendResponse {
Expand Down
7 changes: 4 additions & 3 deletions channels/applicationinsights-channel-js/src/Sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,13 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControls {
if (config.storagePrefix){
utlSetStoragePrefix(config.storagePrefix);
}
if (config.crossOriginResourcePolicy){
this.addHeader(CrossOriginResourcePolicyHeader, config.crossOriginResourcePolicy);
}

let ctx = createProcessTelemetryContext(null, config, core);
// getExtCfg only finds undefined values from core
let senderConfig = ctx.getExtCfg(identifier, defaultAppInsightsChannelConfig);
if (senderConfig.corsPolicy){
this.addHeader(CrossOriginResourcePolicyHeader, senderConfig.corsPolicy);
siyuniu-ms marked this conversation as resolved.
Show resolved Hide resolved
}
if(isPromiseLike(senderConfig.endpointUrl)) {
// if it is promise, means the endpoint url is from core.endpointurl
senderConfig.endpointUrl = config.endpointUrl as any;
Expand Down
14 changes: 0 additions & 14 deletions shared/AppInsightsCommon/src/Interfaces/IConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,20 +389,6 @@ export interface IConfig {
* This URL takes precedence over the 'config.endpointUrl' and any endpoint in the connection string.
*/
userOverrideEndpointUrl?: string;

/**
* [Optional] Specifies the Cross-Origin Resource Policy (CORP) for the endpoint.
* This value is included in the response header as `Cross-Origin-Resource-Policy`,
* which helps control how resources can be shared across different origins.
*
* Possible values:
* - `same-site`: Allows access only from the same site.
* - `same-origin`: Allows access only from the same origin (protocol, host, and port).
* - `cross-origin`: Allows access from any origin.
*
* @since 3.3.3
*/
crossOriginResourcePolicy?: string;
}

export class ConfigurationManager {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { normalizeJsName } from "./HelperFuncs";
import { STR_EMPTY } from "./InternalConstants";
import { newId } from "./RandomHelper";

const version = "#version#";
const version = '3.3.3';
let instanceName = "." + newId(6);
let _dataUid = 0;

Expand Down
Loading