pyscg-0034 is assumin implicit optional types against PEP484

Đang mở
#2 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.

Đá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
52/100
Loại issue
Tài liệu
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
documentation, security

Hướng nghiên cứu

Read the pyscg-0034 guideline section linked in the issue, especially its compliant and non-compliant examples, and compare the stated rule with the Optional type annotations and behavior described in the report. Decide whether the recommendation should be corrected or removed, then update the guideline so its rule and examples agree; done means the guidance addresses the reported type-checking and input-validation concerns.

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

Mô tả

bug

The python guideline psycg-0034 is incorrect, or at least outdated, you shouldn't check that a typed signature is not None if it's not typed as optional, and this is the behaviour of most type checkers, like mypy after 0.991 release.

The compliant case has the same explotation as the non compliant one, if you input another param.

is_valid_name(1) will raise an exception on both compliant and not compliant. There is no difference between None and 1, and there is no null pointer dereference in any case. If you try to pass an incorrect type to a function you will get a type error. You should check for None, if the function can receive None. And check for everything if the function can return anything. In any case, if you don't trust the param, you can get RCE with any param, even checking:

""" Compliant Code Example """
from typing import Optional


def is_valid_name(s: Optional[str]) -> bool:
    """ Check if the input is a name with 2 capitalised Strings """
    if s is None:
        return False
    if isinstance(s, str):
        names = s.split()
        if len(names) != 2:
            return False
        return s.istitle()


#####################
# Attempting to exploit above code example
#####################
class Exploit(str):
    def split(self):
        print("you are hacked")
name = is_valid_name(Exploit())

I suggest delete that recommendation

Ngôn ngữ chính
Python
Star
2
Fork
2
Merge trung bình
11 phút
Pull request đã merge (30 ngày)
2

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 ossf/python-secure-coding-guide

Tất cả issue của ossf/python-secure-coding-guide

Issue tương tự

Thêm issue về Python

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.