Skip to content

we don't check if the user supplies the correct number of bytes when specifying content-length #251

Closed
@weissi

Description

@weissi

I don't have time right now to fix this but these too tests show the issue:

    func testContentLengthTooLongFails() {
        let url = self.defaultHTTPBinURLPrefix + "/post"
        XCTAssertThrowsError(
            try self.defaultClient.execute(request:
                                            Request(url: url,
                                                    body: .stream(length: 10) { streamWriter in
                                                        streamWriter.write(.byteBuffer(ByteBuffer(string: "1")))
                                                    })).wait()) { error in
            // TODO: content-length wrong error.
        }
        // Quickly try another request and check that it works.
        XCTAssertNoThrow(try self.defaultClient.get(url: self.defaultHTTPBinURLPrefix + "/get").wait())
    }

    // currently gets stuck because of #250 the server just never replies
    func testContentLengthTooShortFails() {
        let url = self.defaultHTTPBinURLPrefix + "/post"
        let tooLong = "XBAD BAD BAD NOT HTTP/1.1\r\n\r\n"
        XCTAssertThrowsError(
            try self.defaultClient.execute(request:
                                            Request(url: url,
                                                    body: .stream(length: 1) { streamWriter in
                                                        streamWriter.write(.byteBuffer(ByteBuffer(string: tooLong)))
                                                    })).wait()) { error in
            // TODO: content-length wrong error.
        }
        // Quickly try another request and check that it works. If we by accident wrote some extra bytes into the
        // stream (and reuse the connection) that could cause problems.
        XCTAssertNoThrow(try self.defaultClient.get(url: self.defaultHTTPBinURLPrefix + "/get").wait())
    }

This probably needs to be a blocker because with a connection pool, this is security relevant. We could end up sending private bytes for one request into the next request by accident.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugFeature doesn't work as expected.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions