Skip to content

Commit

Permalink
Prebid Core: Start Github CoreQL Code Scans (prebid#8923)
Browse files Browse the repository at this point in the history
* Create codeql-analysis.yml

* Update codeql-analysis.yml

* Update instream.html

* Update emx_digitalBidAdapter_spec.js

* Update index.js

* Update index.js

* Update index.js

* Merge master  (prebid#8873)

* Readme: remove dead dev dependency and maintenance badges (prebid#8849)

* Readme: remove dead dev dependency badge and issue

* Remove maintainability and add back issues

* Prebid 7.11.0 release

* Increment version to 7.12.0-pre

* Adriver Bid and Id Modules: buyerid bug fix (prebid#8768)

* initial commit

* adriver id submodule add

* add id system tests, fix adriver bid adapter tests

* adriver: fix buyerid

* remarks fixing

* removal of excess

* delete custom parameter

* bug fixes

* handle native response privacy link (prebid#8838)

Co-authored-by: Zicong Zhou <[email protected]>

* Criteo Bid Adapter - Add support for banner+native multiformat ad unit (prebid#8842)

Previously, the use of a native adunit was exclusive with the banner type.

* Ras Bid Adapter: support for SlotSequence parameter (prebid#8792)

* add rasbidadapter pos param

* Read pos off the adunit

* rename conflicting pos parameter for clarity

* Improve Digital adapter: refactor code to align with latest RAZR creative tags (prebid#8827)

* IX Bid Adapter: Native OpenRTB Request Support (prebid#8853)

* fix native click trackers to only fire on click

* fix unit tests for ix

* remove version for native requests

* remove unnecessary request conversion

Co-authored-by: Zicong Zhou <[email protected]>

* Update Sonobi adapter with GVLID (prebid#8860)

* dgkeyword RTD provider: fix tests causing ID5 test failures (prebid#8862)

* Id5 id configurable fetch flow (prebid#8784)

Co-authored-by: Paweł Kowalski <[email protected]>

* NextMillenium Bid Adapter: Remove ortb2 referrerInfo (prebid#8868)

* remove ortb2, get device/site manually

* updated tests

* remove fallbacks

* no need to craete variable if there is no fallback (return in place)

* removed one test case

Co-authored-by: Yakov Klein <[email protected]>

* adserver.js : remove unused code (prebid#8855)

* Displayio Bid Adapter: custom render; fix eids payload (prebid#8847)

* Custom render; call pubmatic get user id function is removed

* use refererInfo; remove call createEidsArray

* VidCrunch LLC bidder (prebid#8872)

Co-authored-by: Chris Huie <[email protected]>
Co-authored-by: Prebid.js automated release <[email protected]>
Co-authored-by: m-oranskaya <[email protected]>
Co-authored-by: Love Sharma <[email protected]>
Co-authored-by: Zicong Zhou <[email protected]>
Co-authored-by: Léonard Labat <[email protected]>
Co-authored-by: wsusrasp <[email protected]>
Co-authored-by: Catalin Ciocov <[email protected]>
Co-authored-by: Mike Miller <[email protected]>
Co-authored-by: Demetrio Girardi <[email protected]>
Co-authored-by: Scott Menzer <[email protected]>
Co-authored-by: Paweł Kowalski <[email protected]>
Co-authored-by: JacobKlein26 <[email protected]>
Co-authored-by: Yakov Klein <[email protected]>
Co-authored-by: caseywhitmire <[email protected]>
Co-authored-by: philan15 <[email protected]>
Co-authored-by: Gena <[email protected]>

* Revert "Merge master  (prebid#8873)" (prebid#8911)

This reverts commit 07c5369.

* Update code scan config

* Update viewability

* Sanitize JSON for adgeneration

Co-authored-by: Patrick McCann <[email protected]>
Co-authored-by: Chris Huie <[email protected]>
Co-authored-by: Prebid.js automated release <[email protected]>
Co-authored-by: m-oranskaya <[email protected]>
Co-authored-by: Love Sharma <[email protected]>
Co-authored-by: Zicong Zhou <[email protected]>
Co-authored-by: Léonard Labat <[email protected]>
Co-authored-by: wsusrasp <[email protected]>
Co-authored-by: Catalin Ciocov <[email protected]>
Co-authored-by: Mike Miller <[email protected]>
Co-authored-by: Scott Menzer <[email protected]>
Co-authored-by: Paweł Kowalski <[email protected]>
Co-authored-by: JacobKlein26 <[email protected]>
Co-authored-by: Yakov Klein <[email protected]>
Co-authored-by: caseywhitmire <[email protected]>
Co-authored-by: philan15 <[email protected]>
Co-authored-by: Gena <[email protected]>
  • Loading branch information
18 people committed Feb 8, 2023
1 parent ca6d68e commit e29e828
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 20 deletions.
4 changes: 4 additions & 0 deletions .github/codeql/codeql-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
paths:
- src
- modules
- libraries
73 changes: 73 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# 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: '22 11 * * 0'

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', 'ruby' ]
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

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

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
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.

# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality


# 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@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
4 changes: 2 additions & 2 deletions modules/adgenerationBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {tryAppendQueryString, getBidIdParameter} from '../src/utils.js';
import {tryAppendQueryString, getBidIdParameter, escapeUnsafeChars} from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER, NATIVE} from '../src/mediaTypes.js';
import {config} from '../src/config.js';
Expand Down Expand Up @@ -230,7 +230,7 @@ function insertVASTMethodForAPV(targetId, vastXml) {
};
let script = document.createElement(`script`);
script.type = 'text/javascript';
script.innerHTML = `(function(){ new APV.VideoAd(${JSON.stringify(apvVideoAdParam)}).load('${vastXml.replace(/\r?\n/g, '')}'); })();`;
script.innerHTML = `(function(){ new APV.VideoAd(${escapeUnsafeChars(JSON.stringify(apvVideoAdParam))}).load('${vastXml.replace(/\r?\n/g, '')}'); })();`;
return script.outerHTML;
}

Expand Down
2 changes: 1 addition & 1 deletion modules/consentManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function lookupIabConsent({onSuccess, onError}) {
if (json[cmpDataPkgName] && json[cmpDataPkgName].callId) {
const payload = json[cmpDataPkgName];
// TODO - clean up this logic (move listeners?); we have duplicate messages responses because 2 eventlisteners are active from the 2 cmp requests running in parallel
if (typeof cmpCallbacks[payload.callId] !== 'undefined') {
if (cmpCallbacks.hasOwnProperty(payload.callId)) {
cmpCallbacks[payload.callId](payload.returnValue, payload.success);
}
}
Expand Down
2 changes: 1 addition & 1 deletion modules/consentManagementUsp.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function lookupUspConsent({onSuccess, onError}) {
function readPostMessageResponse(event) {
const res = event && event.data && event.data.__uspapiReturn;
if (res && res.callId) {
if (typeof uspapiCallbacks[res.callId] !== 'undefined') {
if (uspapiCallbacks.hasOwnProperty(res.callId)) {
uspapiCallbacks[res.callId](res.returnValue, res.success);
delete uspapiCallbacks[res.callId];
}
Expand Down
28 changes: 14 additions & 14 deletions modules/viewability.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function init() {
listenMessagesFromCreative();
}

const observers = {};
const observers = new Map();

function isValid(vid, element, tracker, criteria) {
if (!element) {
Expand All @@ -36,7 +36,7 @@ function isValid(vid, element, tracker, criteria) {
return false;
}

if (!vid || observers[vid]) {
if (!vid || observers.has(vid)) {
logWarn(`${MODULE_NAME}: must provide an unregistered vid`, vid);
return false;
}
Expand All @@ -46,7 +46,7 @@ function isValid(vid, element, tracker, criteria) {

function stopObserving(observer, vid, element) {
observer.unobserve(element);
observers[vid].done = true;
observers.get(vid).done = true;
}

function fireViewabilityTracker(element, tracker) {
Expand Down Expand Up @@ -96,21 +96,21 @@ export function startMeasurement(vid, element, tracker, criteria) {
viewable = entries[0].isIntersecting;

if (viewable) {
observers[vid].timeoutId = window.setTimeout(() => {
observers.get(vid).timeoutId = window.setTimeout(() => {
viewabilityCriteriaMet(observer, vid, element, tracker);
}, criteria.timeInView);
} else if (observers[vid].timeoutId) {
window.clearTimeout(observers[vid].timeoutId);
} else if (observers.get(vid).timeoutId) {
window.clearTimeout(observers.get(vid).timeoutId);
}
};

observer = new IntersectionObserver(stateChange, options);
observers[vid] = {
observers.set(vid, {
observer: observer,
element: element,
timeoutId: null,
done: false,
};
});

observer.observe(element);

Expand All @@ -122,19 +122,19 @@ export function startMeasurement(vid, element, tracker, criteria) {
* @param {string} vid unique viewability identifier
*/
export function stopMeasurement(vid) {
if (!vid || !observers[vid]) {
if (!vid || !observers.has(vid)) {
logWarn(`${MODULE_NAME}: must provide a registered vid`, vid);
return;
}

observers[vid].observer.unobserve(observers[vid].element);
if (observers[vid].timeoutId) {
window.clearTimeout(observers[vid].timeoutId);
observers.get(vid).observer.unobserve(observers.get(vid).element);
if (observers.get(vid).timeoutId) {
window.clearTimeout(observers.get(vid).timeoutId);
}

// allow the observer under this vid to be created again
if (!observers[vid].done) {
delete observers[vid];
if (!observers.get(vid).done) {
observers.delete(vid);
}
}

Expand Down
27 changes: 27 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1381,3 +1381,30 @@ export function setScriptAttributes(script, attributes) {
}
}
}

/**
* Encode a string for inclusion in HTML.
* See https://pragmaticwebsecurity.com/articles/spasecurity/json-stringify-xss.html and
* https://codeql.github.com/codeql-query-help/javascript/js-bad-code-sanitization/
* @return {string}
*/
export const escapeUnsafeChars = (() => {
const escapes = {
'<': '\\u003C',
'>': '\\u003E',
'/': '\\u002F',
'\\': '\\\\',
'\b': '\\b',
'\f': '\\f',
'\n': '\\n',
'\r': '\\r',
'\t': '\\t',
'\0': '\\0',
'\u2028': '\\u2028',
'\u2029': '\\u2029'
};

return function(str) {
return str.replace(/[<>\b\f\n\r\t\0\u2028\u2029\\]/g, x => escapes[x])
}
})();
4 changes: 2 additions & 2 deletions test/pages/instream.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<title>Prebid.js video adUnit example</title>

<!-- videojs -->
<link rel="stylesheet" href="http://vjs.zencdn.net/5.9.2/video-js.css">
<script type="text/javascript" src="http://vjs.zencdn.net/5.9.2/video.js"></script>
<link rel="stylesheet" href="https://vjs.zencdn.net/5.9.2/video-js.css">
<script type="text/javascript" src="https://vjs.zencdn.net/5.9.2/video.js"></script>

<!-- videojs-vast-vpaid -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/videojs-vast-vpaid/2.0.2/videojs.vast.vpaid.min.css" rel="stylesheet">
Expand Down

0 comments on commit e29e828

Please sign in to comment.