Skip to content

refactor: FeatureFlag.Save and PropertySet.Save lack atomic write #37

@HeyItsGilbert

Description

@HeyItsGilbert

Summary

Both Save methods write directly to the target file with Set-Content. A process crash mid-write leaves a partially written, corrupt file. On shared machines where the flag store is in a common location, there is no integrity guarantee.

Files

  • Gatekeeper/Classes/FeatureFlag.ps1:184
  • Gatekeeper/Classes/Property.ps1:182

Fix

Write to a temp file then atomically rename:

[void]Save() {
    if ($null -eq $this.FilePath) { throw 'No file path specified to save FeatureFlag.' }
    $tmpPath = "$($this.FilePath).tmp"
    $json = $this | ConvertTo-Json -Depth 10 -EnumsAsStrings
    Set-Content -Path $tmpPath -Value $json
    Move-Item -Path $tmpPath -Destination $this.FilePath -Force
}

Notes

  • Found by DualCore (security review)

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactorCode quality, structure, or naming

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions