Language: Python
Label: vulnerable
CWE: CWE-20 \u2014 Improper Input Validation
The product receives input or data, but it does
        not validate or incorrectly validates that the input has the
        properties that are required to process the data safely and
        correctly.

Code:
def test_upload_file(httpbin):
    browser = mechanicalsoup.StatefulBrowser()
    browser.open(httpbin + "/forms/post")

    # Create two temporary files to upload
    def make_file(content):
        path = tempfile.mkstemp()[1]
        with open(path, "w") as fd:
            fd.write(content)
        return path
    path1, path2 = (make_file(content) for content in
                    ("first file content", "second file content"))

    # The form doesn't have a type=file field, but the target action
    # does show it => add the fields ourselves, and add enctype too.
    browser.select_form()
    browser._StatefulBrowser__state.form.form[
      "enctype"] = "multipart/form-data"
    browser.new_control("file", "first", path1)
    browser.new_control("file", "second", "")
    browser["second"] = path2
    browser.form.print_summary()
    response = browser.submit_selected()
    files = response.json()["files"]
    assert files["first"] == "first file content"
    assert files["second"] == "second file content"