feat(apigateway): add check for secrets in REST API stage variables#11188
Open
chirag1206 wants to merge 1 commit into
Open
feat(apigateway): add check for secrets in REST API stage variables#11188chirag1206 wants to merge 1 commit into
chirag1206 wants to merge 1 commit into
Conversation
Adds a new check apigateway_restapi_no_secrets_in_stage_variables that scans API Gateway REST API stage variables for hardcoded secrets such as API keys, passwords, and tokens using the detect-secrets library. Also extends the Stage model in apigateway_service.py to capture and store stage variables from the AWS API response. Relates to prowler-cloud#3085
Contributor
|
✅ Conflict Markers Resolved All conflict markers have been successfully resolved in this pull request. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a new check
apigateway_restapi_no_secrets_in_stage_variablesthat scans API Gateway REST API stage variables for hardcoded secrets such as API keys, passwords, and tokens using thedetect-secretslibrary.Also extends the
Stagemodel inapigateway_service.pyto capture and store stage variables from the AWS API response.Relates to #3085
Context
API Gateway stage variables are key-value pairs referenced in integration requests and mapping templates. Developers sometimes hardcode credentials directly into these variables instead of using Secrets Manager, leaving them exposed in plaintext in the AWS control plane. This check detects those hardcoded secrets using the same
detect-secretspattern already used across Lambda, CodeBuild, Step Functions, and other services.Description
apigateway_service.py: Addedvariables: Optional[dict] = {}field to theStagemodel and populated it viastage.get("variables", {})in_get_stages()— 2 line change, no new API calls needed sinceget_stagesalready returns variables in its responseapigateway_restapi_no_secrets_in_stage_variables: iterates all REST API stages, scans the variables dict usingdetect_secrets_scanwithjson.dumps, follows the same pattern asawslambda_function_no_secrets_in_variablesand the recently merged Step Functions check (feat(stepfunctions): add check for secrets in state machine definition #10570)Steps to review
prowler/providers/aws/services/apigateway/apigateway_service.py— 2 line change addingvariablesfield toStagemodelprowler/providers/aws/services/apigateway/apigateway_restapi_no_secrets_in_stage_variables/— new check folder with 3 files (__init__.py, check.py, metadata.json)tests/providers/aws/services/apigateway/apigateway_restapi_no_secrets_in_stage_variables/— 4 tests covering: no REST APIs, stage with no variables (PASS), stage with safe variables (PASS), stage with hardcoded AWS keyAKIAIOSFODNN7EXAMPLE(FAIL)pytest tests/providers/aws/services/apigateway/ -vto verify — 43 passed, 0 failedChecklist
Community Checklist
SDK/CLI
apigateway:GetStagesis already invoked by the existing service. Stage variables are returned in the same API response, so no additional IAM permissions are required.UI
API
License
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.