nodejs / nodejs/node

Permission allow-fs-* to resolve env variables

Đang mở
#65,422 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

feature request permission
Ngôn ngữ chính
JavaScript
Star
122k
Fork
37.3k
Merge trung bình
4 ngày 2 giờ
Pull request đã merge (30 ngày)
283

Mô tả

What is the problem this feature will solve?

While it is possible to pass values of env variables when calling node directly

node --permission --allow-fs-read=$HOME

there are other ways to set permissions (in config file or via NODE_OPTIONS) that don't go through the shell first.

I'd like to make it possible for all methods of passing in permissions to support using environment variables.

{
  "nodeOptions": {
    "--permission": true,
    "--allow-fs-read": [
      "$HOME"
    ]
  }
}
What is the feature you are proposing to solve the problem?

Pseudocode:

    const replaceEnvVar = (value) => {
      const envVarMatch = value.match(/^\$([A-Z_][A-Z0-9_]*)$/i)
      if (envVarMatch) {
        const envVarName = envVarMatch[1]
        if (process.env[envVarName] !== undefined) {
          return process.env[envVarName]
        } else {
          console.error(
            `[LavaMoat] Environment variable "${envVarName}" referenced in config but not found in environment`
          )
        }
      }
      return value
    }

    for (const key of ['--allow-fs-read', '--allow-fs-write']) {
      if (Array.isArray(configOptions[key])) {
        configOptions[key] = configOptions[key].map(replaceEnvVar)
      } else if (typeof configOptions[key] === 'string') {
        configOptions[key] = replaceEnvVar(configOptions[key])
      }
    }
What alternatives have you considered?

I've considered more advanced support where this would also work:

{
  "nodeOptions": {
    "--permission": true,
    "--allow-fs-read": [
      "/home/${MY_USER}/some/place/else"
    ]
  }
}

but it seems unnecessarily complex and error prone to be worth it IMHO.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách lần theo cách Node.js phân tích --allow-fs-read và --allow-fs-write từ các đối số trực tiếp, NODE_OPTIONS và các tệp cấu hình. Kiểm tra các bài kiểm thử permission-option hiện có và bổ sung phạm vi kiểm thử cho các giá trị chính xác của environment-variable ở dạng string và array. Được xem là hoàn tất khi các đầu vào permission được hỗ trợ phân giải các biến môi trường một cách nhất quán, bao gồm cả hành vi khi một biến chưa được thiết lập.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript
Lĩnh vực
cli, security
Loại issue
Tính năng
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Sôi nổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
55/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.