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

Core: Fix sua low entropy check for empty objects #10167

Merged
merged 1 commit into from
Jul 12, 2023

Conversation

pycnvr
Copy link
Collaborator

@pycnvr pycnvr commented Jun 29, 2023

Type of change

  • Bugfix

Description of change

Device.sua is not generated by default because window.navigator.userAgentData is mistakenly identified as empty. On Chrome, this object has read-only properties that doesn't work with hasOwnProperty checks.

https://jsfiddle.net/bwspyja9/

let uaData = window.navigator.userAgentData;

function isEmpty(obj) {
   if (!obj) return true;
   for (let x in obj) {
      if (Object.prototype.hasOwnProperty.call(obj, x)) return false;
   }
   return true;
}

function isReallyEmpty(obj) {
   if (!obj) return true;
   for (let x in obj) return false;
   return true;
}

console.log(uaData);
console.log('is empty? ', isEmpty(uaData));
console.log('is really empty? ', isReallyEmpty(uaData));
 "Running fiddle"
[object NavigatorUAData] {
  brands: [{
  brand: "Not.A/Brand",
  version: "8"
}, {
  brand: "Chromium",
  version: "114"
}, {
  brand: "Google Chrome",
  version: "114"
}],
  getHighEntropyValues: function getHighEntropyValues() { [native code] },
  mobile: false,
  platform: "macOS",
  toJSON: function toJSON() { [native code] }
}
"is empty? ", true
"is really empty? ", false

Other information

@pycnvr
Copy link
Collaborator Author

pycnvr commented Jul 6, 2023

Thanks @dgirardi!
@ChrisHuie Is it ok to merge now?

@patmmccann patmmccann merged commit 89a1e1e into prebid:master Jul 12, 2023
2 checks passed
santii7395 pushed a commit to themaven-net/Prebid.js that referenced this pull request Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants