Skip to content

fix(visu): redact kamera secrets from API responses#42

Open
Micsi wants to merge 1 commit into
mainfrom
codex/propose-fix-for-camera-credential-leak
Open

fix(visu): redact kamera secrets from API responses#42
Micsi wants to merge 1 commit into
mainfrom
codex/propose-fix-for-camera-credential-leak

Conversation

@Micsi
Copy link
Copy Markdown
Owner

@Micsi Micsi commented May 17, 2026

Motivation

  • The Kamera widget stores sensitive fields (password, apiKeyValue) in page_config, and existing visu endpoints returned page_config verbatim which could leak credentials to unauthenticated or low-privilege callers.
  • The intention is to prevent accidental secret disclosure while preserving existing API shapes and frontend functionality by sanitizing responses server-side.

Description

  • Add _CAMERA_SECRET_KEYS and a _sanitize_widget_config helper that blanks configured secret keys in WidgetInstance.config and returns a model copy.
  • Add _sanitize_page_config to apply widget-level sanitization to all widgets in a PageConfig while preserving non-secret fields.
  • Apply sanitization when building response models by calling _sanitize_page_config in _row_to_node, in GET /visu/pages/{node_id}, and in GET /visu/widget-ref/{page_id} so existing unauthenticated/low-auth endpoints no longer expose camera secrets.
  • The change is intentionally minimal and server-side only, leaving storage and page-saving behavior unchanged while redacting secrets from API payloads.

Testing

  • Ran python -m compileall obs/api/v1/visu.py which completed successfully.
  • Verified the modified code paths produce the same response model shapes with secret fields redacted (sanitized) during serialization.

Codex Task

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c9326f089a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread obs/api/v1/visu.py
access=row["access"],
access_pin=None, # PIN-Hash niemals in der API zurückgeben
page_config=PageConfig(**pc) if pc else None,
page_config=_sanitize_page_config(PageConfig(**pc) if pc else None),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Avoid sanitizing configs in shared DB-to-model mapper

Redacting secrets inside _row_to_node means every internal consumer now receives scrubbed data, not just public API responses. copy_node loads the source via _get_node_or_404 and then persists source.page_config, so copied pages will store password/apiKeyValue as empty strings and Kamera widgets lose working credentials after copy. Sanitization should be applied at response serialization boundaries, not in the shared row-mapping path used for write operations.

Useful? React with 👍 / 👎.

Comment thread obs/api/v1/visu.py
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Zugriff verweigert")

return node.page_config or PageConfig()
return _sanitize_page_config(node.page_config) or PageConfig()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve secrets in edit round-trips for page config

GET /pages/{node_id} now always returns a redacted page_config, while save_page still overwrites the full stored JSON with whatever the client posts. In a normal edit flow (load page, change layout, save), the redacted empty password/apiKeyValue values are written back and permanently erase existing Kamera credentials even when the user did not intend to rotate them. This needs either a non-redacted privileged read path or server-side merge logic that retains existing secret fields when clients submit placeholders.

Useful? React with 👍 / 👎.

Comment thread obs/api/v1/visu.py
cfg = dict(widget.config or {})
for key in _CAMERA_SECRET_KEYS:
if key in cfg:
cfg[key] = ""
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep camera secrets for runtime widget rendering

Blanking password and apiKeyValue in _sanitize_widget_config breaks live Kamera widgets that rely on those fields to build authenticated stream URLs (frontend/src/widgets/Kamera/Widget.vue reads props.config.password/apiKeyValue directly). Because sanitization is applied on read paths, cameras using basic/apikey auth can fail immediately at runtime even when no page edit/save occurs.

Useful? React with 👍 / 👎.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant