xref: /aosp_15_r20/external/cronet/testing/libfuzzer/proto/url.proto (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1// Copyright 2017 The Chromium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// This file contains the definition of the Url protobuf used in the
6// url_parse_proto_fuzzer that is meant to serve as an example for future
7// Chromium fuzzers that use libprotobuf-mutator. We will consider the format of
8// a URL for this fuzzer, to be
9// [scheme:][//[user[:password]@]host[:port]][/path][?query][#value] There may
10// be some URLs Chromium treats as valid that this syntax does not capture.
11// However, we will ignore them for the sake of simplicity. It is recommended to
12// read this file in conjunction with Convert() in url_proto_converter.cc as
13// logic in this function is sometimes used to ensure that the Url Protocol
14// Buffer obeys the syntax we have defined for URLs. Though reading it is
15// completely unnecessary for understanding this fuzzer, we have roughly
16// followed RFC 3986 (https://tools.ietf.org/html/rfc3986) which defines the
17// syntax of URIs (which URLs are a subset of).
18
19syntax = "proto2";
20
21package url_proto;
22
23// Here we define the format for a Url Protocol Buffer. This will be passed to
24// our fuzzer function.
25message Url {
26  // If there is a scheme, then it must be followed by a colon. A scheme is in
27  // practice not required in a URL. Therefore, we will define the scheme as
28  // optional but ensure it is followed by a colon in our conversion code if it
29  // is included.
30  optional string scheme = 1;
31
32  enum Slash {
33    NONE = 0;      // Separate path segments using ""
34    FORWARD = 1;   // Separate path segments using /
35    BACKWARD = 2;  // Separate path segments using \
36  }
37    // The syntax rules of the two slashes that precede the host in a URL are
38    // surprisingly complex. They are not required, even if a scheme is included
39    // (http:example.com is treated as valid), and are valid even if a scheme is
40    // not included (//example.com is treated as file:///example.com). They can
41    // even be backslashes (http:\\example.com and http\/example.com are both
42    // valid) and there can be any number of them (http:/example.com and
43    // http://////example.com are both valid).
44    // We will therefore define slashes as a list of enum values (repeated
45    // Slash). In our conversion code, this will be read to append the
46    // appropriate kind and appropriate number of slashes to the URL.
47    repeated Slash slashes = 2 [packed = true];
48
49    // The [user:password@] part of the URL shown above is called the userinfo.
50    // Userinfo is not mandatory, but if it is included in a URL, then it must
51    // contain a string called user. There is another optional field in userinfo
52    // called the password. If a password is included, the user must be
53    // separated from it by ":". In either case, the userinfo must be separated
54    // from the host by "@". A URL must have a host if it has a userinfo. These
55    // requirements will be ensured by the conversion code.
56    message Userinfo {
57      required string user = 1;
58      optional string password = 2;
59    }
60    optional Userinfo userinfo = 3;
61
62    // Hosts, like most else in our Url definition, are optional (there are
63    // are URLs such as data URLs that do not have hosts).
64    optional string host = 4;
65
66    // Ports are unsigned integers between 1-2^16. The closest type to this in
67    // the proto2 format is uint32. Also if a port number is specified it must
68    // be preceded by a colon (consider "google.com80" 80 will be interpreted as
69    // part of the host). The conversion code will ensure this is the case.
70    optional uint32 port = 5;
71
72    // The rules for the path are somewhat complex. A path is not required,
73    // however if it follows a port or host, it must start with "/" according
74    // to the RFC, though Chromium accepts "\" as it converts all backslashes to
75    // slashes. It does not need to start with "/" if there is no host (in data
76    // URLs for example). Thus we will define path as a repeated string where
77    // each member contains a segment of the path and will be preceded by the
78    // path_separator. The one exception to this is for the first segment if
79    // path_seperator == NONE and there is a non empty path and host, then the
80    // first segment will be preceded by "/".
81    repeated string path = 6;
82    required Slash path_separator = 7 [default = FORWARD];
83
84    // A query must preceded by "?". This will be ensured in the conversion
85    // code. Queries can have many components which the converter will separate
86    // using "&", as is the convention.
87    repeated string query = 8;
88
89    // A fragment must preceded by "#". This will be ensured in the conversion
90    // code.
91    optional string fragment = 9;
92  }
93