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

navigator.userAgent in CognitoUser.js is raising a Chrome Audit notification #9957

Closed
3 tasks done
jrobbins-LiveData opened this issue Jun 2, 2022 · 5 comments
Closed
3 tasks done
Assignees
Labels
amazon-cognito-identity-js Used for issues related to this specific package within the monorepo Auth Related to Auth components/category bug Something isn't working

Comments

@jrobbins-LiveData
Copy link

Before opening, please confirm:

JavaScript Framework

Not applicable

Amplify APIs

Not applicable

Amplify Categories

No response

Environment information

# Put output below this line
  System:
    OS: Windows 10 10.0.19044
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz
    Memory: 5.15 GB / 31.73 GB
  Binaries:
    Node: 16.6.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.18 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 8.5.3 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (102.0.1245.30)
    Internet Explorer: 11.0.19041.1566
  npmPackages:
    cdk-dia: ^0.6.1 => 0.6.1
  npmGlobalPackages:
    @aws-amplify/cli: 7.6.19
    @mhlabs/cfn-diagram: 1.1.33
    @openapitools/openapi-generator-cli: 2.5.1
    aws-cdk: 2.26.0
    npm: 8.5.3
    python: 0.0.4
    serve: 13.0.2
    yarn: 1.22.18

Describe the bug

const userAgent = isBrowser ? navigator.userAgent : 'nodejs';
triggers Audit usage of navigator.userAgent, navigator.appVersion, and navigator.platform from Chrome.

Expected behavior

Following Chrome's suggestion "To fix this issue, replace the usage of navigator.userAgent, navigator.appVersion, and navigator.platform with feature detection, progressive enhancement, or migrate to navigator.userAgentData." should result in removing this flagged "Audit Issue", reducing concerns from security reviews and audits about amazon-cognito-identity.js.

Reproduction steps

Any web app using amazon-cognito-identity.js should exhibit the Audit Issue.

Code Snippet

// Put your code below this line.

Log output

// Put your logs below this line


aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

While amazon-cognito-identity.js's use of navigator.userAgent in CognitoUser.js appears safe with respect to the announcing browser "reduction" (https://www.chromium.org/updates/ua-reduction/#reduced-navigatoruseragent-values), such Audit Issues cause concern for those of us using Cognito in secure environments with apps subject to security reviews and audits. Rather than having to give a lengthy explanation why this particular Audit Issue isn't really a concern, it is much much easier to not have to explain it to begin with!

There is hopefully an alternative way for the code to determine the DeviceName rather than using this property.

@chrisbonifacio chrisbonifacio added the amazon-cognito-identity-js Used for issues related to this specific package within the monorepo label Jun 2, 2022
@chrisbonifacio chrisbonifacio self-assigned this Jun 2, 2022
@chrisbonifacio
Copy link
Member

Hi @jrobbins-LiveData 👋 thank you for raising this issue.

We were able to consistently reproduce the issue as you mentioned and the team will be looking into how it can be addressed within our library. We've noted the mention of a User Agent Client Hints API, which according to Chromium, will help to solve the problems of browser fingerprinting and complex string parsing.

@chrisbonifacio chrisbonifacio added Auth Related to Auth components/category and removed p1 labels Jun 2, 2022
@jrobbins-LiveData
Copy link
Author

Hi @chrisbonifacio. I worry about the apparent lack of cross-browser support for that API, at least as listed here. But if you restrict its use to only when running on Chrome, that would work. (Sorry if that is obvious!)

@chrisbonifacio
Copy link
Member

chrisbonifacio commented Jun 3, 2022

@jrobbins-LiveData that's a good point. We could make it backwards compatible until browser support is better by checking for navigator.userAgentData first and, if not found, fallback to navigator.userAgent.

if (navigator.userAgentData) {
  // use new hints
} else {
  // fall back to user-agent string
}

@chrisbonifacio chrisbonifacio added investigating This issue is being investigated bug Something isn't working and removed investigating This issue is being investigated labels Jun 6, 2022
@nickarocho nickarocho added this to the Cognito Pluggable milestone Jun 14, 2022
@nickarocho nickarocho self-assigned this Jun 14, 2022
@nickarocho
Copy link
Contributor

I'm also able to consistently reproduce the issue with a super simple implementation of amazon-cognito-identity-js in a React app.

I'll begin looking into solutions and will keep you updated along the way. Thanks for pointing this out, @jrobbins-LiveData!

Screen Shot 2022-06-16 at 3 11 26 PM

@nadetastic
Copy link
Member

With the release of the latest major version of Amplify (aws-amplify@>6), this issue should now be resolved! Please refer to our release announcement, migration guide, and documentation for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
amazon-cognito-identity-js Used for issues related to this specific package within the monorepo Auth Related to Auth components/category bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants