elections.k8s.io uses weak session secret key, may place elections at risk
The elections.k8s.io site signed its session cookies with a weak, guessable Flask secret key (the literal string N/A). An attacker who knows the key could forge or modify session cookies, which the reporter suggests might enable cross-site request forgery against voting or authentication flows, though the GitHub OAuth token stored in the session makes direct impersonation hard.
- Triaged in 3 days
- Fixed in 3.8 years
- Paid in 8 days
- Disclosed after 3.9 years
Summary
Hi there, I have been working on a new tool to detect misconfigured session signing across bug bounty programs, called CookieMonster. Many applications use stateless cookies to preserve session information (i.e. who has logged in), but many applications do not properly secure this. @nagli and I discovered that elections.k8s.io uses a weak Flask SECRET_KEY, literally the string N/A, to sign authentication cookies.
In many applications, this allows the complete compromise of the application, as you can manipulate who you are logged in as. This would be especially problematic for an election voting system. It seems, in the case of Elekto, this may not be the case as the GitHub OAuth token is injected into the session instead of a user ID, which would be hard to obtain for another user. However, this may enable weird attacks like using cross-origin request forgery with the voting or authentication flows, as we would be able to manipulate the session which contains these tokens.
Note the warning from the Elekto source (this is what you have set to N/A):
# Encryption Key
#
# This is used by the Flask server and should be set to a random character
# string, please do not deploy before doing this!.
SECRET_KEY = env('APP_KEY', 'test')
PoC
As CookieMonster is not yet public, you can also use Flask-Unsign (pip3 install flask-unsign[wordlist]) to validate this:
% curl https://elections.k8s.io -Is | grep cookie
set-cookie: session=eyJfcGVybWFuZW50Ijp0cnVlfQ.YX-V3g.NET76NNJbweb_qagyfYl2_7TDJg; Expires=Thu, 02 Dec 2021 07:23:10 GMT; HttpOnly; Path=/
% flask-unsign -u -c "eyJfcGVybWFuZW50Ijp0cnVlfQ.YX-V3g.NET76NNJbweb_qagyfYl2_7TDJg"
[*] Session decodes to: {'_permanent': True}
[*] No wordlist selected, falling back to default wordlist..
[*] Starting brute-forcer with 8 threads..
[+] Found secret key after 8192 attemptspdcQHNyXaB0O
'N/A'
Impact
Weak secret likely allows arbitrary session manipulation
Context
elections.k8s.io is a deployment of Elekto, an election system used by the Kubernetes project to run community votes. Elekto is a Flask application, and like most Flask applications it keeps session state in a signed cookie rather than in server-side storage. The cookie holds the session contents and a signature produced with the application's SECRET_KEY; the server trusts the contents as long as the signature verifies.
The report concerns that key. The deployment was signing session cookies with a weak value, literally the string N/A, which makes the signature forgeable by anyone who guesses or brute-forces the key.
Setup
The researcher used a tool of their own, CookieMonster, built to detect misconfigured session signing across bug bounty programs. Because CookieMonster was not yet public, the report also gives a validation path using Flask-Unsign, installed with the wordlist extra:
pip3 install flask-unsign[wordlist]
No account, role or special access was needed: the check starts from an unauthenticated request to the site's front page.
Finding it
The starting observation is that many applications use stateless cookies to preserve session information, such as who has logged in, and many do not properly secure them. Working with @nagli, the researcher found that elections.k8s.io used a weak Flask SECRET_KEY, the string N/A, to sign authentication cookies.
The Elekto source itself warns about this setting. The report quotes the comment above the key in config.py (the value the deployment had set to N/A):
# Encryption Key
#
# This is used by the Flask server and should be set to a random character
# string, please do not deploy before doing this!.
SECRET_KEY = env('APP_KEY', 'test')
So the application expects APP_KEY to be set to a random string before deployment, and this deployment did not do that.
Exploitation
Step 1: collect a session cookie
The first step is an ordinary unauthenticated request, filtering the response headers for the cookie:
% curl https://elections.k8s.io -Is | grep cookie
set-cookie: [redacted] Expires=Thu, 02 Dec 2021 07:23:10 GMT; HttpOnly; Path=/
The server hands out a session cookie on the front page. It is HttpOnly and scoped to Path=/, and it carries an expiry date. The value has the three-part Flask structure: a base64-encoded payload, a timestamp, and a signature.
Step 2: recover the signing key
The cookie is then fed to flask-unsign in unsign mode:
% flask-unsign -u -c "eyJfcGVybWFuZW50Ijp0cnVlfQ.YX-V3g.NET76NNJbweb_qagyfYl2_7TDJg"
[*] Session decodes to: {'_permanent': True}
[*] No wordlist selected, falling back to default wordlist..
[*] Starting brute-forcer with 8 threads..
[+] Found secret key after 8192 attemptspdcQHNyXaB0O
'N/A'
The tool decodes the payload to {'_permanent': True}, meaning the cookie only marks the session as permanent at this point. With no wordlist supplied it falls back to its default wordlist, runs the brute-forcer with 8 threads, and recovers the key after 8192 attempts. The key is N/A.
With the key known, the signature on any session cookie can be recomputed, so the session contents can be chosen by the attacker.
Root cause
The mistake is configuration: the Flask SECRET_KEY was left at the placeholder value N/A instead of being set to a random character string as the Elekto source instructs. Flask's signed-cookie sessions rely entirely on that key being secret; there is no server-side session store to fall back on, so a guessable key removes the integrity protection on the cookie. The application's own warning in config.py is the defence that was meant to prevent this, and it was not followed at deployment time.
Impact
In many applications, a weak session key allows complete compromise, because an attacker can manipulate who they are logged in as. The report is careful about Elekto: it seems this may not be the case here, because the GitHub OAuth token is injected into the session instead of a user ID, and that token would be hard to obtain for another user.
What remains is the ability to manipulate the session that contains these tokens. The researcher suggests this may enable unusual attacks, such as cross-origin request forgery against the voting or authentication flows. The report frames the overall risk as a weak secret that likely allows arbitrary session manipulation, which is especially problematic for an election voting system.
Fix
The report does not describe a fix or a change made in response. The direction it points to is the one in the Elekto source: set APP_KEY to a random character string before deploying, so that SECRET_KEY is not a guessable placeholder.
Variants to test
- Request any page and inspect
Set-Cookiefor a Flask-style three-part session value. A positive result is asessioncookie whose payload decodes to a small dictionary such as{'_permanent': True}. - Run
flask-unsign -u -c "<cookie>"against that value. A positive result is the tool printing a recovered secret key, as it did here withN/Aafter 8192 attempts. - Try obvious deployment placeholders and defaults as candidate keys, such as the string
N/Arecovered here. A positive result is a key that verifies the existing signature.
Hunting notes
This class of bug hides in deployments of frameworks that sign client-side state with a configured secret: Flask sessions are the example here, but the same shape appears wherever a key is meant to be set per environment. The signal during recon is a session cookie with a recognisable signed structure and a payload that decodes to something trivial, which suggests the deployment is running on defaults.
The researcher showed the weakness in two steps: first by recovering the key from a cookie obtained without authentication, then by explaining what control over the session contents could mean for an election system. The report is also explicit about the limit, noting that the GitHub OAuth token in the session rather than a user ID makes direct account takeover hard here, and presenting the remaining risk as session manipulation and possible cross-origin request forgery against the voting and authentication flows.
What happened, in plain words
A security researcher found that a website used by the Kubernetes project to run community elections, elections.k8s.io, was protecting its login cookies with a password that was effectively no password at all: the literal text N/A. The site is a deployment of Elekto, an open-source election system built on a web framework called Flask. Flask has a habit of storing a user's session information inside the cookie itself, and it stamps that cookie with a signature so the server can tell whether the contents were changed. The stamp is produced with a secret key that the site owner is supposed to choose. Here the key was left at a placeholder value, so anyone who guessed it could produce valid stamps for cookies of their own design.
The researcher, working with another researcher called @nagli, built a tool called CookieMonster to look for exactly this kind of mistake across bug bounty programs. The report shows how to confirm the finding with a publicly available tool, Flask-Unsign, so that anyone can repeat the check.
The report is careful about how serious this is. In many applications a weak session key means an attacker can simply pretend to be any user. Here that seems harder, because the session stores a GitHub login token rather than a user identifier, and another person's token would be difficult to obtain. What remains possible is tampering with the session itself, which the researcher suggests could open the door to unusual attacks against the voting or login flows. For an election system, that is still a serious concern.
Background: the pieces involved
Before walking through the steps, here are the ideas you need. None of them require any prior security knowledge.
A web application and its server. When you visit a site, your browser sends a request to a computer somewhere (the server), and the server sends back a response, usually a web page. Most of what happens is invisible to you: the browser and server exchange small pieces of data behind the scenes.
HTTP headers. Every request and response carries a set of headers, which are lines of text with a name and a value. They describe things like the type of content being returned or instructions about cookies. You normally never see them, but browser developer tools and command-line tools can show them.
Cookies. A cookie is a small piece of text that a website asks your browser to store and to send back on every later request to that site. It is how a website remembers who you are between page loads. Think of it like a cloakroom ticket: you hand it in, and the staff know which coat is yours. If someone can forge a convincing ticket, they can walk off with a coat that is not theirs.
Sessions. A session is the server's idea of "this is the same visitor as before". In many frameworks the session data (for example, whether you are logged in) is not kept on the server at all. Instead it is packed into the cookie, and the server simply reads it back on each request. This is called a stateless session, because the server keeps no record of it.
Signing and secret keys. If the session lives in the cookie, the server must be able to tell whether someone edited it. So it computes a signature: a short code derived from the cookie contents plus a secret key that only the server knows. When the cookie comes back, the server recomputes the signature and compares. If the contents were changed, the signature no longer matches and the cookie is rejected. The whole scheme rests on the secret key staying secret. If the key is guessable, the signature is worthless, because anyone can compute a correct one.
Flask. Flask is a popular toolkit for building web applications in the Python programming language. Its default session mechanism works exactly as described above: a signed cookie containing the session data.
Elekto. Elekto is an election system, and elections.k8s.io is a deployment of it used by the Kubernetes project for community votes. It is a Flask application, so it uses Flask's signed-cookie sessions.
Brute-forcing. Brute-forcing means trying many possibilities in turn until one works, usually with a computer doing it very fast. A list of candidate values to try is called a wordlist. If a secret key is a common word or a placeholder, a brute-forcer will find it quickly.
OAuth token. OAuth is a way for a website to let you log in with an account you already have elsewhere, such as GitHub, without giving the site your password. The site receives a token, a long string that stands in for your login. In this application, that token is what gets stored in the session.
Cross-origin request forgery. This is a class of attack where a malicious page causes your browser to send a request to another site where you are logged in, without you intending it. If an attacker can also tamper with your session, such tricks can become more powerful.
The setup
The researcher used their own tool, CookieMonster, which was built to detect misconfigured session signing across bug bounty programs. Because CookieMonster was not yet public, the report also gives a way to validate the finding with Flask-Unsign, a tool that can decode and attack Flask session cookies. It is installed with the wordlist extra, which brings along a built-in list of candidate keys:
pip3 install flask-unsign[wordlist]
pip3 is Python's package installer. The command downloads and installs flask-unsign together with its wordlist component, so the tool has a default list of guesses to work through.
No account, role or special access was needed. The check starts from an ordinary request to the site's front page, the same thing any visitor's browser does.
Finding it
The starting observation is that many applications use stateless cookies to preserve session information, such as who has logged in, and many do not properly secure them. Working with @nagli, the researcher found that elections.k8s.io used a weak Flask SECRET_KEY, the string N/A, to sign authentication cookies.
The Elekto source code itself warns about this setting. The report quotes the comment that sits above the key in the file config.py, and notes that this is the value the deployment had set to N/A:
# Encryption Key
#
# This is used by the Flask server and should be set to a random character
# string, please do not deploy before doing this!.
SECRET_KEY = env('APP_KEY', 'test')
Line by line:
- The lines beginning with
#are comments, notes for humans that the computer ignores. They explain that the key is used by the Flask server and should be a random string, and they explicitly warn not to deploy before setting it. SECRET_KEY = env('APP_KEY', 'test')sets the secret key from an environment variable calledAPP_KEY. Environment variables are settings supplied from outside the code, typically by whoever deploys the application, so that secrets do not have to be written into the source.- The second argument,
'test', is a fallback: ifAPP_KEYis not set, the key becomes the stringtest. That fallback is itself a poor default, which is why the comment warns against deploying without setting the variable.
So the application expects APP_KEY to be set to a random string before deployment, and this deployment did not do that.
Exploitation
Step 1: collect a session cookie
The first step is an ordinary request to the site with no login, filtering the response headers so that only the cookie line is shown:
% curl https://elections.k8s.io -Is | grep cookie
set-cookie: [redacted] Expires=Thu, 02 Dec 2021 07:23:10 GMT; HttpOnly; Path=/
What each part does:
curlis a command-line tool that fetches a URL, like a browser but printing the raw response instead of drawing a page.-Istells curl to send a request for the page headers only (-I) and to be silent about progress (-s).| grep cookiepipes the output intogrep, a tool that prints only the lines containing the wordcookie. This is a quick way to pick out the interesting header from everything else.- The result is a
set-cookieheader, which is how a server tells the browser to store a cookie. The cookie is namedsessionand its value is the long string after the equals sign. Expires=Thu, 02 Dec 2021 07:23:10 GMTsays when the cookie should be discarded.HttpOnlymeans the cookie is hidden from JavaScript running in the page, a protection against some kinds of theft.Path=/means the cookie applies to the whole site.
The server hands out a session cookie on the front page, before any login. The value has the three-part Flask structure: a base64-encoded payload, a timestamp, and a signature. Base64 is a way of writing arbitrary data using only ordinary text characters, so it can travel safely in a header. The three parts are separated by dots. The first part is the session contents in encoded form, the second is when the cookie was made, and the third is the signature that proves the first two were not altered.
Step 2: recover the signing key
The cookie is then fed to flask-unsign in unsign mode, which means "decode this cookie and try to find the key that signed it":
% flask-unsign -u -c "eyJfcGVybWFuZW50Ijp0cnVlfQ.YX-V3g.NET76NNJbweb_qagyfYl2_7TDJg"
[*] Session decodes to: {'_permanent': True}
[*] No wordlist selected, falling back to default wordlist..
[*] Starting brute-forcer with 8 threads..
[+] Found secret key after 8192 attemptspdcQHNyXaB0O
'N/A'
Line by line:
flask-unsign -u -c "..."runs the tool in unsign mode (-u) against the cookie value given with-c. The value is the same three-part string from the previous step.[*] Session decodes to: {'_permanent': True}is the tool reporting what is inside the cookie. The payload is a small dictionary, a Python data structure of key and value pairs, containing just one entry:_permanentset toTrue. In plain terms, the cookie only marks the session as permanent at this point. There is no user identity in it yet, because nobody has logged in.[*] No wordlist selected, falling back to default wordlist..means the researcher did not supply a list of guesses, so the tool uses the one that came with the installation.[*] Starting brute-forcer with 8 threads..means it is now trying candidate keys, using 8 threads, which are parallel workers that let it try several guesses at once.[+] Found secret key after 8192 attemptspdcQHNyXaB0Oreports success: after 8192 attempts it found a key that produces the same signature as the one on the cookie. The trailing text is part of the tool's output as captured in the report.'N/A'is the recovered key. It is the literal two-character-plus-slash stringN/A, a placeholder that was never replaced.
With the key known, the signature on any session cookie can be recomputed, so the session contents can be chosen by the attacker. In other words, the attacker can write whatever they like into the cookie and produce a signature the server will accept, because the server uses the same key to check it.
Root cause
The mistake is configuration: the Flask SECRET_KEY was left at the placeholder value N/A instead of being set to a random character string as the Elekto source instructs. Flask's signed-cookie sessions rely entirely on that key being secret. There is no server-side session store to fall back on, so a guessable key removes the integrity protection on the cookie. Integrity here means the guarantee that the contents have not been changed. The application's own warning in config.py is the defence that was meant to prevent this, and it was not followed at deployment time.
Impact
In many applications, a weak session key allows complete compromise, because an attacker can manipulate who they are logged in as. The report is careful about Elekto: it seems this may not be the case here, because the GitHub OAuth token is injected into the session instead of a user ID, and that token would be hard to obtain for another user. A user ID is often a simple number or name that can be guessed; a GitHub token is a long, secret string tied to one person's account, so copying someone else's login this way is not straightforward.
What remains is the ability to manipulate the session that contains these tokens. The researcher suggests this may enable unusual attacks, such as cross-origin request forgery against the voting or authentication flows. The report frames the overall risk as a weak secret that likely allows arbitrary session manipulation, which is especially problematic for an election voting system.
Fix
The report does not describe a fix or a change made in response. The direction it points to is the one in the Elekto source: set APP_KEY to a random character string before deploying, so that SECRET_KEY is not a guessable placeholder. A long random value cannot be guessed or found by working through a wordlist, which restores the protection the signature is supposed to provide.
Variants to test
If you want to look for the same mistake elsewhere, these are the steps the report lays out:
- Request any page and inspect
Set-Cookiefor a Flask-style three-part session value. A positive result is asessioncookie whose payload decodes to a small dictionary such as{'_permanent': True}. - Run
flask-unsign -u -c "<cookie>"against that value. A positive result is the tool printing a recovered secret key, as it did here withN/Aafter 8192 attempts. - Try obvious deployment placeholders and defaults as candidate keys, such as the string
N/Arecovered here. A positive result is a key that verifies the existing signature.
Hunting notes
This class of bug hides in deployments of frameworks that sign client-side state with a configured secret. Flask sessions are the example here, but the same shape appears wherever a key is meant to be set per environment. The signal during recon, the early information-gathering phase of a security test, is a session cookie with a recognisable signed structure and a payload that decodes to something trivial, which suggests the deployment is running on defaults.
The researcher showed the weakness in two steps: first by recovering the key from a cookie obtained without authentication, then by explaining what control over the session contents could mean for an election system. The report is also explicit about the limit, noting that the GitHub OAuth token in the session rather than a user ID makes direct account takeover hard here, and presenting the remaining risk as session manipulation and possible cross-origin request forgery against the voting and authentication flows.
Glossary
- API: a defined way for one piece of software to talk to another, usually over the network, exchanging requests and responses in an agreed format.
- Base64: an encoding that turns arbitrary data into ordinary text characters so it can be carried in places that only allow text, such as headers.
- Brute-forcing: trying many candidate values automatically until one works.
- Cookie: a small piece of text a website asks your browser to store and send back on later requests, used to remember things about you.
- Cross-origin request forgery: an attack where a malicious page makes your browser send a request to another site where you are logged in, without your intent.
- curl: a command-line tool for fetching URLs and printing the raw response.
- Elekto: an open-source election system, built on Flask, used by the Kubernetes project for community votes.
- Environment variable: a setting supplied to a program from outside its code, often used to keep secrets out of source files.
- Flask: a Python web framework whose default sessions are stored in signed cookies.
- Flask-Unsign: a tool that decodes Flask session cookies and can brute-force the key that signed them.
- grep: a command-line tool that prints only the lines of its input matching a given word or pattern.
- Header: a named line of text in an HTTP request or response carrying metadata, such as cookie instructions.
- HttpOnly: a cookie attribute that hides the cookie from JavaScript in the page.
- Integrity: the guarantee that data has not been altered, here provided by the cookie signature.
- Kubernetes: an open-source system for running and managing software containers, whose community uses this election site.
- OAuth: a scheme that lets a site log you in through an account you already have elsewhere, receiving a token instead of your password.
- OAuth token: the long secret string issued by an OAuth provider that stands in for a user's login.
- Payload: the part of a cookie or message that carries the actual data, as opposed to the signature.
- pip3: Python's package installer, used to install libraries and tools.
- Recon: the early information-gathering phase of a security test.
- Secret key: the private value used to compute and verify cookie signatures; if it is guessable, the signatures can be forged.
- Session: the server's notion of a continuing visit by the same user, often stored in a cookie.
- Signature: a short code derived from data plus a secret key, used to detect changes to the data.
- Stateless session: a session kept entirely in the cookie rather than stored on the server.
- Thread: a unit of parallel work inside a program, letting it do several things at once.
- Wordlist: a list of candidate values, such as common passwords or placeholders, used when brute-forcing.
- XSS: cross-site scripting, a class of attack where malicious script runs in a page; mentioned here only as the kind of theft
HttpOnlyhelps prevent.