INNER CODE UNIT · Python

do_GET

cipi-sh/cipi · lib/cipi-crowdsec-rescue.py:156

    def do_GET(self) -> None:
        ip = _peer_ip(self)
        if ip in ("127.0.0.1", "::1", ""):
            self._send(403, "forbidden\n")
            return
        path = self.path.split("?", 1)[0]
        token = path.lstrip("/")
        if not TOKEN_RE.match(token):
            self._reject(ip)
            return
        try:
            os.makedirs(CONFIG, exist_ok=True)
            with open(LOCK_FILE, "a+", encoding="ascii") as lock:
                fcntl.flock(lock, fcntl.LOCK_EX)
                expected = _read(TOKEN_FILE)
                if len(expected) != 64 or not hmac.compare_digest(expected, token):
                    self._reject(ip)
                    return

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…