Subscription status response validators omit validation of data and nested lastTransactions

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

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

  • #467 của @Shubham-Padkonde — đã đóng, không merge

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
84/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript
Lĩnh vực
api

Hướng nghiên cứu

Bắt đầu bằng cách kiểm tra các validator trong dist/models/StatusResponse.js, dist/models/SubscriptionGroupIdentifierItem.js và dist/models/LastTransactionsItem.js sau khi build package. Theo dõi cách các mảng tùy chọn và validator lồng nhau được xử lý, sau đó thêm phạm vi kiểm thử hồi quy cho các kiểu mảng không hợp lệ, các mục lồng nhau sai định dạng và các trường bị bỏ qua hoặc lồng nhau hợp lệ. Công việc được xem là hoàn tất khi các response lồng nhau không hợp lệ trả về false, trong khi các response hợp lệ và các trường tùy chọn bị bỏ qua vẫn được chấp nhận.

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

Mô tả

Description

StatusResponseValidator checks environment, bundleId and appAppleId, but never validates data, which is declared as SubscriptionGroupIdentifierItem[].

There is a second gap in the nested model: SubscriptionGroupIdentifierItemValidator checks only subscriptionGroupIdentifier and never validates lastTransactions, which is declared as LastTransactionsItem[].

Consequently, the response validator accepts a non-array data value, malformed subscription-group entries and malformed transaction entries. Connecting StatusResponseValidator to the existing subscription-group validator alone would not fully address the problem, because that validator also omits its nested array.

Reproduction

From the repository root, after building the package:

const {
  StatusResponseValidator,
} = require('./dist/models/StatusResponse.js');
const {
  SubscriptionGroupIdentifierItemValidator,
} = require('./dist/models/SubscriptionGroupIdentifierItem.js');
const {
  LastTransactionsItemValidator,
} = require('./dist/models/LastTransactionsItem.js');

const responseValidator = new StatusResponseValidator();
const groupValidator = new SubscriptionGroupIdentifierItemValidator();
const transactionValidator = new LastTransactionsItemValidator();

console.log(responseValidator.validate({ data: 'not-an-array' }));
// true

console.log(groupValidator.validate({ lastTransactions: 'not-an-array' }));
// true

const invalidTransaction = { signedTransactionInfo: 123 };
console.log(responseValidator.validate({
  data: [{
    subscriptionGroupIdentifier: '123',
    lastTransactions: [invalidTransaction],
  }],
}));
// true

console.log(transactionValidator.validate(invalidTransaction));
// false
Expected behavior

When present, data must be an array of valid subscription-group items. Within each group, lastTransactions, when present, must be an array of valid transaction items. Invalid nested values should cause validation of the containing response to return false.

Omitted optional fields should remain accepted, consistent with the current model definitions.

Impact

AppStoreServerAPIClient.getAllSubscriptionStatuses uses StatusResponseValidator. Its runtime validation therefore does not enforce the declared structure of the subscription data returned to callers. Downstream code may receive incompatible values despite a successful client validation result.

This concerns structural validation of the API response. Cryptographic verification of the signed transaction and renewal payloads remains a separate operation.

Suggested change
  • In StatusResponseValidator, check that a present data value is an array and validate each entry with SubscriptionGroupIdentifierItemValidator.
  • In SubscriptionGroupIdentifierItemValidator, check that a present lastTransactions value is an array and validate each entry with LastTransactionsItemValidator.
  • Add regression coverage for invalid array types, invalid nested fields and valid nested responses.
Ngôn ngữ chính
TypeScript
Star
388
Fork
88
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

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.

Issue khác của apple/app-store-server-library-node

Tất cả issue của apple/app-store-server-library-node

Issue tương tự

Thêm issue về TypeScript

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.