Internet-Scale analysis of AWS Cognito Security

Andres Riancho

BruCON 0x0B · Day 2

Overview

In this compelling talk from BruCON, security researcher Andres Riancho unveils the findings of an extensive, internet-scale analysis into the security posture of AWS Cognito implementations. The presentation begins with a personal anecdote: during a routine cloud security assessment, Riancho encountered Cognito for the first time. Delving into its documentation, he quickly realized its critical function: enabling end-users of applications to directly access AWS services. This capability, while powerful for developers, immediately raised red flags regarding potential misconfigurations and excessive permissions.

Watch on YouTube

Visual summary for Internet-Scale analysis of AWS Cognito Security by Andres Riancho
Visual summary for Internet-Scale analysis of AWS Cognito Security by Andres Riancho

Key moments

  1. 0:00 Introduction to Cognito and initial security assessment
  2. 2:20 How AWS Cognito identity pools grant credentials
  3. 23:00 Extracting Cognito IDs from Common Crawl with CC Lambda
  4. 30:00 Safely enumerating AWS permissions for unknown accounts
  5. 38:00 Research findings: 20% of Cognito pools misconfigured
  6. 41:40 Impact: Sensitive data exposed via Cognito misconfigurations
  7. 44:30 Why misconfigurations happen and developer recommendations
  8. 51:00 Discovery of hard-coded AWS credentials and key takeaways

Internet-Scale analysis of AWS Cognito Security

Speakers: Andres Riancho

Conference: BruCON

YouTube: https://www.youtube.com/watch?v=fxDwGg0EzTs

Overview

In this compelling talk from BruCON, security researcher Andres Riancho unveils the findings of an extensive, internet-scale analysis into the security posture of AWS Cognito implementations. The presentation begins with a personal anecdote: during a routine cloud security assessment, Riancho encountered Cognito for the first time. Delving into its documentation, he quickly realized its critical function: enabling end-users of applications to directly access AWS services. This capability, while powerful for developers, immediately raised red flags regarding potential misconfigurations and excessive permissions.

Riancho's initial assessment revealed a critical vulnerability where an AWS Cognito Identity Pool was configured with overly broad permissions, allowing for privilege escalation within the customer's AWS account. This discovery sparked a broader research question: how widespread are such misconfigurations, and is it possible to perform an internet-scale analysis to quantify this risk? The talk details the ambitious methodology employed to answer these questions, including scraping mobile application stores and the entire internet via Common Crawl to identify Cognito Identity Pool IDs, enumerate their associated permissions, and ultimately uncover a significant prevalence of insecure configurations that expose sensitive data and critical AWS resources.

The research highlights a systemic issue where developers, often following inadequate or insecure-by-default documentation examples, assign far more privileges than necessary to Cognito roles. This leads to a substantial attack surface, demonstrating that a simple misconfiguration can grant unauthorized access to sensitive S3 buckets, DynamoDB tables, and even Lambda function environment variables containing API keys and database credentials. Riancho's work serves as a stark warning to developers and security professionals alike, urging a re-evaluation of how AWS Cognito is configured and emphasizing the critical importance of the principle of least privilege.

Background

▶ Watch: Introduction to Cognito and initial security assessment (0:00)

AWS Cognito is a robust identity service provided by Amazon Web Services, primarily designed to manage user authentication and authorization for web and mobile applications. It comprises two main components: User Pools and Identity Pools. User Pools serve as a secure user directory, handling user registration, authentication, and account recovery, effectively acting as an identity provider. Identity Pools, on the other hand, are the critical component that allows application users (whether authenticated via a User Pool or another identity provider like Facebook/Google, or even unauthenticated) to obtain temporary, limited-privilege AWS credentials. These credentials enable the application's end-users to directly access other AWS services, such as Amazon S3 for file storage or Amazon DynamoDB for database interactions.

