User Email should be Private
More Info:
Checks that the primary email addresses associated with a GitHub account is set to private visibility. Email addresses added to GitHub should be set to private visibility to increase privacy and prevent account reconnaissance.
Risk Level
Medium
Address
Security
Compliance Standards
Remediation
Using Console
To remediate the misconfiguration of user email being public on Github, you can follow the below steps:
- Log in to your Github account.
- Click on your profile picture in the top-right corner and select “Settings” from the dropdown menu.
- In the left-hand menu, select “Emails”.
- Under the “Primary email address” section, ensure that the checkbox next to “Keep my email address private” is checked.
- If you have any additional email addresses listed, ensure that the checkbox next to each of them is also checked.
- Click on the “Save” button at the bottom of the page to save your changes.
Following these steps will ensure that your email address is kept private on Github.
Using CLI
To remediate the misconfiguration of user email being public in Github using Github CLI, follow the below steps:
- Open the command prompt or terminal on your local machine.
- Install Github CLI, if not already installed, by following the instructions given on this link: https://cli.github.com/manual/installation
- Login to your Github account using the command:
gh auth login
- Select the appropriate authentication method and follow the prompts to complete the authentication process.
- Once authenticated, run the command
gh config set prompt private
to set the default visibility of future commits to private. - To update the visibility of all previous commits to private, navigate to the local repository directory on your machine and run the command
git filter-branch --commit-filter 'if [ "$GIT_AUTHOR_EMAIL" = "[email protected]" ]; then git commit-tree "$@" -m "$GIT_COMMIT"; else git commit-tree "$@"; fi' HEAD
- Push the updated commits to Github using the command
git push --force origin HEAD
Once these steps are completed, the user email will be set to private and all previous commits with the public email will be updated to private.
Using Python
To remediate the issue of user email being public in GitHub using Python, you can follow the below steps:
-
Install the PyGithub library using the pip command:
pip install PyGithub
-
Create a personal access token from GitHub with
user
anduser:email
scopes. -
In your Python script, import the necessary libraries:
- Set the access token as an environment variable:
- Initialize the Github object with the access token:
- Get the authenticated user:
- Get the current email visibility setting:
- If the email visibility is public, set it to private:
- Print a message to confirm that the email visibility has been updated:
- Save and run the Python script.
After following these steps, the user email visibility will be set to private in GitHub.