{"record":{"id":"61bfe2db9ca3a6fc","repo":"OtterMind/Chat2DB","slug":"onebot-token-must-contain-at-least-32-characters","errorCode":null,"errorMessage":"ONEBOT_TOKEN must contain at least 32 characters","messagePattern":"ONEBOT_TOKEN must contain at least 32 characters","errorType":"validation","errorClass":"RuntimeError","httpStatus":null,"severity":"critical","filePath":"script/github/qq_relay/relay_server.py","lineNumber":62,"sourceCode":"class RelayConfig:\n    relay_token: str\n    onebot_token: str\n    onebot_url: str\n    repository: str\n    group_id: int\n    max_message_length: int = 900\n    rate_limit: int = 30\n    rate_window_seconds: int = 60\n\n    @classmethod\n    def from_environment(cls) -> \"RelayConfig\":\n        relay_token = os.environ.get(\"RELAY_TOKEN\", \"\")\n        onebot_token = os.environ.get(\"ONEBOT_TOKEN\", \"\")\n        group_id = os.environ.get(\"QQ_GROUP_ID\", \"\")\n        if len(relay_token) < 32:\n            raise RuntimeError(\"RELAY_TOKEN must contain at least 32 characters\")\n        if len(onebot_token) < 32:\n            raise RuntimeError(\"ONEBOT_TOKEN must contain at least 32 characters\")\n        if not group_id.isdigit():\n            raise RuntimeError(\"QQ_GROUP_ID must be a numeric QQ group number\")\n        return cls(\n            relay_token=relay_token,\n            onebot_token=onebot_token,\n            onebot_url=os.environ.get(\"ONEBOT_URL\", \"http://napcat:3000\"),\n            repository=os.environ.get(\"RELAY_REPOSITORY\", \"OtterMind/Chat2DB\"),\n            group_id=int(group_id),\n            max_message_length=int(os.environ.get(\"RELAY_MAX_MESSAGE_LENGTH\", \"900\")),\n            rate_limit=int(os.environ.get(\"RELAY_RATE_LIMIT\", \"30\")),\n        )\n\n\nclass RateLimiter:\n    def __init__(self, limit: int, window_seconds: int):\n        self.limit = limit\n        self.window_seconds = window_seconds\n        self._timestamps: deque[float] = deque()","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/OtterMind/Chat2DB/blob/5ee1e990e73fbcae1969dc554be254fedb3ab888/script/github/qq_relay/relay_server.py#L44-L80","documentation":"Raised by RelayConfig.from_environment (relay_server.py:62) as a RuntimeError when ONEBOT_TOKEN has fewer than 32 characters. The relay forwards messages to the NapCat/OneBot backend using this token; a short token is treated as misconfiguration and the server refuses to start.","triggerScenarios":"Starting the relay with ONEBOT_TOKEN unset, empty, or shorter than 32 chars. Checked at startup in from_environment, so it is fatal before serving.","commonSituations":"ONEBOT_TOKEN not set; the OneBot access token changed but the relay env was not updated; a placeholder used during setup; NapCat deployed without an access token.","solutions":["Generate a OneBot access token of at least 32 characters.","Configure the same token in NapCat/OneBot and set ONEBOT_TOKEN in the relay environment.","Restart the relay after updating the env."],"exampleFix":"ONEBOT_TOKEN=$(python -c 'import secrets;print(secrets.token_urlsafe(48))')","handlingStrategy":"validation","validationCode":"import os\ntoken = os.environ.get(\"ONEBOT_TOKEN\", \"\")\nif len(token) < 32:\n    raise SystemExit(\"ONEBOT_TOKEN must be >= 32 chars; set the NapCat access token\")","typeGuard":"def is_strong_token(value: str) -> bool:\n    return len(value) >= 32","tryCatchPattern":null,"preventionTips":["Set a >=32-char access token in NapCat/OneBot.","Mirror it as ONEBOT_TOKEN in the relay environment.","Restart the relay after rotating the token."],"tags":["config","security","relay","startup","secrets"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}