Skip to content

htpasswd.entry does not observe the mode its apply sets #635

Description

@haribo

Part of #634.

htpasswd.entry's apply ends with:

mv -f "$staged" "$path"
# A credentials file readable by anyone is the credential leaked.
chmod 600 "$path"

Its observe returns a single field — whether the stored hash verifies against the password.
A file with the right hash at mode 644 is therefore reported already, and the chmod
never runs. The def's own comment says what that costs.

sudo.write and sshd.config, the two defs built like it, each observe a secured field
beside their content field. This one does not.

Build

Add the mode to the observe, as its neighbours do — state(valid: …, secured: …). Their
spelling is [ "$(stat -c '%a' "$f")" = "600" ]; file.mode uses an awk numeric compare
for a reason worth reading before copying either (#543).

Validation

  • An adverse case: a correct file chmod'd 644 on purpose, then the def, then assert the
    mode on the machine
    . Verified red before the fix.
  • The existing adverse-htpasswd.entry.shellf and adverse-htpasswd.regex-login.shellf
    stay green — neither asserts the mode today, which is how this survived.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugdefect or malfunction

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions