Skip to content

don't allow empty keys#2193

Merged
j-chmielewski merged 5 commits intomainfrom
fix-empty-keys
Mar 5, 2026
Merged

don't allow empty keys#2193
j-chmielewski merged 5 commits intomainfrom
fix-empty-keys

Conversation

@j-chmielewski
Copy link
Copy Markdown
Contributor

No description provided.

moubctez
moubctez previously approved these changes Mar 5, 2026
filipslezaklab
filipslezaklab previously approved these changes Mar 5, 2026
@j-chmielewski j-chmielewski dismissed stale reviews from filipslezaklab and moubctez via dd5a251 March 5, 2026 11:55
@wojcik91 wojcik91 requested a review from Copilot March 5, 2026 12:40
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

This PR adds validation to prevent empty authentication keys from being submitted, along with GPG key verification on the backend. It also updates the key input from a single-line input to a textarea and bumps several frontend dependencies.

Changes:

  • Adds frontend validation for minimum key length and switches the key input from FormInput to FormTextarea for better UX with long keys.
  • Implements server-side GPG key verification using the pgp crate, replacing a previous FIXME comment.
  • Bumps multiple frontend dependency versions in package.json.

Reviewed changes

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

File Description
web/src/shared/defguard-ui Updates the defguard-ui subproject commit reference.
web/src/pages/.../AddAuthenticationKeyForm.tsx Switches key input to textarea, adds .min() validations, and adjusts regex for trimming trailing newlines.
web/package.json Bumps several dependency versions.
crates/defguard_core/src/handlers/ssh_authorized_keys.rs Adds GPG key verification using SignedPublicKey::from_string.
Files not reviewed (1)
  • web/pnpm-lock.yaml: Language not supported

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

})
.trim(),
.trim()
.min(1, LL.form.error.required())
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

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

The .min(1, LL.form.error.required()) check is redundant because .min(50, ...) on the next line already guarantees the string has at least 50 characters (which implies it's non-empty). You can remove the .min(1, ...) call and rely solely on .min(50, LL.form.error.minimumLength()) — the required_error on the string() call above already handles the truly-empty / missing case.

Suggested change
.min(1, LL.form.error.required())

Copilot uses AI. Check for mistakes.
if (user) {
mutate({
key: trimmed.keyValue.replace(/\r?\n|\r/g, ''),
key: trimmed.keyValue.replace(/[\r\n]+$/, ''),
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

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

The original regex /\r?\n|\r/g stripped all internal newlines/carriage-returns from the key value. The new regex /[\r\n]+$/ only removes trailing newline characters. For SSH keys (which should be a single line), internal newlines from a user pasting a wrapped key will now be preserved and sent to the server, likely causing SSH key validation to fail. Consider keeping internal newline stripping (e.g. /[\r\n]+/g) or at least stripping internal newlines for SSH keys specifically.

Copilot uses AI. Check for mistakes.
@j-chmielewski j-chmielewski merged commit e330a73 into main Mar 5, 2026
10 of 11 checks passed
@j-chmielewski j-chmielewski deleted the fix-empty-keys branch March 5, 2026 12:55
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.

5 participants