The core mechanism involves an application first authenticating a user (or allowing unauthenticated access), then exchanging a token (or simply requesting unauthenticated credentials) with an Identity Pool. In return, the Identity Pool provides temporary AWS security credentials (an access key, secret key, and session token). These credentials are bound by IAM roles and policies defined by the developer, which dictate precisely what AWS services and resources the end-user can interact with. For instance, a mobile application might allow authenticated users to upload photos to a specific S3 bucket and unauthenticated users to only view public photos. The permissions for these actions are governed by IAM roles attached to the Cognito Identity Pool.

The problem, as Riancho discovered, arises from the ease with which these IAM roles can be over-provisioned. Developers, often aiming for quick functionality or following examples that are not production-hardened, might assign overly broad permissions. The Identity Pool ID itself is a long, randomly generated string that must be hard-coded into client-side applications (mobile apps, web apps) to enable them to communicate with the correct Cognito instance. This hard-coding makes these IDs publicly discoverable. Prior work in cloud security has often focused on server-side misconfigurations or leaked credentials, but Riancho's research highlights a significant client-side vector leading to server-side compromise, demonstrating how publicly exposed Identity Pool IDs, coupled with overly permissive IAM policies, create a widespread and easily exploitable vulnerability.

Key Findings

▶ Watch: Extracting Cognito IDs from Common Crawl with CC Lambda (23:00)

Andres Riancho's internet-scale analysis of AWS Cognito yielded several significant and concerning findings, underscoring a pervasive security misconfiguration problem.

