Skip to content

fs.chmod behaviour should change to be more expected across platforms #30019

@exx8

Description

@exx8

Is your feature request related to a problem? Please describe.
fs.chmod currently behaves a bit odd across different platforms:
On linux and unix like system it behaves as expected if mode<=777.
On windows on the other hand it ignores the group and other permissions, and changes the 'read-only' attribute. This is problematic because:

  1. Making file readonly doesn't really prevent anyone from changing its content. one can just undo read-only. So chmod doesn't do what it meant to do; user can change the file if a write permission set elsewhere outside node. Using chmod doesn't restrict its usage.. this might also be a minor security issue.
  2. User might get the false impression that node is compatible with windows' acl permission policy (regarding group and other permissions). Which currently isn't the case because libuv doesn't support it. Because of that, bugs which are related to other users permissions might happen.
  3. User who passes numbers greater than 777 accidentally might experience random platform dependent bugs. As according the docs, "any value larger than 0o777 may result in platform-specific behaviors that are not supported to work consistently".

Describe the solution you'd like

  1. fs.chmod will throw newly created ERR_FEATURE_UNAVAILABLE_ON_PLATFORM on windows.
  2. Current windows logic of fs.chmod will be separated to different method fs.makeReadonly. related functionality of other platforms should be researched and used. If not found, ERR_FEATURE_UNAVAILABLE_ON_PLATFORM should be thrown.
  3. chmod will no longer support passing modes greater than 777. An exception will be thrown instead. If for some reason in the future a new mode will be added, or will be discovered, this behavior will change.
    Describe alternatives you've considered
    any combination of 1,2,3.

Metadata

Metadata

Assignees

No one assigned

    Labels

    fsIssues and PRs related to the fs subsystem / file system.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions