[PR #207] fix: name the real S1-S4 parameter in the header protection padding error #205

Open
opened 2026-11-07 18:00:31 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/amnezia-vpn/amneziawg-go/pull/207
Author: @Dv2Corn
Created: 11/5/2026
Status: 🔄 Open

Base: master ← Head: fix/header-protection-padding-error


📝 Commits (1)

  • 4706820 fix: name the real S1-S4 parameter in the header protection padding error

📊 Changes

2 files changed (+83 additions, -1 deletions)

View changed files

📝 device/uapi.go (+1 -1)
➕ device/uapi_test.go (+82 -0)

📄 Description

  • With header_protection_key set, the padding check in mergeWithDevice (device/uapi.go#L852-L858) printed the zero-based slice index, so a too small S1 was reported as "S0", S2 as "S1" and so on, and S4 was never named. The text also said "more then 12" although 12 is accepted. The error now names the real parameter, says "at least", and includes the configured value, e.g. S4 must be at least 12 to use header protection, got 0.
  • The requirement itself is kept: every one of S1-S4 has to be at least 12. The receiver takes the header protection nonce from the first 12 bytes of every datagram before it knows the message type (device/receive.go#L144), and every message type is protected: initiation, response, cookie reply and transport (device/send.go#L165, L222, L270, L632). With a padding shorter than 12, the sender's crypt[:HeaderCipherNonceSize] reaches into the message header that is encrypted right afterwards, so the receiver would derive a different keystream and drop the packet. This matches the README (README.md#L81).
  • Added device/uapi_test.go with TestHeaderProtectionPaddingValidation: no key with zero paddings is accepted, all paddings at exactly 12 are accepted, and S1, S2, S3 or S4 below 12 is rejected with an error naming that parameter. The four rejection cases fail before this change and pass after it.

Fixes #201


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/amnezia-vpn/amneziawg-go/pull/207 **Author:** [@Dv2Corn](https://github.com/Dv2Corn) **Created:** 11/5/2026 **Status:** 🔄 Open **Base:** `master` ← **Head:** `fix/header-protection-padding-error` --- ### 📝 Commits (1) - [`4706820`](https://github.com/amnezia-vpn/amneziawg-go/commit/4706820c1fe8ef833ae53fc8750c9d00ae4bd20f) fix: name the real S1-S4 parameter in the header protection padding error ### 📊 Changes **2 files changed** (+83 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `device/uapi.go` (+1 -1) ➕ `device/uapi_test.go` (+82 -0) </details> ### 📄 Description * With `header_protection_key` set, the padding check in `mergeWithDevice` ([device/uapi.go#L852-L858](https://github.com/amnezia-vpn/amneziawg-go/blob/b5928efb6ca19f0153958460c3d141f04abc5c2e/device/uapi.go#L852-L858)) printed the zero-based slice index, so a too small S1 was reported as "S0", S2 as "S1" and so on, and S4 was never named. The text also said "more then 12" although 12 is accepted. The error now names the real parameter, says "at least", and includes the configured value, e.g. `S4 must be at least 12 to use header protection, got 0`. * The requirement itself is kept: every one of S1-S4 has to be at least 12. The receiver takes the header protection nonce from the first 12 bytes of every datagram before it knows the message type ([device/receive.go#L144](https://github.com/amnezia-vpn/amneziawg-go/blob/b5928efb6ca19f0153958460c3d141f04abc5c2e/device/receive.go#L144)), and every message type is protected: initiation, response, cookie reply and transport ([device/send.go#L165](https://github.com/amnezia-vpn/amneziawg-go/blob/b5928efb6ca19f0153958460c3d141f04abc5c2e/device/send.go#L165), [L222](https://github.com/amnezia-vpn/amneziawg-go/blob/b5928efb6ca19f0153958460c3d141f04abc5c2e/device/send.go#L222), [L270](https://github.com/amnezia-vpn/amneziawg-go/blob/b5928efb6ca19f0153958460c3d141f04abc5c2e/device/send.go#L270), [L632](https://github.com/amnezia-vpn/amneziawg-go/blob/b5928efb6ca19f0153958460c3d141f04abc5c2e/device/send.go#L632)). With a padding shorter than 12, the sender's `crypt[:HeaderCipherNonceSize]` reaches into the message header that is encrypted right afterwards, so the receiver would derive a different keystream and drop the packet. This matches the README ([README.md#L81](https://github.com/amnezia-vpn/amneziawg-go/blob/b5928efb6ca19f0153958460c3d141f04abc5c2e/README.md#L81)). * Added `device/uapi_test.go` with `TestHeaderProtectionPaddingValidation`: no key with zero paddings is accepted, all paddings at exactly 12 are accepted, and S1, S2, S3 or S4 below 12 is rejected with an error naming that parameter. The four rejection cases fail before this change and pass after it. Fixes #201 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
amnezia-vpn/amneziawg-go#205
No description provided.