Пример #1
0
def sanitize_test_b_source_attribute():
    if 1 > 2:
        x = a_source()
    else:
        x = b_source()
    c = C_sanitized_b_source(x)
    _test_sink(c.attribute)
Пример #2
0
def sanitize_all_sinks_instance(c: C_sanitized_all_sinks):
    if 1 > 2:
        a_sink(c.instance)
    elif 2 > 3:
        b_sink(c.instance)
    else:
        _test_sink(c.instance)
Пример #3
0
def setters_are_simulated() -> None:
    x = SetterMutatesValue()
    # Expect no issue
    _test_sink(x.p)
    x.p = _test_source()
    # x.p should now have an issue
    _test_sink(x.p)
Пример #4
0
def sanitize_all_sinks_attribute(c: C_sanitized_all_sinks):
    if 1 > 2:
        a_sink(c.attribute)
    elif 2 > 3:
        b_sink(c.attribute)
    else:
        _test_sink(c.attribute)
Пример #5
0
def test_union_property_attribute_sink(x):
    obj: Union[TaintedGetterAndSetter, RegularAttribute]
    if 1 > 2:
        obj = TaintedGetterAndSetter()
    else:
        obj = RegularAttribute(x)
    _test_sink(obj.my_property)
Пример #6
0
def sanitize_test_ab_sources_instance():
    if 1 > 2:
        x = a_source()
    else:
        x = b_source()
    c = C_sanitized_ab_sources(x)
    _test_sink(c.instance)  # should only trigger Test -> Test
Пример #7
0
def sanitize_test_b_source_instance():
    if 1 > 2:
        x = a_source()
    else:
        x = b_source()
    c = C_sanitized_b_source(x)
    _test_sink(c.instance)
Пример #8
0
def test_within_try_to_finally():
    x = None
    try:
        x = _test_source()
        return none_throws(x)
    finally:
        # TODO(T106611060): We do not find the issue here.
        _test_sink(x)
Пример #9
0
def test_except_to_finally():
    x = None
    try:
        return none_throws(x)
    except:
        x = _test_source()
    finally:
        _test_sink(x)
Пример #10
0
def lists_of_dictionary_iteration_is_precise():
    list_of_dicts = [{
        "with_feature": _test_source(),
        "without_feature": 0
    } for x in []]
    for dict in list_of_dicts:
        _test_sink(dict["with_feature"])
        _test_sink(dict["without_feature"])
Пример #11
0
def alternate_fields():
    d = {"a": _test_source(), "b": _test_source()}
    if 1 > 2:
        x = d["a"]
    else:
        x = d["b"]
    _test_sink(x)
    return x
Пример #12
0
def test_items_backward_values(x, y):
    key_is_tainted = {x: "a"}
    value_is_tainted = {"b": y}
    for k, v in key_is_tainted.items():
        _test_sink(v)

    for k, v in value_is_tainted.items():
        _test_sink(v)
Пример #13
0
def test2_alarm4(foo):
    # via-type:Dict[str, int], via-type:List[str], via-type:float
    c = Test2_C(_test_source())
    foo = c.x
    if 1:
        foo = c.y
    elif 2:
        foo = c.z
    _test_sink(foo)
Пример #14
0
def test1_alarm4(foo):
    # via-type:int, via-type:str, via-type:typing.Annotated[str]
    c = Test1_C(_test_source())
    foo = c.x
    if 1:
        foo = c.y
    elif 2:
        foo = c.z
    _test_sink(foo)
Пример #15
0
def sanitize_test_all_sources_instance():
    if 1 > 2:
        x = a_source()
    elif 2 > 3:
        x = b_source()
    else:
        x = _test_source()
    c = C_sanitized_all_sources(x)
    _test_sink(c.instance)
Пример #16
0
def sanitize_test_all_sources_attribute():
    if 1 > 2:
        x = a_source()
    elif 2 > 3:
        x = b_source()
    else:
        x = _test_source()
    c = C_sanitized_all_sources(x)
    _test_sink(c.attribute)
Пример #17
0
def test3_alarm4(c: Test3_C, foo):
    # via-type:Dict[str, List[int]],
    # via-type:Test3_Foo,
    # via-type:typing.Annotated[List[List[str]]
    foo = c.x
    if 1:
        foo = c.y
    elif 2:
        foo = c.z
    _test_sink(foo)
Пример #18
0
def test_keys_and_values():
    tainted_values = {"benign": ("benign", _test_source())}
    # Should be an issue.
    _test_sink(tainted_values.values())
    # Shouldn't be an issue.
    _test_sink(tainted_values.keys())
    for item in tainted_values.values():
        _test_sink(item[0])

    tainted_keys = {_test_source(): ""}
    # Should be an issue.
    _test_sink(tainted_keys.keys())
    # Shouldn't be an issue.
    _test_sink(tainted_keys.values())
Пример #19
0
def issue_only_with_nested_first():
    first, second = only_applies_to_nested()
    a, issue = first
    c, d = second
    _test_sink(issue)
    _test_sink(a)
    _test_sink(c)
    _test_sink(d)
    return only_applies_to_nested()
Пример #20
0
def test(complicated_service: ComplicatedService):
    exception = False
    result = None
    try:
        result = complicated_service.serve_tainted_request()

    except:
        exception = True

    # Only try reactivation if all other checks passed
    if exception:
        try:
            result = complicated_service.serve_tainted_request()
        except:
            raise

    _test_sink(result)
Пример #21
0
def test_items():
    key_is_tainted = {_test_source(): ""}
    value_is_tainted = {"a": _test_source()}
    for k, v in key_is_tainted.items():
        # Should be an issue.
        _test_sink(k)
        # Should not be an issue.
        _test_sink(v)

    for k, v in value_is_tainted.items():
        # Should not be an issue.
        _test_sink(k)
        # Should be an issue.
        _test_sink(v)
Пример #22
0
def dict_update_sinks(x, y, z):
    d = {"a": x, "b": y}
    d.update({"a": "safe", "c": z})
    _test_sink(d["a"])
    _test_sink(d["b"])
    _test_sink(d["c"])
    return
Пример #23
0
def locals_to_sink():
    # No issue before assigning.
    _test_sink(locals()["x"])
    x = _test_source()

    _test_sink(locals()["x"])
    _test_sink(locals()["y"])

    # We properly handle named parameters through `**`.
    named_sink(**locals())
Пример #24
0
def format_sink(x):
    y = "a {}".format(x)
    _test_sink(y)
Пример #25
0
def through_iadd():
    a = _test_source()
    b = ""
    b += a
    _test_sink(b)
Пример #26
0
def maybe_rhs(b: bool):
    if b:
        a = _test_source()
    else:
        a = concatenate_rhs(_test_source())
    _test_sink(a)
Пример #27
0
def either(b: bool):
    if b:
        a = concatenate_lhs(_test_source())
    else:
        a = concatenate_rhs(_test_source())
    _test_sink(a)
Пример #28
0
def bad_2():
    a = concatenate_rhs(_test_source())
    _test_sink(a)
Пример #29
0
def bad_1():
    a = concatenate_lhs(_test_source())
    _test_sink(a)
Пример #30
0
async def async_issue_bools() -> None:
    x, y = await async_tuple_of_bools()
    _test_sink(x)