Skip to content

fix: reject HP_SHARED_KEY with FRP-incompatible characters#104

Merged
oleksandr-nc merged 3 commits into
mainfrom
fix/shared-key-special-chars
May 11, 2026
Merged

fix: reject HP_SHARED_KEY with FRP-incompatible characters#104
oleksandr-nc merged 3 commits into
mainfrom
fix/shared-key-special-chars

Conversation

@oleksandr-nc
Copy link
Copy Markdown
Contributor

@oleksandr-nc oleksandr-nc commented May 11, 2026

Reject HP_SHARED_KEY values that contain " or \ after the existing strip_quotes normalization, with a clear error message naming the forbidden characters. These characters otherwise corrupt the generated FRP TOML line metadatas.token = "..." and cause frpc to fail at startup.

The check runs after strip_quotes so that accidentally-wrapped values like "secret" / 'secret' (the use case PR #83 added strip_quotes for) keep working. The single-quote character is intentionally not forbidden: it is valid inside a TOML basic string and rejecting it would break legitimate apostrophe-in-passphrase values (e.g. don'tguessit).

Also bumps /info endpoint version to 0.4.

Fixes #103

…onfig

Signed-off-by: Oleksander Piskun <oleksandr2088@icloud.com>
Signed-off-by: Oleksander Piskun <oleksandr2088@icloud.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 11, 2026

📝 Walkthrough

Walkthrough

start.sh now strips surrounding quotes from HP_SHARED_KEY then validates the value and aborts if it contains a double quote (") or backslash (), preventing malformed FRP TOML token lines. The haproxy_agent /info HTTP endpoint JSON now reports "version": 0.4 (was 0.3).

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and specifically describes the main change: validation of HP_SHARED_KEY to reject FRP-incompatible characters.
Linked Issues check ✅ Passed Changes align with issue #103 requirements: HP_SHARED_KEY validation rejects incompatible characters with clear error messages, and version bump to 0.4 documents the fix.
Out of Scope Changes check ✅ Passed All changes are directly scoped to issue #103: validation logic in start.sh, version bump in haproxy_agent.py, with no unrelated modifications.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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


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

@oleksandr-nc oleksandr-nc marked this pull request as ready for review May 11, 2026 09:33
@oleksandr-nc oleksandr-nc requested a review from kyteinsky as a code owner May 11, 2026 09:33
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@start.sh`:
- Around line 131-137: The forbidden-character check runs on HP_SHARED_KEY
before normalization; call the existing strip_quotes normalization on
HP_SHARED_KEY first (i.e., replace HP_SHARED_KEY with the normalized value
produced by strip_quotes) and then compute FORBIDDEN_COUNT (the tr/wc check) so
wrapped values like 'secret' or "secret" are accepted while still rejecting
embedded double-quote, single-quote, or backslash characters; update references
to FORBIDDEN_COUNT and any subsequent usage to use the normalized HP_SHARED_KEY
variable.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1727ca64-aa21-4de8-9666-06fd34ed326f

📥 Commits

Reviewing files that changed from the base of the PR and between f68704b and cdb586a.

📒 Files selected for processing (2)
  • haproxy_agent.py
  • start.sh

Comment thread start.sh Outdated
…ing apostrophes

Signed-off-by: Oleksander Piskun <oleksandr2088@icloud.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
start.sh (1)

130-141: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Apostrophe is still silently lossy with current normalization flow.

At Line 127, strip_quotes() removes leading/trailing ', but Lines 130-141 no longer reject '. This can still mutate a valid key (e.g., edge apostrophes) and lead to FRP token mismatch. If apostrophes are not fully supported end-to-end, they should remain rejected here.

💡 Minimal fix
-FORBIDDEN_COUNT=$(printf '%s' "$HP_SHARED_KEY" | LC_ALL=C tr -cd '"\\' | wc -c)
+FORBIDDEN_COUNT=$(printf '%s' "$HP_SHARED_KEY" | LC_ALL=C tr -cd "\"\\\\'" | wc -c)
 if [ "$FORBIDDEN_COUNT" -gt 0 ]; then
     echo "ERROR: HP_SHARED_KEY contains a forbidden character."
-    echo "The following characters are not allowed: double quote (\"), backslash (\\)."
+    echo "The following characters are not allowed: double quote (\"), single quote ('), backslash (\\)."
     echo "Please choose a password without these characters."
     exit 1
 fi
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@start.sh` around lines 130 - 141, The current validation after strip_quotes()
checks only for double quotes and backslashes but not apostrophes, which allows
silent lossiness when strip_quotes() removes edge single quotes; update the
forbidden-character check for HP_SHARED_KEY (used with strip_quotes()) to
include the single quote character (') in the set counted by FORBIDDEN_COUNT and
update the error message to mention single quotes as disallowed so keys
containing apostrophes are rejected rather than silently mutated; locate the
FORBIDDEN_COUNT calculation and the error output block that references
HP_SHARED_KEY to make this change.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@start.sh`:
- Around line 130-141: The current validation after strip_quotes() checks only
for double quotes and backslashes but not apostrophes, which allows silent
lossiness when strip_quotes() removes edge single quotes; update the
forbidden-character check for HP_SHARED_KEY (used with strip_quotes()) to
include the single quote character (') in the set counted by FORBIDDEN_COUNT and
update the error message to mention single quotes as disallowed so keys
containing apostrophes are rejected rather than silently mutated; locate the
FORBIDDEN_COUNT calculation and the error output block that references
HP_SHARED_KEY to make this change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1ad2ceac-fc37-4ec2-a720-675e5c37929d

📥 Commits

Reviewing files that changed from the base of the PR and between cdb586a and ac274bf.

📒 Files selected for processing (1)
  • start.sh

@kyteinsky kyteinsky requested a review from Copilot May 11, 2026 10:42
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Rejects FRP-incompatible characters in HP_SHARED_KEY earlier to prevent generating invalid FRP TOML and bumps the /info endpoint version.

Changes:

  • Add validation in start.sh to reject HP_SHARED_KEY values containing TOML-breaking characters.
  • Improve error messaging for invalid HP_SHARED_KEY.
  • Bump /info endpoint version from 0.3 to 0.4.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
start.sh Adds upfront validation for HP_SHARED_KEY to prevent corrupt FRP TOML generation.
haproxy_agent.py Updates /info response version to 0.4.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread start.sh
Comment on lines +135 to +141
FORBIDDEN_COUNT=$(printf '%s' "$HP_SHARED_KEY" | LC_ALL=C tr -cd '"\\' | wc -c)
if [ "$FORBIDDEN_COUNT" -gt 0 ]; then
echo "ERROR: HP_SHARED_KEY contains a forbidden character."
echo "The following characters are not allowed: double quote (\"), backslash (\\)."
echo "Please choose a password without these characters."
exit 1
fi
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated PR description 👍

Comment thread start.sh
Comment thread haproxy_agent.py
@oleksandr-nc oleksandr-nc merged commit e0079d1 into main May 11, 2026
19 checks passed
@oleksandr-nc oleksandr-nc deleted the fix/shared-key-special-chars branch May 11, 2026 11:01
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.

Super Secret password with special characters not accepted and blocking startup of HARP

3 participants