|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2026 The Stdlib Authors. |
| 6 | +
|
| 7 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +you may not use this file except in compliance with the License. |
| 9 | +You may obtain a copy of the License at |
| 10 | +
|
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +
|
| 13 | +Unless required by applicable law or agreed to in writing, software |
| 14 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +See the License for the specific language governing permissions and |
| 17 | +limitations under the License. |
| 18 | +
|
| 19 | +--> |
| 20 | + |
| 21 | +# isSafeToken |
| 22 | + |
| 23 | +> Test whether a JSON Pointer reference token is safe. |
| 24 | +
|
| 25 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 26 | + |
| 27 | +<section class="intro"> |
| 28 | + |
| 29 | +This function tests whether a [JSON Pointer][json-pointer] reference token is safe to use for property traversal. Tokens matching `__proto__`, `constructor`, or `prototype` are considered unsafe as they are common prototype pollution vectors. |
| 30 | + |
| 31 | +</section> |
| 32 | + |
| 33 | +<!-- /.intro --> |
| 34 | + |
| 35 | +<!-- Package usage documentation. --> |
| 36 | + |
| 37 | +<section class="usage"> |
| 38 | + |
| 39 | +## Usage |
| 40 | + |
| 41 | +```javascript |
| 42 | +var isSafeToken = require( '@stdlib/utils/json-pointer/base/assert/is-safe-token' ); |
| 43 | +``` |
| 44 | + |
| 45 | +#### isSafeToken( token ) |
| 46 | + |
| 47 | +Tests whether a JSON Pointer reference token is safe. |
| 48 | + |
| 49 | +```javascript |
| 50 | +var bool = isSafeToken( 'foo' ); |
| 51 | +// returns true |
| 52 | + |
| 53 | +bool = isSafeToken( '__proto__' ); |
| 54 | +// returns false |
| 55 | + |
| 56 | +bool = isSafeToken( 'constructor' ); |
| 57 | +// returns false |
| 58 | + |
| 59 | +bool = isSafeToken( 'prototype' ); |
| 60 | +// returns false |
| 61 | +``` |
| 62 | + |
| 63 | +</section> |
| 64 | + |
| 65 | +<!-- /.usage --> |
| 66 | + |
| 67 | +<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 68 | + |
| 69 | +<section class="notes"> |
| 70 | + |
| 71 | +</section> |
| 72 | + |
| 73 | +<!-- /.notes --> |
| 74 | + |
| 75 | +<!-- Package usage examples. --> |
| 76 | + |
| 77 | +<section class="examples"> |
| 78 | + |
| 79 | +## Examples |
| 80 | + |
| 81 | +<!-- eslint no-undef: "error" --> |
| 82 | + |
| 83 | +```javascript |
| 84 | +var isSafeToken = require( '@stdlib/utils/json-pointer/base/assert/is-safe-token' ); |
| 85 | + |
| 86 | +var bool = isSafeToken( 'foo' ); |
| 87 | +// returns true |
| 88 | + |
| 89 | +bool = isSafeToken( '0' ); |
| 90 | +// returns true |
| 91 | + |
| 92 | +bool = isSafeToken( '-' ); |
| 93 | +// returns true |
| 94 | + |
| 95 | +bool = isSafeToken( '__proto__' ); |
| 96 | +// returns false |
| 97 | + |
| 98 | +bool = isSafeToken( 'constructor' ); |
| 99 | +// returns false |
| 100 | + |
| 101 | +bool = isSafeToken( 'prototype' ); |
| 102 | +// returns false |
| 103 | +``` |
| 104 | + |
| 105 | +</section> |
| 106 | + |
| 107 | +<!-- /.examples --> |
| 108 | + |
| 109 | +<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 110 | + |
| 111 | +<section class="references"> |
| 112 | + |
| 113 | +</section> |
| 114 | + |
| 115 | +<!-- /.references --> |
| 116 | + |
| 117 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 118 | + |
| 119 | +<section class="related"> |
| 120 | + |
| 121 | +</section> |
| 122 | + |
| 123 | +<!-- /.related --> |
| 124 | + |
| 125 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 126 | + |
| 127 | +<section class="links"> |
| 128 | + |
| 129 | +[json-pointer]: https://tools.ietf.org/html/rfc6901 |
| 130 | + |
| 131 | +</section> |
| 132 | + |
| 133 | +<!-- /.links --> |
0 commit comments