Documentation ¶
Overview ¶
Package safebrowsing provides access to the Safe Browsing API.
For product documentation, see: https://developers.google.com/safe-browsing/
Library status ¶
These client libraries are officially supported by Google. However, this library is considered complete and is in maintenance mode. This means that we will address critical bugs and security issues but will not add any new features.
When possible, we recommend using our newer [Cloud Client Libraries for Go](https://pkg.go.dev/cloud.google.com/go) that are still actively being worked and iterated on.
Creating a client ¶
Usage example:
import "google.golang.org/api/safebrowsing/v5" ... ctx := context.Background() safebrowsingService, err := safebrowsing.NewService(ctx)
In this example, Google Application Default Credentials are used for authentication. For information on how to create and obtain Application Default Credentials, see https://developers.google.com/identity/protocols/application-default-credentials.
Other authentication options ¶
To use an API key for authentication (note: some APIs do not support API keys), use google.golang.org/api/option.WithAPIKey:
safebrowsingService, err := safebrowsing.NewService(ctx, option.WithAPIKey("AIza..."))
To use an OAuth token (e.g., a user token obtained via a three-legged OAuth flow, use google.golang.org/api/option.WithTokenSource:
config := &oauth2.Config{...} // ... token, err := config.Exchange(ctx, ...) safebrowsingService, err := safebrowsing.NewService(ctx, option.WithTokenSource(config.TokenSource(ctx, token)))
See google.golang.org/api/option.ClientOption for details on options.
Index ¶
- type GoogleSecuritySafebrowsingV5FullHash
- type GoogleSecuritySafebrowsingV5FullHashFullHashDetail
- type GoogleSecuritySafebrowsingV5SearchHashesResponse
- type HashesSearchCall
- func (c *HashesSearchCall) Context(ctx context.Context) *HashesSearchCall
- func (c *HashesSearchCall) Do(opts ...googleapi.CallOption) (*GoogleSecuritySafebrowsingV5SearchHashesResponse, error)
- func (c *HashesSearchCall) Fields(s ...googleapi.Field) *HashesSearchCall
- func (c *HashesSearchCall) HashPrefixes(hashPrefixes ...string) *HashesSearchCall
- func (c *HashesSearchCall) Header() http.Header
- func (c *HashesSearchCall) IfNoneMatch(entityTag string) *HashesSearchCall
- type HashesService
- type Service
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GoogleSecuritySafebrowsingV5FullHash ¶
type GoogleSecuritySafebrowsingV5FullHash struct { // FullHash: The matching full hash. This is the SHA256 hash. The length // will be exactly 32 bytes. FullHash string `json:"fullHash,omitempty"` // FullHashDetails: Unordered list. A repeated field identifying the // details relevant to this full hash. FullHashDetails []*GoogleSecuritySafebrowsingV5FullHashFullHashDetail `json:"fullHashDetails,omitempty"` // ForceSendFields is a list of field names (e.g. "FullHash") to // unconditionally include in API requests. By default, fields with // empty or default values are omitted from API requests. However, any // non-pointer, non-interface field appearing in ForceSendFields will be // sent to the server regardless of whether the field is empty or not. // This may be used to include empty fields in Patch requests. ForceSendFields []string `json:"-"` // NullFields is a list of field names (e.g. "FullHash") to include in // API requests with the JSON null value. By default, fields with empty // values are omitted from API requests. However, any field with an // empty value appearing in NullFields will be sent to the server as // null. It is an error if a field in this list has a non-empty value. // This may be used to include null fields in Patch requests. NullFields []string `json:"-"` }
GoogleSecuritySafebrowsingV5FullHash: The full hash identified with one or more matches.
func (*GoogleSecuritySafebrowsingV5FullHash) MarshalJSON ¶
func (s *GoogleSecuritySafebrowsingV5FullHash) MarshalJSON() ([]byte, error)
type GoogleSecuritySafebrowsingV5FullHashFullHashDetail ¶
type GoogleSecuritySafebrowsingV5FullHashFullHashDetail struct { // Attributes: Unordered list. Additional attributes about those full // hashes. This may be empty. // // Possible values: // "THREAT_ATTRIBUTE_UNSPECIFIED" - Unknown attribute. If this is // returned by the server, the client shall disregard the enclosing // `FullHashDetail` altogether. // "CANARY" - Indicates that the threat_type should not be used for // enforcement. // "FRAME_ONLY" - Indicates that the threat_type should only be used // for enforcement on frames. Attributes []string `json:"attributes,omitempty"` // ThreatType: The type of threat. This field will never be empty. // // Possible values: // "THREAT_TYPE_UNSPECIFIED" - Unknown threat type. If this is // returned by the server, the client shall disregard the enclosing // `FullHashDetail` altogether. // "MALWARE" - Malware threat type. Malware is any software or mobile // application specifically designed to harm a computer, a mobile // device, the software it's running, or its users. Malware exhibits // malicious behavior that can include installing software without user // consent and installing harmful software such as viruses. More // information can be found // [here](https://developers.google.com/search/docs/monitor-debug/securit // y/malware). // "SOCIAL_ENGINEERING" - Social engineering threat type. Social // engineering pages falsely purport to act on behalf of a third party // with the intention of confusing viewers into performing an action // with which the viewer would only trust a true agent of that third // party. Phishing is a type of social engineering that tricks the // viewer into performing the specific action of providing information, // such as login credentials. More information can be found // [here](https://developers.google.com/search/docs/monitor-debug/securit // y/social-engineering). // "UNWANTED_SOFTWARE" - Unwanted software threat type. Unwanted // software is any software that does not adhere to [Google's Software // Principles](https://www.google.com/about/software-principles.html) // but isn't malware. // "POTENTIALLY_HARMFUL_APPLICATION" - Potentially harmful application // threat type [as used by Google Play Protect for the Play // Store](https://developers.google.com/android/play-protect/potentially- // harmful-applications). ThreatType string `json:"threatType,omitempty"` // ForceSendFields is a list of field names (e.g. "Attributes") to // unconditionally include in API requests. By default, fields with // empty or default values are omitted from API requests. However, any // non-pointer, non-interface field appearing in ForceSendFields will be // sent to the server regardless of whether the field is empty or not. // This may be used to include empty fields in Patch requests. ForceSendFields []string `json:"-"` // NullFields is a list of field names (e.g. "Attributes") to include in // API requests with the JSON null value. By default, fields with empty // values are omitted from API requests. However, any field with an // empty value appearing in NullFields will be sent to the server as // null. It is an error if a field in this list has a non-empty value. // This may be used to include null fields in Patch requests. NullFields []string `json:"-"` }
GoogleSecuritySafebrowsingV5FullHashFullHashDetail: Details about a matching full hash. An important note about forward compatibility: new threat types and threat attributes may be added by the server at any time; those additions are considered minor version changes. It is Google's policy not to expose minor version numbers in APIs (see https://cloud.google.com/apis/design/versioning for the versioning policy), so clients MUST be prepared to receive `FullHashDetail` messages containing `ThreatType` enum values or `ThreatAttribute` enum values that are considered invalid by the client. Therefore, it is the client's responsibility to check for the validity of all `ThreatType` and `ThreatAttribute` enum values; if any value is considered invalid, the client MUST disregard the entire `FullHashDetail` message.
func (*GoogleSecuritySafebrowsingV5FullHashFullHashDetail) MarshalJSON ¶
func (s *GoogleSecuritySafebrowsingV5FullHashFullHashDetail) MarshalJSON() ([]byte, error)
type GoogleSecuritySafebrowsingV5SearchHashesResponse ¶
type GoogleSecuritySafebrowsingV5SearchHashesResponse struct { // CacheDuration: The client-side cache duration. The client MUST add // this duration to the current time to determine the expiration time. // The expiration time then applies to every hash prefix queried by the // client in the request, regardless of how many full hashes are // returned in the response. Even if the server returns no full hashes // for a particular hash prefix, this fact MUST also be cached by the // client. Important: the client MUST NOT assume that the server will // return the same cache duration for all responses. The server MAY // choose different cache durations for different responses depending on // the situation. CacheDuration string `json:"cacheDuration,omitempty"` // FullHashes: Unordered list. The unordered list of full hashes found. FullHashes []*GoogleSecuritySafebrowsingV5FullHash `json:"fullHashes,omitempty"` // ServerResponse contains the HTTP response code and headers from the // server. googleapi.ServerResponse `json:"-"` // ForceSendFields is a list of field names (e.g. "CacheDuration") to // unconditionally include in API requests. By default, fields with // empty or default values are omitted from API requests. However, any // non-pointer, non-interface field appearing in ForceSendFields will be // sent to the server regardless of whether the field is empty or not. // This may be used to include empty fields in Patch requests. ForceSendFields []string `json:"-"` // NullFields is a list of field names (e.g. "CacheDuration") to include // in API requests with the JSON null value. By default, fields with // empty values are omitted from API requests. However, any field with // an empty value appearing in NullFields will be sent to the server as // null. It is an error if a field in this list has a non-empty value. // This may be used to include null fields in Patch requests. NullFields []string `json:"-"` }
GoogleSecuritySafebrowsingV5SearchHashesResponse: The response returned after searching threat hashes. If nothing is found, the server will return an OK status (HTTP status code 200) with the `full_hashes` field empty, rather than returning a NOT_FOUND status (HTTP status code 404). **What's new in V5**: There is a separation between `FullHash` and `FullHashDetail`. In the case when a hash represents a site having multiple threats (e.g. both MALWARE and SOCIAL_ENGINEERING), the full hash does not need to be sent twice as in V4. Furthermore, the cache duration has been simplified into a single `cache_duration` field.
func (*GoogleSecuritySafebrowsingV5SearchHashesResponse) MarshalJSON ¶
func (s *GoogleSecuritySafebrowsingV5SearchHashesResponse) MarshalJSON() ([]byte, error)
type HashesSearchCall ¶
type HashesSearchCall struct {
// contains filtered or unexported fields
}
func (*HashesSearchCall) Context ¶
func (c *HashesSearchCall) Context(ctx context.Context) *HashesSearchCall
Context sets the context to be used in this call's Do method. Any pending HTTP request will be aborted if the provided context is canceled.
func (*HashesSearchCall) Do ¶
func (c *HashesSearchCall) Do(opts ...googleapi.CallOption) (*GoogleSecuritySafebrowsingV5SearchHashesResponse, error)
Do executes the "safebrowsing.hashes.search" call. Exactly one of *GoogleSecuritySafebrowsingV5SearchHashesResponse or error will be non-nil. Any non-2xx status code is an error. Response headers are in either *GoogleSecuritySafebrowsingV5SearchHashesResponse.ServerResponse.Heade r or (if a response was returned at all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified to check whether the returned error was because http.StatusNotModified was returned.
func (*HashesSearchCall) Fields ¶
func (c *HashesSearchCall) Fields(s ...googleapi.Field) *HashesSearchCall
Fields allows partial responses to be retrieved. See https://developers.google.com/gdata/docs/2.0/basics#PartialResponse for more information.
func (*HashesSearchCall) HashPrefixes ¶
func (c *HashesSearchCall) HashPrefixes(hashPrefixes ...string) *HashesSearchCall
HashPrefixes sets the optional parameter "hashPrefixes": Required. The hash prefixes to be looked up. Clients MUST NOT send more than 1000 hash prefixes. However, following the URL processing procedure, clients SHOULD NOT need to send more than 30 hash prefixes. Currently each hash prefix is required to be exactly 4 bytes long. This MAY be relaxed in the future.
func (*HashesSearchCall) Header ¶
func (c *HashesSearchCall) Header() http.Header
Header returns an http.Header that can be modified by the caller to add HTTP headers to the request.
func (*HashesSearchCall) IfNoneMatch ¶
func (c *HashesSearchCall) IfNoneMatch(entityTag string) *HashesSearchCall
IfNoneMatch sets the optional parameter which makes the operation fail if the object's ETag matches the given value. This is useful for getting updates only after the object has changed since the last request. Use googleapi.IsNotModified to check whether the response error from Do is the result of In-None-Match.
type HashesService ¶
type HashesService struct {
// contains filtered or unexported fields
}
func NewHashesService ¶
func NewHashesService(s *Service) *HashesService
func (*HashesService) Search ¶
func (r *HashesService) Search() *HashesSearchCall
Search: Search for full hashes matching the specified prefixes. This is a custom method as defined by https://google.aip.dev/136 (the custom method refers to this method having a custom name within Google's general API development nomenclature; it does not refer to using a custom HTTP method).
type Service ¶
type Service struct { BasePath string // API endpoint base URL UserAgent string // optional additional User-Agent fragment Hashes *HashesService // contains filtered or unexported fields }
func New
deprecated
New creates a new Service. It uses the provided http.Client for requests.
Deprecated: please use NewService instead. To provide a custom HTTP client, use option.WithHTTPClient. If you are using google.golang.org/api/googleapis/transport.APIKey, use option.WithAPIKey with NewService instead.
func NewService ¶
NewService creates a new Service.