Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 39 additions & 39 deletions src/content/reference/react/experimental_taintUniqueValue.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,96 +22,96 @@ API ini hanya tersedia di dalam [Komponen Server React](/reference/rsc/use-clien

<Intro>

`taintUniqueValue` lets you prevent unique values from being passed to Client Components like passwords, keys, or tokens.
`taintUniqueValue` memungkinkan Anda mencegah nilai-nilai unik, seperti kata sandi, *key*, atau token, dioper ke Komponen Klien (*Client Component*).

```js
taintUniqueValue(errMessage, lifetime, value)
```

To prevent passing an object containing sensitive data, see [`taintObjectReference`](/reference/react/experimental_taintObjectReference).
Untuk mencegah pengoperan objek yang berisi data sensitif, lihat [`taintObjectReference`](/reference/react/experimental_taintObjectReference).

</Intro>

<InlineToc />

---

## Reference {/*reference*/}
## Referensi {/*reference*/}

### `taintUniqueValue(message, lifetime, value)` {/*taintuniquevalue*/}

Call `taintUniqueValue` with a password, token, key or hash to register it with React as something that should not be allowed to be passed to the Client as is:
Panggil `taintUniqueValue` dengan kata sandi, token, *key*, atau *hash* untuk mendaftarkannya ke React sebagai sesuatu yang tidak boleh dioper ke Klien apa adanya:

```js
import {experimental_taintUniqueValue} from 'react';

experimental_taintUniqueValue(
'Do not pass secret keys to the client.',
'Jangan oper secret key ke klien.',
process,
process.env.SECRET_KEY
);
```

[See more examples below.](#usage)
[Lihat contoh lainnya di bawah.](#usage)

#### Parameters {/*parameters*/}
#### Parameter {/*parameters*/}

* `message`: The message you want to display if `value` is passed to a Client Component. This message will be displayed as a part of the Error that will be thrown if `value` is passed to a Client Component.
* `message`: Pesan yang ingin Anda tampilkan jika `value` dioper ke Komponen Klien. Pesan ini akan ditampilkan sebagai bagian dari galat (*error*) yang akan dilemparkan jika `value` dioper ke Komponen Klien.

* `lifetime`: Any object that indicates how long `value` should be tainted. `value` will be blocked from being sent to any Client Component while this object still exists. For example, passing `globalThis` blocks the value for the lifetime of an app. `lifetime` is typically an object whose properties contains `value`.
* `lifetime`: Objek apa pun yang menunjukkan berapa lama `value` harus ditandai (*tainted*). `value` akan diblokir agar tidak dikirim ke Komponen Klien mana pun selama objek ini masih ada. Sebagai contoh, mengoper `globalThis` akan memblokir nilai tersebut sepanjang masa hidup aplikasi. `lifetime` biasanya berupa objek yang salah satu propertinya berisi `value`.

* `value`: A string, bigint or TypedArray. `value` must be a unique sequence of characters or bytes with high entropy such as a cryptographic token, private key, hash, or a long password. `value` will be blocked from being sent to any Client Component.
* `value`: Sebuah *string*, *bigint*, atau *TypedArray*. `value` harus berupa rangkaian karakter atau *byte* unik dengan entropi tinggi, seperti token kriptografi, kunci privat (*private key*), *hash*, atau kata sandi yang panjang. `value` akan diblokir agar tidak dikirim ke Komponen Klien mana pun.

#### Returns {/*returns*/}
#### Kembalian {/*returns*/}

`experimental_taintUniqueValue` returns `undefined`.
`experimental_taintUniqueValue` mengembalikan `undefined`.

#### Caveats {/*caveats*/}
#### Catatan penting {/*caveats*/}

* Deriving new values from tainted values can compromise tainting protection. New values created by uppercasing tainted values, concatenating tainted string values into a larger string, converting tainted values to base64, substringing tainted values, and other similar transformations are not tainted unless you explicitly call `taintUniqueValue` on these newly created values.
* Do not use `taintUniqueValue` to protect low-entropy values such as PIN codes or phone numbers. If any value in a request is controlled by an attacker, they could infer which value is tainted by enumerating all possible values of the secret.
* Membuat nilai baru dari nilai yang ditandai dapat melemahkan perlindungan penandaan. Nilai baru yang dibuat dengan mengubah nilai yang ditandai menjadi huruf kapital, menggabungkan *string* yang ditandai ke dalam *string* yang lebih panjang, mengonversi nilai yang ditandai ke base64, mengambil *substring* dari nilai yang ditandai, atau transformasi serupa lainnya tidak akan ikut ditandai, kecuali Anda secara eksplisit memanggil `taintUniqueValue` pada nilai-nilai baru tersebut.
* Jangan gunakan `taintUniqueValue` untuk melindungi nilai berentropi rendah seperti kode PIN atau nomor telepon. Jika ada nilai dalam suatu permintaan (*request*) yang dikendalikan oleh penyerang, mereka dapat menebak nilai mana yang ditandai dengan mencoba satu per satu semua kemungkinan nilai rahasia tersebut.

---

## Usage {/*usage*/}
## Penggunaan {/*usage*/}

### Prevent a token from being passed to Client Components {/*prevent-a-token-from-being-passed-to-client-components*/}
### Mencegah token dioper ke Komponen Klien {/*prevent-a-token-from-being-passed-to-client-components*/}

To ensure that sensitive information such as passwords, session tokens, or other unique values do not inadvertently get passed to Client Components, the `taintUniqueValue` function provides a layer of protection. When a value is tainted, any attempt to pass it to a Client Component will result in an error.
Agar informasi sensitif seperti kata sandi, token sesi, atau nilai unik lainnya tidak ikut teroper ke Komponen Klien tanpa disengaja, fungsi `taintUniqueValue` menyediakan sebuah lapisan perlindungan. Ketika sebuah nilai ditandai, setiap upaya untuk mengopernya ke Komponen Klien akan menghasilkan galat.

The `lifetime` argument defines the duration for which the value remains tainted. For values that should remain tainted indefinitely, objects like [`globalThis`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis) or `process` can serve as the `lifetime` argument. These objects have a lifespan that spans the entire duration of your app's execution.
Argumen `lifetime` menentukan berapa lama nilai tersebut tetap ditandai. Untuk nilai yang harus terus ditandai tanpa batas waktu, objek seperti [`globalThis`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis) atau `process` dapat digunakan sebagai argumen `lifetime`. Objek-objek ini memiliki masa hidup yang mencakup seluruh durasi eksekusi aplikasi Anda.

```js
import {experimental_taintUniqueValue} from 'react';

experimental_taintUniqueValue(
'Do not pass a user password to the client.',
'Jangan oper kata sandi pengguna ke klien.',
globalThis,
process.env.SECRET_KEY
);
```

If the tainted value's lifespan is tied to a object, the `lifetime` should be the object that encapsulates the value. This ensures the tainted value remains protected for the lifetime of the encapsulating object.
Jika masa hidup nilai yang ditandai terikat pada sebuah objek, `lifetime` harus berupa objek yang mengenkapsulasi nilai tersebut. Hal ini memastikan nilai yang ditandai tetap terlindungi selama masa hidup objek yang mengenkapsulasinya.

```js
import {experimental_taintUniqueValue} from 'react';

export async function getUser(id) {
const user = await db`SELECT * FROM users WHERE id = ${id}`;
experimental_taintUniqueValue(
'Do not pass a user session token to the client.',
'Jangan oper token sesi pengguna ke klien.',
user,
user.session.token
);
return user;
}
```

In this example, the `user` object serves as the `lifetime` argument. If this object gets stored in a global cache or is accessible by another request, the session token remains tainted.
Dalam contoh ini, objek `user` berperan sebagai argumen `lifetime`. Jika objek ini disimpan dalam *cache* global atau dapat diakses oleh permintaan lain, token sesi tersebut tetap ditandai.

<Pitfall>

**Do not rely solely on tainting for security.** Tainting a value doesn't block every possible derived value. For example, creating a new value by upper casing a tainted string will not taint the new value.
**Jangan hanya mengandalkan penandaan (*tainting*) untuk keamanan.** Menandai sebuah nilai tidak memblokir setiap kemungkinan nilai turunannya. Sebagai contoh, membuat nilai baru dengan mengubah *string* yang ditandai menjadi huruf kapital tidak akan membuat nilai baru tersebut ikut ditandai.


```js
Expand All @@ -120,31 +120,31 @@ import {experimental_taintUniqueValue} from 'react';
const password = 'correct horse battery staple';

experimental_taintUniqueValue(
'Do not pass the password to the client.',
'Jangan oper kata sandi ke klien.',
globalThis,
password
);

const uppercasePassword = password.toUpperCase() // `uppercasePassword` is not tainted
const uppercasePassword = password.toUpperCase() // `uppercasePassword` tidak ditandai
```

In this example, the constant `password` is tainted. Then `password` is used to create a new value `uppercasePassword` by calling the `toUpperCase` method on `password`. The newly created `uppercasePassword` is not tainted.
Dalam contoh ini, konstanta `password` ditandai. Kemudian `password` digunakan untuk membuat nilai baru `uppercasePassword` dengan memanggil *method* `toUpperCase` pada `password`. Nilai `uppercasePassword` yang baru dibuat ini tidak ditandai.

Other similar ways of deriving new values from tainted values like concatenating it into a larger string, converting it to base64, or returning a substring create untained values.
Cara serupa lainnya untuk membuat nilai baru dari nilai yang ditandai, seperti menggabungkannya ke dalam *string* yang lebih panjang, mengonversinya ke base64, atau mengambil *substring*-nya, juga menghasilkan nilai yang tidak ditandai.

Tainting only protects against simple mistakes like explicitly passing secret values to the client. Mistakes in calling the `taintUniqueValue` like using a global store outside of React, without the corresponding lifetime object, can cause the tainted value to become untainted. Tainting is a layer of protection; a secure app will have multiple layers of protection, well designed APIs, and isolation patterns.
Penandaan hanya melindungi dari kesalahan sederhana, seperti mengoper nilai rahasia ke klien secara eksplisit. Kesalahan dalam memanggil `taintUniqueValue`, misalnya menggunakan *store* global di luar React tanpa objek `lifetime` yang sesuai, dapat membuat nilai yang ditandai tidak lagi ditandai. Penandaan hanyalah satu lapisan perlindungan; aplikasi yang aman akan memiliki beberapa lapisan perlindungan, API yang dirancang dengan baik, serta pola isolasi.

</Pitfall>

<DeepDive>

#### Using `server-only` and `taintUniqueValue` to prevent leaking secrets {/*using-server-only-and-taintuniquevalue-to-prevent-leaking-secrets*/}
#### Menggunakan `server-only` dan `taintUniqueValue` untuk mencegah kebocoran rahasia {/*using-server-only-and-taintuniquevalue-to-prevent-leaking-secrets*/}

If you're running a Server Components environment that has access to private keys or passwords such as database passwords, you have to be careful not to pass that to a Client Component.
Jika Anda menjalankan lingkungan Komponen Server yang memiliki akses ke kunci privat atau kata sandi, seperti kata sandi basis data, Anda harus berhati-hati agar tidak mengopernya ke Komponen Klien.

```js
export async function Dashboard(props) {
// DO NOT DO THIS
// JANGAN LAKUKAN INI
return <Overview password={process.env.API_PASSWORD} />;
}
```
Expand All @@ -163,11 +163,11 @@ export async function Overview({ password }) {
}
```

This example would leak the secret API token to the client. If this API token can be used to access data this particular user shouldn't have access to, it could lead to a data breach.
Contoh ini akan membocorkan token API rahasia ke klien. Jika token API ini dapat digunakan untuk mengakses data yang seharusnya tidak boleh diakses oleh pengguna tersebut, hal ini dapat menyebabkan kebocoran data.

[comment]: <> (TODO: Link to `server-only` docs once they are written)

Ideally, secrets like this are abstracted into a single helper file that can only be imported by trusted data utilities on the server. The helper can even be tagged with [`server-only`](https://www.npmjs.com/package/server-only) to ensure that this file isn't imported on the client.
Idealnya, rahasia seperti ini diabstraksikan ke dalam satu *file* bantuan (*helper*) yang hanya dapat diimpor oleh utilitas data tepercaya di server. *File* bantuan tersebut bahkan dapat dilabeli dengan [`server-only`](https://www.npmjs.com/package/server-only) untuk memastikan *file* ini tidak diimpor di klien.

```js
import "server-only";
Expand All @@ -178,22 +178,22 @@ export function fetchAPI(url) {
}
```

Sometimes mistakes happen during refactoring and not all of your colleagues might know about this.
To protect against this mistakes happening down the line we can "taint" the actual password:
Terkadang kesalahan terjadi saat penulisan ulang kode (*refactoring*), dan tidak semua rekan kerja Anda mungkin mengetahui hal ini.
Untuk melindungi dari kesalahan semacam ini di kemudian hari, kita dapat "menandai" (*taint*) kata sandi yang sebenarnya:

```js
import "server-only";
import {experimental_taintUniqueValue} from 'react';

experimental_taintUniqueValue(
'Do not pass the API token password to the client. ' +
'Instead do all fetches on the server.'
'Jangan oper kata sandi token API ke klien. ' +
'Sebagai gantinya, lakukan semua fetch di server.'
process,
process.env.API_PASSWORD
);
```

Now whenever anyone tries to pass this password to a Client Component, or send the password to a Client Component with a Server Function, an error will be thrown with message you defined when you called `taintUniqueValue`.
Sekarang, setiap kali ada yang mencoba mengoper kata sandi ini ke Komponen Klien, atau mengirim kata sandi tersebut ke Komponen Klien melalui Fungsi Server, galat akan dilemparkan dengan pesan yang Anda tentukan saat memanggil `taintUniqueValue`.

</DeepDive>

Expand Down
Loading