Skip to content

fix(input): Sensitive input sequences are logged in plaintext#659

Merged
wizzomafizzo merged 3 commits into
ZaparooProject:mainfrom
tomaioo:fix/security/sensitive-input-sequences-are-logged-in-
Apr 13, 2026
Merged

fix(input): Sensitive input sequences are logged in plaintext#659
wizzomafizzo merged 3 commits into
ZaparooProject:mainfrom
tomaioo:fix/security/sensitive-input-sequences-are-logged-in-

Conversation

@tomaioo

@tomaioo tomaioo commented Apr 12, 2026

Copy link
Copy Markdown
Contributor

Summary

Security: Sensitive input sequences are logged in plaintext

Problem

Severity: Medium | File: pkg/api/methods/input.go:L47

API handlers for keyboard/gamepad input log full parsed input arguments (keys / buttons). These values can include sensitive sequences (e.g., typed credentials or private control patterns), which then persist in logs and may be exposed through log collection, support bundles, or unauthorized log access.

Solution

Avoid logging raw input payloads. Log only high-level metadata (e.g., action type, argument count, request ID) or redact/hash values. Consider a debug-only gated log path with explicit opt-in.

Changes

  • pkg/api/methods/input.go (modified)

Summary by CodeRabbit

  • Chores

    • Reduced logging verbosity and removed sensitive payloads from logs to limit exposed data.
    • URLs are now redacted in error messages and logs.
    • NFC/tag and input/gamepad logging made less verbose; command/script logs no longer include full payloads.
  • Tests

    • Added tests covering URL redaction and sensitive-command handling.

Note: No functional or user-facing behavior was changed.

API handlers for keyboard/gamepad input log full parsed input arguments (`keys` / `buttons`). These values can include sensitive sequences (e.g., typed credentials or private control patterns), which then persist in logs and may be exposed through log collection, support bundles, or unauthorized log access.

Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Apr 12, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Adjusts logging across the codebase to redact or reduce sensitive/request payloads: replaces detailed payload logs with counts or sanitized values, introduces URL redaction, marks certain ZapScript commands as sensitive, and adds tests for sensitivity and URL redaction.

Changes

Cohort / File(s) Summary
API input/run logging
pkg/api/methods/input.go, pkg/api/methods/run.go
Replaced detailed key/button/token text logging with integer counts or static messages; no control-flow or parsing changes.
API server logging & tests
pkg/api/server.go, pkg/api/server_logging_test.go
Reduced logged request payloads to always log method/id only for requests/notifications; simplified test expectations accordingly.
Readers (NFC) logging
pkg/readers/libnfc/libnfc.go, pkg/readers/pn532/pn532.go
Lowered verbosity and split logs so sensitive/large payloads are logged at Debug or redacted in Info logs; error returns still include details where applicable.
Service queue logging
pkg/service/queues.go
Removed token/script text from "running script" and "injecting new commands" logs, leaving counts only.
ZapScript sensitive-command handling
pkg/zapscript/commands.go, pkg/zapscript/commands_test.go
Added isSensitiveCommand to identify commands whose arguments should not be logged; updated RunCommand to avoid logging arguments for sensitive commands; added tests for sensitivity.
HTTP URL redaction
pkg/zapscript/http.go, pkg/zapscript/http_test.go
Added redactURL(rawURL string) to remove query and userinfo from URLs and used it in HTTP cmd logs/errors; added unit tests covering redaction cases.
ZapScript input logging
pkg/zapscript/input.go
Changed keyboard/gamepad command logs to record argument counts (key_count/button_count) instead of listing arguments.

Sequence Diagram(s)

(none)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I nibble the logs, I prune what they show,
Counts now hop in place of the flow.
URLs masked and commands tucked away,
Quiet and tidy — a safer display. 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main objective of the PR: preventing sensitive input sequences from being logged in plaintext by replacing argument logging with metadata-only logging.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Comment thread pkg/api/methods/input.go
}

log.Info().Strs("keys", args).Msg("keyboard input via API")
log.Info().Int("key_count", len(args)).Msg("keyboard input via API")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: The security fix is incomplete. Sensitive keyboard and gamepad inputs are still logged in plaintext via the ZapScript command handlers in pkg/zapscript/input.go.
Severity: HIGH

Suggested Fix

Apply the same logging fix to the ZapScript handlers in pkg/zapscript/input.go. Modify the log.Info().Msgf calls in cmdKeyboard and cmdGamepad to log only the count of arguments, not the raw arguments themselves, similar to the changes made in pkg/api/methods/input.go.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: pkg/api/methods/input.go#L56

Potential issue: The pull request aims to prevent logging of sensitive keyboard and
gamepad inputs. While it addresses this in the API handler path
(`pkg/api/methods/input.go`), it fails to fix the same issue in the ZapScript command
handler path. The `cmdKeyboard` and `cmdGamepad` functions in `pkg/zapscript/input.go`
still log the full, potentially sensitive, input arguments in plaintext. This logging
occurs during trusted execution scenarios, such as running a locally stored ZapScript
card, where the `env.Unsafe` flag is false.

Did we get this right? 👍 / 👎 to inform future reviews.

