URLs and Hashing
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Bagian ini berisi spesifikasi mendetail tentang cara klien memeriksa URL.
Kanonikalisasi URL
Sebelum URL diperiksa, klien diharapkan melakukan beberapa kanonikalisasi pada URL tersebut.
Untuk memulai, kita mengasumsikan bahwa klien telah mengurai URL dan membuatnya valid sesuai dengan RFC 2396. Jika URL menggunakan nama domain internasional (IDN), klien harus mengonversi URL ke representasi Punycode ASCII. URL harus menyertakan komponen jalur; yaitu, harus memiliki minimal satu garis miring setelah domain (http://google.com/
, bukan http://google.com
).
Pertama, hapus karakter tab (0x09), CR (0x0d), dan LF (0x0a) dari URL. Jangan hapus urutan escape untuk karakter ini (misalnya, %0a
).
Kedua, jika URL berakhir dengan fragmen, hapus fragmen tersebut. Misalnya, persingkat http://google.com/#frag
menjadi http://google.com/
.
Ketiga, hapus persentase URL berulang kali hingga tidak ada lagi persentase yang di-escape. (Tindakan ini dapat membuat URL menjadi tidak valid.)
Untuk melakukan kanonisasi nama host:
Ekstrak nama host dari URL, lalu:
- Hapus semua titik di awal dan di akhir.
- Mengganti titik berurutan dengan satu titik.
- Jika nama host dapat diuraikan sebagai alamat IPv4, normalisasi menjadi 4 nilai desimal yang dipisahkan titik. Klien harus menangani encoding alamat IP yang sah, termasuk oktal, heksadesimal, dan kurang dari empat komponen.
- Jika nama host dapat diuraikan sebagai alamat IPv6 dalam tanda kurung, normalisasi dengan menghapus nol di awal yang tidak diperlukan dalam komponen dan menciutkan komponen nol menggunakan sintaksis titik dua ganda. Misalnya,
[2001:0db8:0000::1]
harus diubah menjadi [2001:db8::1]
. Jika nama host adalah salah satu dari dua jenis alamat IPv6 khusus berikut, ubah menjadi IPv4:
- Alamat IPv6 yang dipetakan IPv4, seperti
[::ffff:1.2.3.4]
, yang harus diubah menjadi 1.2.3.4
;
- Alamat NAT64 menggunakan awalan 64:ff9b::/96 yang terkenal, seperti
[64:ff9b::1.2.3.4]
, yang harus diubah menjadi 1.2.3.4
.
- Mengubah seluruh string menjadi huruf kecil.
Untuk melakukan kanonikalisasi jalur:
- Selesaikan urutan
/../
dan /./
di jalur dengan mengganti /./
dengan /
, dan menghapus /../
beserta komponen jalur sebelumnya.
- Mengganti deretan garis miring berturut-turut dengan satu karakter garis miring.
Jangan terapkan kanonisasi jalur ini ke parameter kueri.
Di URL, gunakan escape persentase untuk semua karakter yang <= ASCII 32, >= 127, #
, atau %
. Escape harus menggunakan karakter hex huruf besar.
Ekspresi Awalan Jalur Akhiran Host
Setelah URL dikanonikasikan, langkah selanjutnya adalah membuat ekspresi akhiran/awalan. Setiap ekspresi akhiran/awalan terdiri dari akhiran host (atau host lengkap) dan awalan jalur (atau jalur lengkap).
Klien akan membentuk hingga 30 kemungkinan kombinasi akhiran host dan awalan jalur yang berbeda. Kombinasi ini hanya menggunakan komponen host dan jalur URL. Skema, nama pengguna, sandi, dan port akan dihapus. Jika URL menyertakan parameter kueri, setidaknya satu kombinasi akan menyertakan jalur lengkap dan parameter kueri.
Untuk host, klien akan mencoba maksimal lima string yang berbeda. Bagian-bagian tersebut adalah:
- Jika nama host bukan literal IPv4 atau IPv6, maksimal empat nama host dapat dibentuk dengan memulai dari domain eTLD+1 dan menambahkan komponen utama berturut-turut. Penentuan eTLD+1 harus didasarkan pada Daftar Akhiran Publik. Misalnya,
a.b.example.com
akan menghasilkan domain eTLD+1 example.com
serta host dengan satu komponen host tambahan b.example.com
.
- Nama host yang sama persis di URL. Mengikuti contoh sebelumnya,
a.b.example.com
akan diperiksa.
Untuk jalur, klien akan mencoba maksimal enam string yang berbeda. Bagian-bagian tersebut adalah:
- Jalur URL yang tepat, termasuk parameter kueri.
- Jalur URL yang tepat, tanpa parameter kueri.
- Empat jalur yang terbentuk dengan memulai dari root (/) dan menambahkan komponen jalur secara berurutan, termasuk garis miring di akhir.
Contoh berikut mengilustrasikan perilaku pemeriksaan:
Untuk URL http://a.b.com/1/2.html?param=1
, klien akan mencoba kemungkinan string berikut:
a.b.com/1/2.html?param=1
a.b.com/1/2.html
a.b.com/
a.b.com/1/
b.com/1/2.html?param=1
b.com/1/2.html
b.com/
b.com/1/
Untuk URL http://a.b.c.d.e.f.com/1.html
, klien akan mencoba kemungkinan string berikut:
a.b.c.d.e.f.com/1.html
a.b.c.d.e.f.com/
c.d.e.f.com/1.html
c.d.e.f.com/
d.e.f.com/1.html
d.e.f.com/
e.f.com/1.html
e.f.com/
f.com/1.html
f.com/
(Catatan: lewati b.c.d.e.f.com
, karena kita hanya akan mengambil lima komponen nama host terakhir, dan nama host lengkap.)
Untuk URL http://1.2.3.4/1/
, klien akan mencoba kemungkinan string berikut:
1.2.3.4/1/
1.2.3.4/
Untuk URL http://example.co.uk/1
, klien akan mencoba kemungkinan string berikut:
example.co.uk/1
example.co.uk/
Hashing
Google Safe Browsing secara eksklusif menggunakan SHA256 sebagai fungsi hash. Fungsi hash ini harus diterapkan ke ekspresi di atas.
Hash 32 byte penuh, bergantung pada situasinya, akan dipotong menjadi 4 byte, 8 byte, atau 16 byte:
Saat menggunakan metode hashes.search, saat ini kami mewajibkan hash dalam permintaan untuk dipotong menjadi tepat 4 byte. Mengirim byte tambahan dalam permintaan ini akan membahayakan privasi pengguna.
Saat mendownload daftar untuk database lokal menggunakan metode hashList.get atau metode hashLists.batchGet, panjang hash yang dikirim oleh server dienkode dalam konvensi penamaan daftar yang berisi akhiran yang menunjukkan panjang hash. Lihat bagian Daftar yang Tersedia untuk mengetahui detail selengkapnya.
Kecuali dinyatakan lain, konten di halaman ini dilisensikan berdasarkan Lisensi Creative Commons Attribution 4.0, sedangkan contoh kode dilisensikan berdasarkan Lisensi Apache 2.0. Untuk mengetahui informasi selengkapnya, lihat Kebijakan Situs Google Developers. Java adalah merek dagang terdaftar dari Oracle dan/atau afiliasinya.
Terakhir diperbarui pada 2025-07-25 UTC.
[null,null,["Terakhir diperbarui pada 2025-07-25 UTC."],[],[],null,["# URLs and Hashing\n\nThis section contains detailed specifications of how clients check URLs.\n\n### Canonicalization of URLs\n\nBefore any URLs are checked, the client is expected to perform some canonicalization on that URL.\n\nTo begin, we assume that the client has parsed the URL and made it valid according to RFC 2396. If the URL uses an internationalized domain name (IDN), the client should convert the URL to the ASCII Punycode representation. The URL must include a path component; that is, it must have at least one slash following the domain (`http://google.com/` instead of `http://google.com`).\n\nFirst, remove tab (0x09), CR (0x0d), and LF (0x0a) characters from the URL. Do not remove escape sequences for these characters (e.g. `%0a`).\n\nSecond, if the URL ends in a fragment, remove the fragment. For example, shorten `http://google.com/#frag` to `http://google.com/`.\n\nThird, repeatedly percent-unescape the URL until it has no more percent-escapes. (This may render the URL invalid.)\n\n**To canonicalize the hostname:**\n\nExtract the hostname from the URL and then:\n\n1. Remove all leading and trailing dots.\n2. Replace consecutive dots with a single dot.\n3. If the hostname can be parsed as an IPv4 address, normalize it to 4 dot-separated decimal values. The client should handle any legal IP-address encoding, including octal, hex, and fewer than four components.\n4. If the hostname can be parsed as a bracketed IPv6 address, normalize it by removing unnecessary leading zeroes in the components and collapsing zero components by using the double-colon syntax. For example `[2001:0db8:0000::1]` should be transformed into `[2001:db8::1]`. If the hostname is one of the two following special IPv6 address types, transform them into IPv4:\n - An IPv4-mapped IPv6 address, such as `[::ffff:1.2.3.4]`, which should be transformed into `1.2.3.4`;\n - A NAT64 address using [the well-known prefix 64:ff9b::/96](https://datatracker.ietf.org/doc/html/rfc6052#section-2.1), such as `[64:ff9b::1.2.3.4]`, which should be transformed into `1.2.3.4`.\n5. Lowercase the whole string.\n\n**To canonicalize the path:**\n\n1. Resolve the sequences `/../` and `/./` in the path by replacing `/./` with `/`, and removing `/../` along with the preceding path component.\n2. Replace runs of consecutive slashes with a single slash character.\n\nDo not apply these path canonicalizations to the query parameters.\n\nIn the URL, percent-escape all characters that are \\\u003c= ASCII 32, \\\u003e= 127, `#`, or `%`. The escapes should use uppercase hex characters.\n\n### Host-Suffix Path-Prefix Expressions\n\nOnce the URL is canonicalized, the next step is to create the suffix/prefix expressions. Each suffix/prefix expression consists of a host suffix (or full host) and a path prefix (or full path).\n\nThe client will form up to 30 different possible host suffix and path prefix combinations. These combinations use only the host and path components of the URL. The scheme, username, password, and port are discarded. If the URL includes query parameters, then at least one combination will include the full path and query parameters.\n\n**For the host**, the client will try at most five different strings. They are:\n\n- If the hostname is not an IPv4 or IPv6 literal, up to four hostnames formed by starting with the eTLD+1 domain and adding successive leading components. The determination of eTLD+1 should be based on the [Public Suffix List](https://publicsuffix.org/). For example, `a.b.example.com` would result in the eTLD+1 domain of `example.com` as well as the host with one additional host component `b.example.com`.\n- The exact hostname in the URL. Following the previous example, `a.b.example.com` would be checked.\n\n**For the path**, the client will try at most six different strings. They are:\n\n- The exact path of the URL, including query parameters.\n- The exact path of the URL, without query parameters.\n- The four paths formed by starting at the root (/) and successively appending path components, including a trailing slash.\n\nThe following examples illustrate the check behavior:\n\nFor the URL `http://a.b.com/1/2.html?param=1`, the client will try these possible strings: \n\n a.b.com/1/2.html?param=1\n a.b.com/1/2.html\n a.b.com/\n a.b.com/1/\n b.com/1/2.html?param=1\n b.com/1/2.html\n b.com/\n b.com/1/\n\nFor the URL `http://a.b.c.d.e.f.com/1.html`, the client will try these possible strings: \n\n a.b.c.d.e.f.com/1.html\n a.b.c.d.e.f.com/\n c.d.e.f.com/1.html\n c.d.e.f.com/\n d.e.f.com/1.html\n d.e.f.com/\n e.f.com/1.html\n e.f.com/\n f.com/1.html\n f.com/\n\n(Note: skip `b.c.d.e.f.com`, since we'll take only the last five hostname components, and the full hostname.)\n\nFor the URL `http://1.2.3.4/1/`, the client will try these possible strings: \n\n 1.2.3.4/1/\n 1.2.3.4/\n\nFor the URL `http://example.co.uk/1`, the client will try these possible strings: \n\n example.co.uk/1\n example.co.uk/\n\n### Hashing\n\nGoogle Safe Browsing exclusively uses SHA256 as the hash function. This hash function should be applied to the above expressions.\n\nThe full 32-byte hash will, depending on the circumstances, be truncated to 4 bytes, 8 bytes, or 16 bytes:\n\n- When using the [hashes.search method](/safe-browsing/reference/rest/v5/hashes/search), we currently require the hashes in the request to be truncated to exactly 4 bytes. Sending additional bytes in this request will compromise user privacy.\n\n- When downloading the lists for the local database using the [hashList.get method](/safe-browsing/reference/rest/v5/hashList/get) or the [hashLists.batchGet method](/safe-browsing/reference/rest/v5/hashLists/batchGet), the length of the hashes sent by the server is encoded within the naming convention of the lists that contain suffix indicating hash length. See [Available Lists](/safe-browsing/reference/Local.Database#available-lists) section for more details."]]