c633ef
diff --git a/Mailman/CSRFcheck.py b/Mailman/CSRFcheck.py
c633ef
index 24e3e11..81998cf 100644
c633ef
--- a/Mailman/CSRFcheck.py
c633ef
+++ b/Mailman/CSRFcheck.py
c633ef
@@ -55,7 +55,7 @@ def csrf_token(mlist, contexts, user=None):
c633ef
     token = binascii.hexlify(marshal.dumps((issued, keymac)))
c633ef
     return token
c633ef
 
c633ef
-def csrf_check(mlist, token, options_user=None):
c633ef
+def csrf_check(mlist, token, cgi_user=None):
c633ef
     """ check token by mailman cookie validation algorithm """
c633ef
     try:
c633ef
         issued, keymac = marshal.loads(binascii.unhexlify(token))
c633ef
@@ -67,12 +67,25 @@ def csrf_check(mlist, token, options_user=None):
c633ef
             key, user = key.split('+', 1)
c633ef
         else:
c633ef
             user = None
c633ef
+        # Don't allow unprivileged tokens for admin or admindb.
c633ef
+        if cgi_user == 'admin':
c633ef
+            if key not in ('admin', 'site'):
c633ef
+                syslog('mischief',
c633ef
+                       'admin form submitted with CSRF token issued for %s.',
c633ef
+                       key + '+' + user if user else key)
c633ef
+                return False
c633ef
+        elif cgi_user == 'admindb':
c633ef
+            if key not in ('moderator', 'admin', 'site'):
c633ef
+                syslog('mischief',
c633ef
+                       'admindb form submitted with CSRF token issued for %s.',
c633ef
+                       key + '+' + user if user else key)
c633ef
+                return False
c633ef
         if user:
c633ef
             # This is for CVE-2021-42097.  The token is a user token because
c633ef
             # of the fix for CVE-2021-42096 but it must match the user for
c633ef
             # whom the options page is requested.
c633ef
             raw_user = UnobscureEmail(urllib.unquote(user))
c633ef
-            if options_user and options_user != raw_user:
c633ef
+            if cgi_user and cgi_user != raw_user:
c633ef
                 syslog('mischief',
c633ef
                        'Form for user %s submitted with CSRF token '
c633ef
                        'issued for %s.',
c633ef
diff --git a/Mailman/Cgi/admin.py b/Mailman/Cgi/admin.py
c633ef
index d2577b5..7c600df 100644
c633ef
--- a/Mailman/Cgi/admin.py
c633ef
+++ b/Mailman/Cgi/admin.py
c633ef
@@ -107,7 +107,8 @@ def main():
c633ef
                    'legend']
c633ef
     params = cgidata.keys()
c633ef
     if set(params) - set(safe_params):
c633ef
-        csrf_checked = csrf_check(mlist, cgidata.getfirst('csrf_token'))
c633ef
+        csrf_checked = csrf_check(mlist, cgidata.getfirst('csrf_token'),
c633ef
+                                  'admin')
c633ef
     else:
c633ef
         csrf_checked = True
c633ef
     # if password is present, void cookie to force password authentication.
c633ef
diff --git a/Mailman/Cgi/admindb.py b/Mailman/Cgi/admindb.py
c633ef
index 58bb357..c152501 100644
c633ef
--- a/Mailman/Cgi/admindb.py
c633ef
+++ b/Mailman/Cgi/admindb.py
c633ef
@@ -144,7 +144,8 @@ def main():
c633ef
     safe_params = ['adminpw', 'admlogin', 'msgid', 'sender', 'details']
c633ef
     params = cgidata.keys()
c633ef
     if set(params) - set(safe_params):
c633ef
-        csrf_checked = csrf_check(mlist, cgidata.getfirst('csrf_token'))
c633ef
+        csrf_checked = csrf_check(mlist, cgidata.getfirst('csrf_token'),
c633ef
+                                  'admindb')
c633ef
     else:
c633ef
         csrf_checked = True
c633ef
     # if password is present, void cookie to force password authentication.
c633ef
diff --git a/Mailman/Cgi/edithtml.py b/Mailman/Cgi/edithtml.py
c633ef
index 1dd9e87..170e811 100644
c633ef
--- a/Mailman/Cgi/edithtml.py
c633ef
+++ b/Mailman/Cgi/edithtml.py
c633ef
@@ -111,7 +111,8 @@ def main():
c633ef
     safe_params = ['VARHELP', 'adminpw', 'admlogin']
c633ef
     params = cgidata.keys()
c633ef
     if set(params) - set(safe_params):
c633ef
-        csrf_checked = csrf_check(mlist, cgidata.getfirst('csrf_token'))
c633ef
+        csrf_checked = csrf_check(mlist, cgidata.getfirst('csrf_token'),
c633ef
+                                  'admin')
c633ef
     else:
c633ef
         csrf_checked = True
c633ef
     # if password is present, void cookie to force password authentication.