Skip to content

Add an optional password for the label designer and its API - #393

Open
DL6ER wants to merge 3 commits into
masterfrom
feature/labelburg-password
Open

DL6ER wants to merge 3 commits into
masterfrom
feature/labelburg-password

Conversation

@DL6ER

@DL6ER DL6ER commented Dec 5, 2026

Copy link
Copy Markdown
Owner

With LABELBURG_PASSWORD set, every page and API route asks for it. Unset, nothing changes.

Browsers sign in once and stay signed in for a year, and "Sign out" is in the Settings under About. Programs send the password as a Bearer token or by HTTP Basic, so Home Assistant, Grocy, Homebox and Paperless keep printing, see the docs. Five wrong passwords from one address within a minute refuse it for that minute. The webhook keeps WEBHOOK_PASSWORD.

Sign in Phone Settings, About

DL6ER added 3 commits December 5, 2026 20:08
With `LABELBURG_PASSWORD` set, every page and API route asks for it. Unset, nothing changes.

1. Browsers sign in once on a page with one field and stay signed in for a year through a signed cookie. A new password signs everyone out, and "Sign out" is in the Settings, About.
2. Programs send it as `Authorization: Bearer <password>` or as HTTP Basic with any user name. `/mcp` takes it where `MCP_TOKEN` is unset.
3. Five wrong passwords from one address within a minute refuse that address for the minute, answered at once.
4. The webhook keeps `WEBHOOK_PASSWORD`. All three secrets ignore spaces around them.

Signed-off-by: DL6ER <dl6er@dl6er.de>
How to set `LABELBURG_PASSWORD`, and how Home Assistant, Grocy, Homebox, Paperless and MCP clients send it.

Signed-off-by: DL6ER <dl6er@dl6er.de>
…assword

Signed-off-by: DL6ER <dl6er@dl6er.de>
Copilot AI balanced review requested due to automatic review settings December 5, 2026 21:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Comment thread app/password/__init__.py


def _digest(key: bytes, purpose: bytes, word: str) -> bytes:
return hmac.new(key, purpose + b'\0' + _bytes(word), hashlib.sha256).digest()
Comment thread app/password/__init__.py
def _hashed(value: bytes, longest: int) -> bytes | None:
"""The hash value is compared by, None for one longer than longest,
which is wrong without hashing it."""
return hashlib.sha256(value).digest() if len(value) <= longest else None
Comment thread app/password/__init__.py
kept = state.secrets.get(of)
if kept is None or kept[0] != secret:
raw = _bytes(secret)
kept = state.secrets[of] = (secret, hashlib.sha256(raw).digest(), max(MAX_SENT, len(raw)))
Comment thread app/password/__init__.py
def same(given: bytes, secret: str) -> bool:
"""Whether given is secret, compared as the password is but not counted."""
raw = _bytes(secret)
return _matches(_hashed(given, max(MAX_SENT, len(raw))), hashlib.sha256(raw).digest())
Comment thread app/password/__init__.py
target = local_target(request.values.get('next'))
if request.method == 'GET':
if _signed_in(worked):
return redirect(target or url_for('labeldesigner.index'), 303)
Comment thread app/password/__init__.py
return render_template('signin.html', target=target or '', told=None)
right = attempt(current_app, request.remote_addr, request.form.get('password', '').encode('utf-8'), word)
if right:
response = redirect(target or url_for('labeldesigner.index'), 303)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants