webrisk.proto 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. // Copyright 2020 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. // projects with CREATE_SUBMISSION_USERS visibility can use this method.
  74. rpc CreateSubmission(CreateSubmissionRequest) returns (Submission) {
  75. option (google.api.http) = {
  76. post: "/v1/{parent=projects/*}/submissions"
  77. body: "submission"
  78. };
  79. option (google.api.method_signature) = "parent,submission";
  80. }
  81. }
  82. // Describes an API diff request.
  83. message ComputeThreatListDiffRequest {
  84. // The constraints for this diff.
  85. message Constraints {
  86. // The maximum size in number of entries. The diff will not contain more
  87. // entries than this value. This should be a power of 2 between 2**10 and
  88. // 2**20. If zero, no diff size limit is set.
  89. int32 max_diff_entries = 1;
  90. // Sets the maximum number of entries that the client is willing to have
  91. // in the local database. This should be a power of 2 between 2**10 and
  92. // 2**20. If zero, no database size limit is set.
  93. int32 max_database_entries = 2;
  94. // The compression types supported by the client.
  95. repeated CompressionType supported_compressions = 3;
  96. }
  97. // Required. The threat list to update. Only a single ThreatType should be specified.
  98. ThreatType threat_type = 1 [(google.api.field_behavior) = REQUIRED];
  99. // The current version token of the client for the requested list (the
  100. // client version that was received from the last successful diff).
  101. // If the client does not have a version token (this is the first time calling
  102. // ComputeThreatListDiff), this may be left empty and a full database
  103. // snapshot will be returned.
  104. bytes version_token = 2;
  105. // Required. The constraints associated with this request.
  106. Constraints constraints = 3 [(google.api.field_behavior) = REQUIRED];
  107. }
  108. message ComputeThreatListDiffResponse {
  109. // The expected state of a client's local database.
  110. message Checksum {
  111. // The SHA256 hash of the client state; that is, of the sorted list of all
  112. // hashes present in the database.
  113. bytes sha256 = 1;
  114. }
  115. // The type of response sent to the client.
  116. enum ResponseType {
  117. // Unknown.
  118. RESPONSE_TYPE_UNSPECIFIED = 0;
  119. // Partial updates are applied to the client's existing local database.
  120. DIFF = 1;
  121. // Full updates resets the client's entire local database. This means
  122. // that either the client had no state, was seriously out-of-date,
  123. // or the client is believed to be corrupt.
  124. RESET = 2;
  125. }
  126. // The type of response. This may indicate that an action must be taken by the
  127. // client when the response is received.
  128. ResponseType response_type = 4;
  129. // A set of entries to add to a local threat type's list.
  130. ThreatEntryAdditions additions = 5;
  131. // A set of entries to remove from a local threat type's list.
  132. // This field may be empty.
  133. ThreatEntryRemovals removals = 6;
  134. // The new opaque client version token. This should be retained by the client
  135. // and passed into the next call of ComputeThreatListDiff as 'version_token'.
  136. // A separate version token should be stored and used for each threatList.
  137. bytes new_version_token = 7;
  138. // The expected SHA256 hash of the client state; that is, of the sorted list
  139. // of all hashes present in the database after applying the provided diff.
  140. // If the client state doesn't match the expected state, the client must
  141. // discard this diff and retry later.
  142. Checksum checksum = 8;
  143. // The soonest the client should wait before issuing any diff
  144. // request. Querying sooner is unlikely to produce a meaningful diff.
  145. // Waiting longer is acceptable considering the use case.
  146. // If this field is not set clients may update as soon as they want.
  147. google.protobuf.Timestamp recommended_next_diff = 2;
  148. }
  149. // Request to check URI entries against threatLists.
  150. message SearchUrisRequest {
  151. // Required. The URI to be checked for matches.
  152. string uri = 1 [(google.api.field_behavior) = REQUIRED];
  153. // Required. The ThreatLists to search in. Multiple ThreatLists may be specified.
  154. repeated ThreatType threat_types = 2 [(google.api.field_behavior) = REQUIRED];
  155. }
  156. message SearchUrisResponse {
  157. // Contains threat information on a matching uri.
  158. message ThreatUri {
  159. // The ThreatList this threat belongs to.
  160. repeated ThreatType threat_types = 1;
  161. // The cache lifetime for the returned match. Clients must not cache this
  162. // response past this timestamp to avoid false positives.
  163. google.protobuf.Timestamp expire_time = 2;
  164. }
  165. // The threat list matches. This may be empty if the URI is on no list.
  166. ThreatUri threat = 1;
  167. }
  168. // Request to return full hashes matched by the provided hash prefixes.
  169. message SearchHashesRequest {
  170. // A hash prefix, consisting of the most significant 4-32 bytes of a SHA256
  171. // hash. For JSON requests, this field is base64-encoded.
  172. bytes hash_prefix = 1;
  173. // Required. The ThreatLists to search in. Multiple ThreatLists may be specified.
  174. repeated ThreatType threat_types = 2 [(google.api.field_behavior) = REQUIRED];
  175. }
  176. message SearchHashesResponse {
  177. // Contains threat information on a matching hash.
  178. message ThreatHash {
  179. // The ThreatList this threat belongs to.
  180. // This must contain at least one entry.
  181. repeated ThreatType threat_types = 1;
  182. // A 32 byte SHA256 hash. This field is in binary format. For JSON
  183. // requests, hashes are base64-encoded.
  184. bytes hash = 2;
  185. // The cache lifetime for the returned match. Clients must not cache this
  186. // response past this timestamp to avoid false positives.
  187. google.protobuf.Timestamp expire_time = 3;
  188. }
  189. // The full hashes that matched the requested prefixes.
  190. // The hash will be populated in the key.
  191. repeated ThreatHash threats = 1;
  192. // For requested entities that did not match the threat list, how long to
  193. // cache the response until.
  194. google.protobuf.Timestamp negative_expire_time = 2;
  195. }
  196. // Contains the set of entries to add to a local database.
  197. // May contain a combination of compressed and raw data in a single response.
  198. message ThreatEntryAdditions {
  199. // The raw SHA256-formatted entries.
  200. // Repeated to allow returning sets of hashes with different prefix sizes.
  201. repeated RawHashes raw_hashes = 1;
  202. // The encoded 4-byte prefixes of SHA256-formatted entries, using a
  203. // Golomb-Rice encoding. The hashes are converted to uint32, sorted in
  204. // ascending order, then delta encoded and stored as encoded_data.
  205. RiceDeltaEncoding rice_hashes = 2;
  206. }
  207. // Contains the set of entries to remove from a local database.
  208. message ThreatEntryRemovals {
  209. // The raw removal indices for a local list.
  210. RawIndices raw_indices = 1;
  211. // The encoded local, lexicographically-sorted list indices, using a
  212. // Golomb-Rice encoding. Used for sending compressed removal indices. The
  213. // removal indices (uint32) are sorted in ascending order, then delta encoded
  214. // and stored as encoded_data.
  215. RiceDeltaEncoding rice_indices = 2;
  216. }
  217. // The type of threat. This maps dirrectly to the threat list a threat may
  218. // belong to.
  219. enum ThreatType {
  220. // Unknown.
  221. THREAT_TYPE_UNSPECIFIED = 0;
  222. // Malware targeting any platform.
  223. MALWARE = 1;
  224. // Social engineering targeting any platform.
  225. SOCIAL_ENGINEERING = 2;
  226. // Unwanted software targeting any platform.
  227. UNWANTED_SOFTWARE = 3;
  228. }
  229. // The ways in which threat entry sets can be compressed.
  230. enum CompressionType {
  231. // Unknown.
  232. COMPRESSION_TYPE_UNSPECIFIED = 0;
  233. // Raw, uncompressed data.
  234. RAW = 1;
  235. // Rice-Golomb encoded data.
  236. RICE = 2;
  237. }
  238. // A set of raw indices to remove from a local list.
  239. message RawIndices {
  240. // The indices to remove from a lexicographically-sorted local list.
  241. repeated int32 indices = 1;
  242. }
  243. // The uncompressed threat entries in hash format.
  244. // Hashes can be anywhere from 4 to 32 bytes in size. A large majority are 4
  245. // bytes, but some hashes are lengthened if they collide with the hash of a
  246. // popular URI.
  247. //
  248. // Used for sending ThreatEntryAdditons to clients that do not support
  249. // compression, or when sending non-4-byte hashes to clients that do support
  250. // compression.
  251. message RawHashes {
  252. // The number of bytes for each prefix encoded below. This field can be
  253. // anywhere from 4 (shortest prefix) to 32 (full SHA256 hash).
  254. // In practice this is almost always 4, except in exceptional circumstances.
  255. int32 prefix_size = 1;
  256. // The hashes, in binary format, concatenated into one long string. Hashes are
  257. // sorted in lexicographic order. For JSON API users, hashes are
  258. // base64-encoded.
  259. bytes raw_hashes = 2;
  260. }
  261. // The Rice-Golomb encoded data. Used for sending compressed 4-byte hashes or
  262. // compressed removal indices.
  263. message RiceDeltaEncoding {
  264. // The offset of the first entry in the encoded data, or, if only a single
  265. // integer was encoded, that single integer's value. If the field is empty or
  266. // missing, assume zero.
  267. int64 first_value = 1;
  268. // The Golomb-Rice parameter, which is a number between 2 and 28. This field
  269. // is missing (that is, zero) if `num_entries` is zero.
  270. int32 rice_parameter = 2;
  271. // The number of entries that are delta encoded in the encoded data. If only a
  272. // single integer was encoded, this will be zero and the single value will be
  273. // stored in `first_value`.
  274. int32 entry_count = 3;
  275. // The encoded deltas that are encoded using the Golomb-Rice coder.
  276. bytes encoded_data = 4;
  277. }
  278. // Wraps a URI that might be displaying phishing content.
  279. message Submission {
  280. // Required. The URI that is being reported for phishing content to be analyzed.
  281. string uri = 1 [(google.api.field_behavior) = REQUIRED];
  282. }
  283. // Request to send a potentially phishy URI to WebRisk.
  284. message CreateSubmissionRequest {
  285. // Required. The name of the project that is making the submission. This string is in
  286. // the format "projects/{project_number}".
  287. string parent = 1 [
  288. (google.api.field_behavior) = REQUIRED,
  289. (google.api.resource_reference) = {
  290. type: "cloudresourcemanager.googleapis.com/Project"
  291. }
  292. ];
  293. // Required. The submission that contains the content of the phishing report.
  294. Submission submission = 2 [(google.api.field_behavior) = REQUIRED];
  295. }