1 Commits

Author SHA1 Message Date
Christiaan Goossens
72dbc49c6f Slowed down code checking to prevent brute forcing (#12) 2024-12-31 16:54:39 +01:00
5 changed files with 17 additions and 3 deletions

View File

@@ -16,7 +16,8 @@
"requirements": [ "requirements": [
"python-jose>=3.3.0", "python-jose>=3.3.0",
"aiofiles>=24.1.0", "aiofiles>=24.1.0",
"jinja2>=3.1.4" "jinja2>=3.1.4",
"bcrypt>=4.2.0"
], ],
"version": "0.4.0" "version": "0.4.1"
} }

View File

@@ -6,6 +6,7 @@ import logging
from typing import Dict, Optional from typing import Dict, Optional
import asyncio import asyncio
import bcrypt
from homeassistant.auth import EVENT_USER_ADDED from homeassistant.auth import EVENT_USER_ADDED
from homeassistant.auth.providers import ( from homeassistant.auth.providers import (
AUTH_PROVIDERS, AUTH_PROVIDERS,
@@ -274,6 +275,14 @@ class OpenIdLoginFlow(LoginFlow):
"""Handler for the login flow.""" """Handler for the login flow."""
async def _finalize_user(self, code: str) -> AuthFlowResult: async def _finalize_user(self, code: str) -> AuthFlowResult:
# Verify a dummy hash to make it last a bit longer
# as security measure (limits the amount of attempts you have in 5 min)
# Similar to what the HomeAssistant auth provider does
dummy = b"$2b$12$CiuFGszHx9eNHxPuQcwBWez4CwDTOcLTX5CbOpV6gef2nYuXkY7BO"
bcrypt.checkpw(b"foo", dummy)
# Actually look up the auth provider after,
# this doesn't take a lot of time (regardless of it's in there or not)
sub = await self._auth_provider.async_get_subject(code) sub = await self._auth_provider.async_get_subject(code)
if sub: if sub:
return await self.async_finish( return await self.async_finish(

View File

@@ -1,6 +1,6 @@
[project] [project]
name = "hass-oidc-auth" name = "hass-oidc-auth"
version = "0.4.0" version = "0.4.1"
description = "OIDC component for Home Assistant" description = "OIDC component for Home Assistant"
authors = [ authors = [
{ name = "Christiaan Goossens", email = "contact@christiaangoossens.nl" } { name = "Christiaan Goossens", email = "contact@christiaangoossens.nl" }
@@ -10,6 +10,7 @@ dependencies = [
"python-jose>=3.3.0", "python-jose>=3.3.0",
"aiofiles>=24.1.0", "aiofiles>=24.1.0",
"jinja2>=3.1.4", "jinja2>=3.1.4",
"bcrypt>=4.2.0",
] ]
readme = "README.md" readme = "README.md"
requires-python = ">= 3.13" requires-python = ">= 3.13"

View File

@@ -62,6 +62,7 @@ audioop-lts==0.2.1
awesomeversion==24.6.0 awesomeversion==24.6.0
# via homeassistant # via homeassistant
bcrypt==4.2.0 bcrypt==4.2.0
# via hass-oidc-auth
# via homeassistant # via homeassistant
bleak==0.22.3 bleak==0.22.3
# via bleak-retry-connector # via bleak-retry-connector

View File

@@ -12,6 +12,8 @@
-e file:. -e file:.
aiofiles==24.1.0 aiofiles==24.1.0
# via hass-oidc-auth # via hass-oidc-auth
bcrypt==4.2.1
# via hass-oidc-auth
ecdsa==0.19.0 ecdsa==0.19.0
# via python-jose # via python-jose
jinja2==3.1.5 jinja2==3.1.5