@wizzomafizzo wizzomafizzo changed the title Security: Sensitive input sequences are logged in plaintext fix(input): Sensitive input sequences are logged in plaintext Apr 12, 2026

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
pkg/api/methods/input.go (1)

56-56: Security fix correctly implemented.

The change to log only key_count instead of the actual key values effectively prevents sensitive input sequences (credentials, private patterns, etc.) from being persisted in logs. The implementation is correct and the field name is descriptive.

Consider adding debug-level logging for troubleshooting.

While the security fix is appropriate for production, having no visibility into actual input sequences makes troubleshooting difficult. As mentioned in the PR objectives, consider implementing a debug-only gated log path that requires explicit opt-in:

🔍 Suggested debug logging enhancement
-	log.Info().Int("key_count", len(args)).Msg("keyboard input via API")
+	logger := log.Info().Int("key_count", len(args))
+	if log.Debug().Enabled() {
+		logger = logger.Strs("keys_debug", args)
+	}
+	logger.Msg("keyboard input via API")

This would only expose sensitive data when debug logging is explicitly enabled, balancing security with observability.

Consider adding tests for logging behavior.

The existing tests (see input_test.go:37-83) validate platform method calls but don't verify logging behavior. Adding logging assertions would help ensure this security fix doesn't regress.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/api/methods/input.go` at line 56, Replace the unconditional Info log with
a gated debug path: keep log.Info().Int("key_count", len(args)).Msg("keyboard
input via API") for normal runs, and add a conditional branch that, when a debug
opt-in is enabled (e.g., an env var or a new helper like
enableDebugInputLogging()), logs the actual args via log.Debug().Strs("keys",
args).Msg("keyboard input (debug)") so sensitive values are only emitted when
explicitly enabled; update or add tests in input_test.go to assert that with
debug opt-in the logger receives the full args payload and without it only
key_count is logged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@pkg/api/methods/input.go`:
- Line 56: Replace the unconditional Info log with a gated debug path: keep
log.Info().Int("key_count", len(args)).Msg("keyboard input via API") for normal
runs, and add a conditional branch that, when a debug opt-in is enabled (e.g.,
an env var or a new helper like enableDebugInputLogging()), logs the actual args
via log.Debug().Strs("keys", args).Msg("keyboard input (debug)") so sensitive
values are only emitted when explicitly enabled; update or add tests in
input_test.go to assert that with debug opt-in the logger receives the full args
payload and without it only key_count is logged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e95711b0-7aff-479e-afad-d6d2d2e6e486

📥 Commits

Reviewing files that changed from the base of the PR and between 6c13bc3 and d45d922.

📒 Files selected for processing (1)
  • pkg/api/methods/input.go

@sentry

sentry Bot commented Apr 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 68.00000% with 16 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/readers/libnfc/libnfc.go 0.00% 4 Missing ⚠️
pkg/zapscript/http.go 80.00% 4 Missing ⚠️
pkg/zapscript/commands.go 76.92% 3 Missing ⚠️
pkg/api/methods/run.go 0.00% 2 Missing ⚠️
pkg/readers/pn532/pn532.go 66.66% 1 Missing ⚠️
pkg/service/queues.go 50.00% 1 Missing ⚠️
pkg/zapscript/input.go 50.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Extend the sensitive input logging fix to cover the rest of the
codebase. Strip query params and userinfo from HTTP command URLs in
error messages and logs. Redact args for sensitive commands (http.*,
input.*, execute) in the command dispatcher. Move NFC tag text and
token content from INFO to DEBUG level. Stop logging full request
params in the API server.

Add tests for redactURL and isSensitiveCommand.

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
pkg/zapscript/http.go (1)

36-36: Comment should reflect full redaction behavior.

Line 36 says query params are stripped, but the function also clears User info. Please update the comment to match implementation.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/zapscript/http.go` at line 36, Update the function comment for redactURL
to accurately describe its full behavior: note that it strips query parameters
and also clears the URL.User (user info) for safe logging. Edit the comment
immediately above the redactURL function (referencing redactURL) to mention both
query param removal and user-info redaction so the doc matches the
implementation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@pkg/zapscript/http.go`:
- Line 36: Update the function comment for redactURL to accurately describe its
full behavior: note that it strips query parameters and also clears the URL.User
(user info) for safe logging. Edit the comment immediately above the redactURL
function (referencing redactURL) to mention both query param removal and
user-info redaction so the doc matches the implementation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 345d3761-ef2c-4579-9200-593de6ea505e

📥 Commits

Reviewing files that changed from the base of the PR and between d45d922 and dacf27d.

📒 Files selected for processing (11)
  • pkg/api/methods/run.go
  • pkg/api/server.go
  • pkg/api/server_logging_test.go
  • pkg/readers/libnfc/libnfc.go
  • pkg/readers/pn532/pn532.go
  • pkg/service/queues.go
  • pkg/zapscript/commands.go
  • pkg/zapscript/commands_test.go
  • pkg/zapscript/http.go
  • pkg/zapscript/http_test.go
  • pkg/zapscript/input.go
✅ Files skipped from review due to trivial changes (1)
  • pkg/zapscript/input.go

@wizzomafizzo
wizzomafizzo merged commit 5b1499f into ZaparooProject:main Apr 13, 2026
11 checks passed
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.

2 participants