Gratipay rails secret token (secret_key_base) publicly exposed in GitHub
The Rails secret_key_base was committed to a public GitHub repository. An attacker who knows this secret could forge signed cookies and impersonate any user.
- Disclosed after under an hour
Summary
Gratipay's Rails secret token is publicly exposed on GitHub. Knowing the secret token allows an attacker to impersonate any user in the application.
Thanks to EdOverflow for sharing the tips for finding security issues in GitHub projects, below is the referenced github for the analysis.
Description
The secret_token.rb file's content includes a long randomized string which is used to verify the integrity of signed cookies (such as user sessions when people are signed into your web app).
Documentation says:
Use your existing
secret_key_basefrom thesecret_token.rbinitializer to set theSECRET_KEY_BASEenvironment variable for whichever users run the Rails app in production mode. Alternately, you can simply copy the existingsecret_key_basefrom thesecret_token.rbinitializer tosecrets.ymlunder the production section, replacing<%= ENV["SECRET_KEY_BASE"] %>. Make sure your secret_key_base is kept private if you're sharing your code publicly.
Further Details: Knowing the secret token allows an attacker to impersonate any user in the application.
Steps To Reproduce
Go to the Gratipay "Access Dashboard" project (https://github.com/gratipay/access-dashboard/blob/rails-recode/config/initializers)
In the secret_token.rb file the secret_key_base is publicly disclosed.
As per the comments in the code as well as the documentation the key should always be kept private, looks like the developer forgot to remove the token. Happens! Too much work sometimes and the expected delivery deadlines :)
Patch
Removing the secret key would do the work!
Supporting Material/References:
Thanks to EdOverflow for sharing the tips for finding security issues in GitHub projects. :) (https://gist.github.com/EdOverflow/922549f610b258f459b219a32f92d10b)
Please let me know if any further information is needed on this.
BR, null
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the developer committed the Rails initializer containing the secret_key_base to a public repository instead of keeping it in an environment variable or private configuration.
What the attacker needed
Public access to the GitHub repository
The fix
The secret key should be removed from the repository.
How it was found
- Open the project's config/initializers directory on GitHub.
- Open the secret_token.rb file.
- Observe that the secret_key_base value is publicly visible.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Web applications often store a secret key that is used to sign cookies, so the server can tell whether a cookie was really issued by it. If that key is published, anyone can create valid-looking cookies for any user. Here the key was left in a file in a public code repository.
What is Leaked secrets?
Keys, tokens or passwords left in public code, apps, logs or responses, that grant real access.