webrisk.proto 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. // Copyright 2022 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. syntax = "proto3";
  15. package google.cloud.webrisk.v1;
  16. import "google/api/annotations.proto";
  17. import "google/api/client.proto";
  18. import "google/api/field_behavior.proto";
  19. import "google/api/resource.proto";
  20. import "google/protobuf/timestamp.proto";
  21. option csharp_namespace = "Google.Cloud.WebRisk.V1";
  22. option go_package = "google.golang.org/genproto/googleapis/cloud/webrisk/v1;webrisk";
  23. option java_multiple_files = true;
  24. option java_outer_classname = "WebRiskProto";
  25. option java_package = "com.google.webrisk.v1";
  26. option objc_class_prefix = "GCWR";
  27. option php_namespace = "Google\\Cloud\\WebRisk\\V1";
  28. option ruby_package = "Google::Cloud::WebRisk::V1";
  29. // Web Risk API defines an interface to detect malicious URLs on your
  30. // website and in client applications.
  31. service WebRiskService {
  32. option (google.api.default_host) = "webrisk.googleapis.com";
  33. option (google.api.oauth_scopes) = "https://www.googleapis.com/auth/cloud-platform";
  34. // Gets the most recent threat list diffs. These diffs should be applied to
  35. // a local database of hashes to keep it up-to-date. If the local database is
  36. // empty or excessively out-of-date, a complete snapshot of the database will
  37. // be returned. This Method only updates a single ThreatList at a time. To
  38. // update multiple ThreatList databases, this method needs to be called once
  39. // for each list.
  40. rpc ComputeThreatListDiff(ComputeThreatListDiffRequest) returns (ComputeThreatListDiffResponse) {
  41. option (google.api.http) = {
  42. get: "/v1/threatLists:computeDiff"
  43. };
  44. option (google.api.method_signature) = "threat_type,version_token,constraints";
  45. }
  46. // This method is used to check whether a URI is on a given threatList.
  47. // Multiple threatLists may be searched in a single query.
  48. // The response will list all requested threatLists the URI was found to
  49. // match. If the URI is not found on any of the requested ThreatList an
  50. // empty response will be returned.
  51. rpc SearchUris(SearchUrisRequest) returns (SearchUrisResponse) {
  52. option (google.api.http) = {
  53. get: "/v1/uris:search"
  54. };
  55. option (google.api.method_signature) = "uri,threat_types";
  56. }
  57. // Gets the full hashes that match the requested hash prefix.
  58. // This is used after a hash prefix is looked up in a threatList
  59. // and there is a match. The client side threatList only holds partial hashes
  60. // so the client must query this method to determine if there is a full
  61. // hash match of a threat.
  62. rpc SearchHashes(SearchHashesRequest) returns (SearchHashesResponse) {
  63. option (google.api.http) = {
  64. get: "/v1/hashes:search"
  65. };
  66. option (google.api.method_signature) = "hash_prefix,threat_types";
  67. }
  68. // Creates a Submission of a URI suspected of containing phishing content to
  69. // be reviewed. If the result verifies the existence of malicious phishing
  70. // content, the site will be added to the [Google's Social Engineering
  71. // lists](https://support.google.com/webmasters/answer/6350487/) in order to
  72. // protect users that could get exposed to this threat in the future. Only
  73. // allowlisted projects can use this method during Early Access. Please reach
  74. // out to Sales or your customer engineer to obtain access.
  75. rpc CreateSubmission(CreateSubmissionRequest) returns (Submission) {
  76. option (google.api.http) = {
  77. post: "/v1/{parent=projects/*}/submissions"
  78. body: "submission"
  79. };
  80. option (google.api.method_signature) = "parent,submission";
  81. }
  82. }
  83. // Describes an API diff request.
  84. message ComputeThreatListDiffRequest {
  85. // The constraints for this diff.
  86. message Constraints {
  87. // The maximum size in number of entries. The diff will not contain more
  88. // entries than this value. This should be a power of 2 between 2**10 and
  89. // 2**20. If zero, no diff size limit is set.
  90. int32 max_diff_entries = 1;
  91. // Sets the maximum number of entries that the client is willing to have
  92. // in the local database. This should be a power of 2 between 2**10 and
  93. // 2**20. If zero, no database size limit is set.
  94. int32 max_database_entries = 2;
  95. // The compression types supported by the client.
  96. repeated CompressionType supported_compressions = 3;
  97. }
  98. // Required. The threat list to update. Only a single ThreatType should be specified
  99. // per request. If you want to handle multiple ThreatTypes, you must make one
  100. // request per ThreatType.
  101. ThreatType threat_type = 1 [(google.api.field_behavior) = REQUIRED];
  102. // The current version token of the client for the requested list (the
  103. // client version that was received from the last successful diff).
  104. // If the client does not have a version token (this is the first time calling
  105. // ComputeThreatListDiff), this may be left empty and a full database
  106. // snapshot will be returned.
  107. bytes version_token = 2;
  108. // Required. The constraints associated with this request.
  109. Constraints constraints = 3 [(google.api.field_behavior) = REQUIRED];
  110. }
  111. message ComputeThreatListDiffResponse {
  112. // The type of response sent to the client.
  113. enum ResponseType {
  114. // Unknown.
  115. RESPONSE_TYPE_UNSPECIFIED = 0;
  116. // Partial updates are applied to the client's existing local database.
  117. DIFF = 1;
  118. // Full updates resets the client's entire local database. This means
  119. // that either the client had no state, was seriously out-of-date,
  120. // or the client is believed to be corrupt.
  121. RESET = 2;
  122. }
  123. // The expected state of a client's local database.
  124. message Checksum {
  125. // The SHA256 hash of the client state; that is, of the sorted list of all
  126. // hashes present in the database.
  127. bytes sha256 = 1;
  128. }
  129. // The type of response. This may indicate that an action must be taken by the
  130. // client when the response is received.
  131. ResponseType response_type = 4;
  132. // A set of entries to add to a local threat type's list.
  133. ThreatEntryAdditions additions = 5;
  134. // A set of entries to remove from a local threat type's list.
  135. // This field may be empty.
  136. ThreatEntryRemovals removals = 6;
  137. // The new opaque client version token. This should be retained by the client
  138. // and passed into the next call of ComputeThreatListDiff as 'version_token'.
  139. // A separate version token should be stored and used for each threatList.
  140. bytes new_version_token = 7;
  141. // The expected SHA256 hash of the client state; that is, of the sorted list
  142. // of all hashes present in the database after applying the provided diff.
  143. // If the client state doesn't match the expected state, the client must
  144. // discard this diff and retry later.
  145. Checksum checksum = 8;
  146. // The soonest the client should wait before issuing any diff
  147. // request. Querying sooner is unlikely to produce a meaningful diff.
  148. // Waiting longer is acceptable considering the use case.
  149. // If this field is not set clients may update as soon as they want.
  150. google.protobuf.Timestamp recommended_next_diff = 2;
  151. }
  152. // Request to check URI entries against threatLists.
  153. message SearchUrisRequest {
  154. // Required. The URI to be checked for matches.
  155. string uri = 1 [(google.api.field_behavior) = REQUIRED];
  156. // Required. The ThreatLists to search in. Multiple ThreatLists may be specified.
  157. repeated ThreatType threat_types = 2 [(google.api.field_behavior) = REQUIRED];
  158. }
  159. message SearchUrisResponse {
  160. // Contains threat information on a matching uri.
  161. message ThreatUri {
  162. // The ThreatList this threat belongs to.
  163. repeated ThreatType threat_types = 1;
  164. // The cache lifetime for the returned match. Clients must not cache this
  165. // response past this timestamp to avoid false positives.
  166. google.protobuf.Timestamp expire_time = 2;
  167. }
  168. // The threat list matches. This might be empty if the URI is on no list.
  169. ThreatUri threat = 1;
  170. }
  171. // Request to return full hashes matched by the provided hash prefixes.
  172. message SearchHashesRequest {
  173. // A hash prefix, consisting of the most significant 4-32 bytes of a SHA256
  174. // hash. For JSON requests, this field is base64-encoded.
  175. // Note that if this parameter is provided by a URI, it must be encoded using
  176. // the web safe base64 variant (RFC 4648).
  177. bytes hash_prefix = 1;
  178. // Required. The ThreatLists to search in. Multiple ThreatLists may be specified.
  179. repeated ThreatType threat_types = 2 [(google.api.field_behavior) = REQUIRED];
  180. }
  181. message SearchHashesResponse {
  182. // Contains threat information on a matching hash.
  183. message ThreatHash {
  184. // The ThreatList this threat belongs to.
  185. // This must contain at least one entry.
  186. repeated ThreatType threat_types = 1;
  187. // A 32 byte SHA256 hash. This field is in binary format. For JSON
  188. // requests, hashes are base64-encoded.
  189. bytes hash = 2;
  190. // The cache lifetime for the returned match. Clients must not cache this
  191. // response past this timestamp to avoid false positives.
  192. google.protobuf.Timestamp expire_time = 3;
  193. }
  194. // The full hashes that matched the requested prefixes.
  195. // The hash will be populated in the key.
  196. repeated ThreatHash threats = 1;
  197. // For requested entities that did not match the threat list, how long to
  198. // cache the response until.
  199. google.protobuf.Timestamp negative_expire_time = 2;
  200. }
  201. // The type of threat. This maps directly to the threat list a threat may
  202. // belong to.
  203. enum ThreatType {
  204. // No entries should match this threat type. This threat type is unused.
  205. THREAT_TYPE_UNSPECIFIED = 0;
  206. // Malware targeting any platform.
  207. MALWARE = 1;
  208. // Social engineering targeting any platform.
  209. SOCIAL_ENGINEERING = 2;
  210. // Unwanted software targeting any platform.
  211. UNWANTED_SOFTWARE = 3;
  212. // A list of extended coverage social engineering URIs targeting any
  213. // platform.
  214. SOCIAL_ENGINEERING_EXTENDED_COVERAGE = 4;
  215. }
  216. // The ways in which threat entry sets can be compressed.
  217. enum CompressionType {
  218. // Unknown.
  219. COMPRESSION_TYPE_UNSPECIFIED = 0;
  220. // Raw, uncompressed data.
  221. RAW = 1;
  222. // Rice-Golomb encoded data.
  223. RICE = 2;
  224. }
  225. // Contains the set of entries to add to a local database.
  226. // May contain a combination of compressed and raw data in a single response.
  227. message ThreatEntryAdditions {
  228. // The raw SHA256-formatted entries.
  229. // Repeated to allow returning sets of hashes with different prefix sizes.
  230. repeated RawHashes raw_hashes = 1;
  231. // The encoded 4-byte prefixes of SHA256-formatted entries, using a
  232. // Golomb-Rice encoding. The hashes are converted to uint32, sorted in
  233. // ascending order, then delta encoded and stored as encoded_data.
  234. RiceDeltaEncoding rice_hashes = 2;
  235. }
  236. // Contains the set of entries to remove from a local database.
  237. message ThreatEntryRemovals {
  238. // The raw removal indices for a local list.
  239. RawIndices raw_indices = 1;
  240. // The encoded local, lexicographically-sorted list indices, using a
  241. // Golomb-Rice encoding. Used for sending compressed removal indices. The
  242. // removal indices (uint32) are sorted in ascending order, then delta encoded
  243. // and stored as encoded_data.
  244. RiceDeltaEncoding rice_indices = 2;
  245. }
  246. // A set of raw indices to remove from a local list.
  247. message RawIndices {
  248. // The indices to remove from a lexicographically-sorted local list.
  249. repeated int32 indices = 1;
  250. }
  251. // The uncompressed threat entries in hash format.
  252. // Hashes can be anywhere from 4 to 32 bytes in size. A large majority are 4
  253. // bytes, but some hashes are lengthened if they collide with the hash of a
  254. // popular URI.
  255. //
  256. // Used for sending ThreatEntryAdditons to clients that do not support
  257. // compression, or when sending non-4-byte hashes to clients that do support
  258. // compression.
  259. message RawHashes {
  260. // The number of bytes for each prefix encoded below. This field can be
  261. // anywhere from 4 (shortest prefix) to 32 (full SHA256 hash).
  262. // In practice this is almost always 4, except in exceptional circumstances.
  263. int32 prefix_size = 1;
  264. // The hashes, in binary format, concatenated into one long string. Hashes are
  265. // sorted in lexicographic order. For JSON API users, hashes are
  266. // base64-encoded.
  267. bytes raw_hashes = 2;
  268. }
  269. // The Rice-Golomb encoded data. Used for sending compressed 4-byte hashes or
  270. // compressed removal indices.
  271. message RiceDeltaEncoding {
  272. // The offset of the first entry in the encoded data, or, if only a single
  273. // integer was encoded, that single integer's value. If the field is empty or
  274. // missing, assume zero.
  275. int64 first_value = 1;
  276. // The Golomb-Rice parameter, which is a number between 2 and 28. This field
  277. // is missing (that is, zero) if `num_entries` is zero.
  278. int32 rice_parameter = 2;
  279. // The number of entries that are delta encoded in the encoded data. If only a
  280. // single integer was encoded, this will be zero and the single value will be
  281. // stored in `first_value`.
  282. int32 entry_count = 3;
  283. // The encoded deltas that are encoded using the Golomb-Rice coder.
  284. bytes encoded_data = 4;
  285. }
  286. // Wraps a URI that might be displaying malicious content.
  287. message Submission {
  288. // Required. The URI that is being reported for malicious content to be analyzed.
  289. string uri = 1 [(google.api.field_behavior) = REQUIRED];
  290. }
  291. // Request to send a potentially phishy URI to WebRisk.
  292. message CreateSubmissionRequest {
  293. // Required. The name of the project that is making the submission. This string is in
  294. // the format "projects/{project_number}".
  295. string parent = 1 [
  296. (google.api.field_behavior) = REQUIRED,
  297. (google.api.resource_reference) = {
  298. type: "cloudresourcemanager.googleapis.com/Project"
  299. }
  300. ];
  301. // Required. The submission that contains the content of the phishing report.
  302. Submission submission = 2 [(google.api.field_behavior) = REQUIRED];
  303. }