Firstly, the research successfully identified approximately 3,000 unique AWS Cognito Identity Pool IDs across the internet. The majority of these (as expected, given Cognito's target audience) were extracted from mobile applications found on platforms like Google Play and APK mirrors. A substantial number were also discovered within web applications via Common Crawl and public code repositories like GitHub.

Of the identified Identity Pool IDs, not all were immediately usable. Some were found to be non-existent (likely removed after an application was deployed), while others had invalid configurations. Crucially, around 300 Identity Pools only allowed authenticated roles, requiring an additional authentication step (e.g., via Facebook or Google) which was outside the scope of Riancho's initial unauthenticated analysis. However, a staggering 2,500 Identity Pools allowed unauthenticated access, meaning anyone could obtain temporary AWS credentials without any prior authentication, simply by knowing the Identity Pool ID.

The core of the vulnerability lay in the over-provisioning of permissions associated with these unauthenticated roles. Riancho developed a scoring system to identify insecure configurations, focusing on API calls that grant broader access than a typical application would need. His findings were alarming:

  • Approximately 20% of Cognito installations allowed unauthenticated users to perform s3:ListBuckets, meaning attackers could enumerate all S3 buckets within an AWS account, not just the specific one an application might use.
  • Around 4% of installations allowed dynamodb:ListBackups, providing insight into DynamoDB backup strategies and potentially sensitive data.
  • More generally, permissions like s3:ListObjects, dynamodb:ListTables, and lambda:ListFunctions were frequently found, enabling broad enumeration of resources.

The practical impact of these misconfigurations was severe. During the research, Riancho was able to identify access to approximately 13,000 S3 buckets across various AWS accounts. Based solely on bucket names containing keywords like "credit card," "password," or "backup," he identified 900 S3 buckets storing potentially sensitive information. Similarly, he identified 700 DynamoDB tables, with 140 of them flagged as sensitive based on their names.

Perhaps most critically, by listing Lambda functions (lambda:ListFunctions), Riancho was able to retrieve user-defined environment variables for these functions. This practice revealed 78 instances where environment variables contained highly sensitive data such as API keys, database passwords, and other secrets, effectively providing direct access to backend systems.

Beyond Cognito, the internet-scale scraping also uncovered hard-coded, highly privileged AWS credentials: 26 AWS root accounts and 38 high-privilege IAM accounts were found hard-coded in publicly accessible files, primarily from the Common Crawl dataset. These findings underscore a broader issue of credential management and public exposure.

In summary, the key findings illustrate that AWS Cognito is commonly misconfigured, leading to a significant attack surface where unauthenticated users can enumerate, and potentially access, sensitive data and resources across numerous AWS accounts. This widespread vulnerability is primarily attributed to developers assigning excessive permissions, often influenced by insecure documentation examples.

Technical Deep Dive

▶ Watch: Research findings: 20% of Cognito pools misconfigured (38:00)

The technical methodology behind Riancho's internet-scale analysis was multi-faceted, involving novel techniques for discovering AWS Cognito Identity Pool IDs and systematically enumerating their associated permissions.

The first major challenge was the discovery of Identity Pool IDs. Since these IDs are randomly generated and long, a brute-force approach was infeasible. Instead, Riancho focused on where these IDs are typically embedded:

  1. Mobile Applications: Mobile applications built with AWS SDKs require the Identity Pool ID to interact with Cognito. Riancho initially attempted to download and decompile all 2.6 million applications from the Google Play Store. However, Google Play's anti-scraping measures made this impractical. He circumvented this by leveraging a paid service (without naming it to avoid implicating them) that provided search capabilities for application metadata, allowing him to identify 13,000 applications that used the AWS SDK. These applications were then downloaded from alternative APK mirrors (e.g., APKPure), decompiled, and searched for Identity Pool IDs using regular expressions.
  2. Web Applications: Web applications also embed Identity Pool IDs, typically within JavaScript files. Directly searching common search engines for these IDs proved ineffective because search engines primarily index text content, not JavaScript embedded within <script> tags. To overcome this, Riancho turned to Common Crawl, a non-profit organization that crawls the internet monthly, making its raw HTTP responses publicly available in S3 buckets. This dataset comprises around 200 terabytes of data and 2.5 billion web pages.

Processing Common Crawl's massive dataset presented its own challenges due to its sheer size. Traditional methods like downloading the data locally were impractical. Existing tools like CC-MR (Common Crawl MapReduce) were found to be slow and unreliable. To address this, Riancho developed a custom tool called CC-Lambda. This open-source tool leverages AWS Lambda functions to perform distributed processing of the Common Crawl data.

  • CC-Lambda operates by launching 1,000 concurrent Lambda functions.
  • Each Lambda function downloads a small chunk of the Common Crawl data.
  • It decompresses the chunk and applies regular expressions to search for Identity Pool IDs.
  • Any matches found are then stored in an S3 bucket.

This highly parallelized approach allowed Riancho to process 200 terabytes of data across 64,000 chunks in approximately three hours. While incredibly efficient, a single run of CC-Lambda incurs an estimated cost of $300 USD in AWS Lambda execution fees.

  1. Other Sources: Riancho also utilized GitHub's API, Google, and Yandex search APIs to find additional Identity Pool IDs, although these yielded fewer results compared to mobile apps and Common Crawl.

Once a comprehensive list of Identity Pool IDs was obtained, the next critical step was permission enumeration. Given an Identity Pool ID, it's straightforward to obtain temporary AWS credentials using the GetCredentialsForIdentity function (as shown in AWS documentation). However, these credentials are just strings; their associated permissions need to be determined.

  • Direct IAM Query (Limited): The ideal way to check permissions is to query the IAM service using the obtained credentials. However, this only works if the credentials themselves have explicit permissions to query IAM, which is rarely the case for least-privileged application roles.
  • Brute-Force Enumeration (Primary Method): Riancho resorted to a systematic brute-force approach. This involved attempting to call a wide array of AWS API functions across various services (e.g., S3, DynamoDB, Lambda). If an API call returned a 200 OK response with content, it indicated the credentials had permission for that action. A 403 Forbidden response indicated a lack of permission.
  • Safety First: Crucially, Riancho emphasized that this brute-force was strictly limited to read-only API calls (e.g., Get, List, Describe). This was to avoid any destructive actions on AWS accounts for which no explicit permission was granted. Furthermore, he differentiated between merely listing resources (e.g., s3:ListBuckets) and reading the content of those resources (e.g., s3:GetObject). While both are "read-only," accessing customer data was explicitly avoided to prevent legal issues.

To perform this permission enumeration efficiently, Riancho found existing tools like Paku to be slow and incomplete. He therefore developed his own open-source tool, Enumerate IAM. This tool is optimized for speed and completeness, using threading and connection pooling to quickly test permissions across all AWS services. It provides a clear output indicating which API calls succeeded or failed, giving a precise picture of the permissions associated with a given set of AWS credentials. This systematic approach allowed for the large-scale analysis of permissions and the identification of the widespread misconfigurations.

Demo / Proof of Concept

▶ Watch: Impact: Sensitive data exposed via Cognito misconfigurations (41:40)

While Andres Riancho did not conduct a live, interactive demonstration during the BruCON talk, the entire presentation serves as a robust proof of concept for the feasibility and impact of his internet-scale analysis. The "demo" is effectively the methodology itself and the quantitative results of applying that methodology across the internet.

The core proof of concept lies in the successful execution of the research methodology:

  1. Identity Pool ID Extraction: The ability to systematically extract thousands of AWS Cognito Identity Pool IDs from diverse sources (mobile APKs, web pages via Common Crawl, GitHub) demonstrates that these critical identifiers are publicly discoverable. The CC-Lambda tool, in particular, proves that internet-scale scraping for specific patterns within web content is not only possible but can be done efficiently and cost-effectively (within reasonable bounds).
  2. Credential Acquisition: The ease with which temporary AWS credentials could be obtained for 2,500 unauthenticated Identity Pools by simply using the publicly available Identity Pool ID, without any form of authentication, directly validates the initial premise of the vulnerability.
  3. Permission Enumeration: The Enumerate IAM tool, by systematically brute-forcing read-only API calls, successfully demonstrated the ability to precisely map the permissions associated with each set of obtained credentials. This proved that attackers can accurately understand their access level without causing disruption.
  4. Impact and Data Exposure: The most compelling "demonstration" was the quantifiable discovery of sensitive data exposure. Riancho's ability to identify 900 S3 buckets and 140 DynamoDB tables containing sensitive information (based on naming conventions) and, more critically, to extract 78 environment variables with API keys and database passwords from Lambda functions, serves as undeniable proof of the severe consequences of these misconfigurations. This was not theoretical; it was actual data exposure identified through the research.

Riancho further reinforced the practical impact by mentioning a real-world scenario: a few days after delivering an earlier version of this talk, a person contacted him claiming to have "owned an AWS account" using the techniques presented. This anecdote, while not a direct live demo, underscores that the methodology is not just academic but immediately applicable by those with malicious intent or during authorized security assessments. The research effectively demonstrates the widespread prevalence of a critical misconfiguration and the ease with which it can be exploited to gain unauthorized access to sensitive data and resources within AWS environments.

Defensive Implications

▶ Watch: Discovery of hard-coded AWS credentials and key takeaways (51:00)

The findings from Andres Riancho's internet-scale analysis of AWS Cognito carry significant defensive implications for organizations utilizing AWS, particularly those leveraging Cognito for user authentication and authorization.

  1. Strict Adherence to the Principle of Least Privilege: This is the paramount takeaway. Developers must meticulously review and restrict the IAM policies attached to Cognito Identity Pool roles, especially for unauthenticated users. Permissions should be granted only for the absolute minimum actions and resources required for the application's functionality. For example, if an application needs to upload to a specific S3 bucket, it should only have s3:PutObject permission on that specific bucket, not s3:ListBuckets or s3:* on all buckets. The research clearly shows that 20% of installations allowing s3:ListBuckets and 4% allowing dynamodb:ListBackups are prime examples of over-permissioning.
  2. Implement Object-Level Permissions: Riancho briefly touched upon the importance of object-level permissions. Beyond just controlling access to a service or a bucket, granular control should be applied to individual objects within a resource. For instance, in an S3 bucket, a user should only be able to modify or delete objects they own, not arbitrary objects uploaded by others. While not tested in this automated research, object-level permissions add a crucial layer of defense against horizontal privilege escalation within an application's data store.
  3. Review and Secure Lambda Environment Variables: The discovery of 78 instances of sensitive data (API keys, database passwords) in Lambda environment variables accessible via Cognito misconfigurations is a critical alert. Developers must avoid storing secrets directly in environment variables, especially if those Lambda functions can be enumerated or invoked by overly permissive Cognito roles. Secure alternatives like AWS Secrets Manager or AWS Parameter Store (with appropriate KMS encryption) should be used, and access to these secret stores should also be governed by the principle of least privilege.
  4. Understand AWS Cognito Role Restrictions (and their Limitations): AWS does impose some restrictions, limiting unauthenticated roles to 26 specific services (preventing direct access to EC2 or IAM, for example). However, as Riancho demonstrated, even with these restrictions, it's still "really easy for the developer to make a mistake and expose the security of the whole AWS account" through services like S3, DynamoDB, and Lambda. Furthermore, for authenticated roles, there are no such restrictions, making it even easier to over-provision permissions for users who have simply clicked "create my user" or "authenticate with Facebook."
  5. Demand Better UI/UX from AWS: Riancho suggested that AWS should implement more proactive warnings within the console UI when developers are attempting to assign excessive permissions. An intelligent UI could identify common insecure patterns (e.g., s3:* on an unauthenticated role) and display prominent red warnings, along with explanations and references to secure configurations. While AWS has added warnings to its documentation (e.g., "this is an example, don't use it in production"), these are often overlooked. A visual, in-context warning in the UI would be far more effective.
  6. Regular Security Assessments and Automated Scans: Organizations should incorporate regular security assessments, including manual reviews and automated scans, specifically targeting Cognito configurations and associated IAM policies. Tools like Enumerate IAM (or similar internal scripts) can be used in authorized environments to identify over-privileged roles. Cloud security posture management (CSPM) tools can also help identify misconfigurations.
  7. Awareness and Training: The prevalence of these misconfigurations points to a lack of awareness among developers regarding the security implications of Cognito and IAM. Comprehensive training on secure cloud development practices, focusing on IAM policy construction and the principle of least privilege, is essential.

By addressing these defensive implications, organizations can significantly reduce their attack surface and protect sensitive data from unauthorized access stemming from common AWS Cognito misconfigurations.

Key Takeaways

  • AWS Cognito is commonly misconfigured: Approximately 20% of Cognito installations allow unauthenticated users to enumerate S3 buckets, and 4% allow listing DynamoDB backups, indicating widespread over-permissioning.
  • Easy exploitation leads to sensitive data exposure: These misconfigurations enable attackers to access sensitive data in S3 buckets, DynamoDB tables, and extract API keys and database passwords from Lambda function environment variables.
  • Internet-scale vulnerability discovery is feasible: Tools like CC-Lambda (for Common Crawl) and Enumerate IAM demonstrate that it's possible to efficiently scrape the internet for specific patterns (like Identity Pool IDs) and systematically enumerate cloud permissions at scale.
  • Documentation and UI contribute to the problem: Insecure-by-default examples in AWS documentation and a lack of proactive warnings in the AWS console UI contribute to developers assigning excessive permissions.
  • Least privilege is paramount: Developers must strictly adhere to the principle of least privilege when configuring IAM roles for Cognito, granting only the absolutely necessary permissions to specific resources.
  • Hard-coded credentials remain a threat: Beyond Cognito, the research also uncovered publicly exposed 26 root accounts and 38 high-privilege IAM accounts hard-coded online, highlighting a broader security hygiene issue.

About the Speaker(s)

Andres Riancho is a security researcher known for his work in cloud security. As presented in the talk, his expertise lies in identifying and exploiting vulnerabilities within cloud environments, often through large-scale analytical approaches. His research, including this analysis of AWS Cognito, demonstrates a deep understanding of AWS services and the common pitfalls in their configuration. Riancho is also a tool developer, having created open-source utilities like CC-Lambda and Enumerate IAM to facilitate security assessments and research.

Reviews

  • Heather Calloway (CISO) — MUST SEE ★★★★★

→ Top-rated talks at BruCON 0x0B

All talks from BruCON 0x0B