Skip to content

Commit

Permalink
Enable Security Analysis (CodeQL) for Policy Compliance (#1593)
Browse files Browse the repository at this point in the history
  • Loading branch information
MSNev committed Jun 25, 2021
1 parent a7ee32c commit 110b22f
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 16 deletions.
11 changes: 11 additions & 0 deletions .github/codeql/codeql-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: "CodeQL config"

queries:
- uses: security-and-quality

paths-ignore:
- '**/test/'
- '**/Tests/'
- '**/dist-history/'
- '**/rollup.config.js'
- '/extensions/applicationinsights-angularplugin-js/'
72 changes: 72 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ master ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master ]
schedule:
- cron: '17 15 * * 2'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'javascript' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
# Learn more:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed

steps:
- name: Checkout repository
uses: actions/checkout@v2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
config-file: ./.github/codeql/codeql-config.yml
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
2 changes: 1 addition & 1 deletion channels/applicationinsights-channel-js/src/Offline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class OfflineListener {

if (!isUndefined(target.ononline)) {
target.ononline = _setOnline;
target.onoffline = _setOffline
target.onoffline = _setOffline;
isListening = true;

}
Expand Down
4 changes: 2 additions & 2 deletions channels/applicationinsights-channel-js/src/Sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
ITelemetryItem, IProcessTelemetryContext, IConfiguration,
_InternalMessageId, LoggingSeverity, IDiagnosticLogger, IAppInsightsCore, IPlugin,
getWindow, getNavigator, getJSON, BaseTelemetryPlugin, ITelemetryPluginChain, INotificationManager,
SendRequestReason, getGlobalInst, objForEachKey, isNullOrUndefined, arrForEach, dateNow, dumpObj, getExceptionName, getIEVersion, throwError, objKeys
SendRequestReason, getGlobalInst, objForEachKey, isNullOrUndefined, arrForEach, dateNow, dumpObj, getExceptionName, getIEVersion, throwError, objKeys, strUndefined
} from '@microsoft/applicationinsights-core-js';
import { Offline } from './Offline';
import { Sample } from './TelemetryProcessors/Sample'
Expand Down Expand Up @@ -252,7 +252,7 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
if ("withCredentials" in testXhr) {
_self._sender = _xhrSender;
_self._XMLHttpRequestSupported = true;
} else if (typeof XDomainRequest !== undefined) {
} else if (typeof XDomainRequest !== strUndefined) {
_self._sender = _xdrSender; // IE 8 and 9
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class Sample implements ISample {
_InternalMessageId.SampleRateOutOfRange,
"Sampling rate is out of range (0..100). Sampling will be disabled, you may be sending too much data which may affect your AI service level.",
{ samplingRate: sampleRate }, true);
this.sampleRate = 100;
sampleRate = 100;
}

this.sampleRate = sampleRate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ export function traverseAndReplace(target: Object, maxDepth: number, currentDept

function _sanitizeText(value: string) {
if (value) {
value = value.replace('&', '&');
value = value.replace('>', '>');
value = value.replace('<', '&lt;');
value = value.replace(/&/g, '&amp;');
value = value.replace(/>/g, '&gt;');
value = value.replace(/</g, '&lt;');
}

return value;
Expand Down
2 changes: 1 addition & 1 deletion extensions/applicationinsights-dependencies-js/src/ajax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
if (_isMonitoredXhrInstance(xhr) && !ajaxData.xhrMonitoringState.sendDone) {
_createMarkId("xhr", ajaxData);
ajaxData.requestSentTime = dateTimeUtilsNow();
xhr = _self.includeCorrelationHeaders(ajaxData, undefined, undefined, xhr);
_self.includeCorrelationHeaders(ajaxData, undefined, undefined, xhr);
ajaxData.xhrMonitoringState.sendDone = true;
}
},
Expand Down
4 changes: 2 additions & 2 deletions shared/AppInsightsCommon/src/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ export const CorrelationIdHelper: ICorrelationIdHelper = {
if (includedDomains) {
let matchExists: boolean;
arrForEach(includedDomains, (domain) => {
const regex = new RegExp(domain.toLowerCase().replace(/\./g, "\.").replace(/\*/g, ".*"));
const regex = new RegExp(domain.toLowerCase().replace(/\\/g, "\\\\").replace(/\./g, "\\.").replace(/\*/g, ".*"));
matchExists = matchExists || regex.test(requestHost);
});

Expand All @@ -378,7 +378,7 @@ export const CorrelationIdHelper: ICorrelationIdHelper = {
}

for (let i = 0; i < excludedDomains.length; i++) {
const regex = new RegExp(excludedDomains[i].toLowerCase().replace(/\./g, "\.").replace(/\*/g, ".*"));
const regex = new RegExp(excludedDomains[i].toLowerCase().replace(/\\/g, "\\\\").replace(/\./g, "\\.").replace(/\*/g, ".*"));
if (regex.test(requestHost)) {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions shared/AppInsightsCore/src/JavaScriptSDK/CookieMgr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ export function safeGetCookieMgr(core: IAppInsightsCore, config?: IConfiguration
if (core) {
// Always returns an instance
cookieMgr = core.getCookieMgr();
} else if(config) {
let cookieCfg = (config ||{}).cookieCfg;
} else if (config) {
let cookieCfg = config.cookieCfg;
if (cookieCfg[strConfigCookieMgr]) {
cookieMgr = cookieCfg[strConfigCookieMgr];
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class DiagnosticLogger implements IDiagnosticLogger {
if (_self.enableDebugExceptions()) {
throw message;
} else {
if (!isUndefined(message) && !!message && !isUndefined(message.message)) {
if (!isUndefined(message.message)) {
const logLevel = _self.consoleLoggingLevel();
if (isUserAct) {
// check if this message type was already logged to console for this page view and if so, don't log it again
Expand Down
2 changes: 1 addition & 1 deletion shared/AppInsightsCore/src/JavaScriptSDK/PerfManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ const doPerfActiveKey = "CoreUtils.doPerf";
export function doPerf<T>(mgrSource: IPerfManagerProvider | IPerfManager, getSource: () => string, func: (perfEvt?: IPerfEvent) => T, details?: () => any, isAsync?: boolean) {
if (mgrSource) {
let perfMgr: IPerfManager = mgrSource as IPerfManager;
if (perfMgr && isFunction(perfMgr["getPerfMgr"])) {
if (isFunction(perfMgr["getPerfMgr"])) {
// Looks like a perf manager provider object
perfMgr = perfMgr["getPerfMgr"]()
}
Expand Down
3 changes: 1 addition & 2 deletions tools/release-tools/setVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ function calculateVersion(rootVersion) {
parts = ["0", "0", "0"];
}

// Set the default version to the current
newVersion = preRelParts[0];
let newVersion;

if (newVer) {
newVersion = newVer;
Expand Down

0 comments on commit 110b22f

Please sign in to comment.