@intellifend/requestshieldjs 2.0.0-stg.263 → 2.0.0-stg.279

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -144,7 +144,7 @@ await fetch("/api/register", {
144
144
  | `challengeUrl` | No | Absolute Challenge Server base URL. Defaults to `https://challenge.intellifend.ai`. It must use HTTP(S) and contain no credentials, query, or fragment. |
145
145
  | `fallbackChallengeUrl` | No | Approved absolute HTTPS secondary base URL, without credentials, query, or fragment. Omitted by default. An identical normalized primary URL adds no alternate endpoint. |
146
146
  | `timeoutMs` | No | Positive whole-flow time budget for create, solve, verify, and retries. Defaults to 5,000 ms. |
147
- | `protect` | No | Exact endpoint path or URL strings for Seamless mode. Omit or pass an empty list for Manual-only operation. |
147
+ | `protect` | No | Endpoint paths or URLs for Seamless mode, optionally containing named path parameters as described below. Omit or pass an empty list for Manual-only operation. |
148
148
  | `telemetry` | No | Enables the optional browser signal collection on API v2. Default `false`; collection stays disabled on v1. |
149
149
 
150
150
  `init()` validates synchronously and throws `IntelliFendError` with code `invalid_config` for invalid input. Reinitialization replaces the previous valid configuration; a failing reinitialization leaves that configuration in place. Unknown configuration keys are ignored.
@@ -199,14 +199,63 @@ The method always resolves to a string: the issued token or `""` for validation,
199
199
 
200
200
  ### Endpoint matching
201
201
 
202
+ Use named path parameters for endpoints whose path contains an identifier.
203
+
204
+ For npm/ESM initialization:
205
+
206
+ ```javascript
207
+ import { IntelliFend } from "@intellifend/requestshieldjs";
208
+
209
+ IntelliFend.init({
210
+ appKey: "YOUR_APP_KEY",
211
+ protect: ["/api/orders/:orderId/items"],
212
+ });
213
+ ```
214
+
215
+ For script-tag initialization, use the equivalent attribute:
216
+
217
+ ```html
218
+ data-protect='["/api/orders/:orderId/items"]'
219
+ ```
220
+
202
221
  - A root-relative entry is resolved once against the current page origin.
203
222
  - An absolute entry must not contain credentials. Cross-origin entries require HTTPS, except for `localhost`, `127.0.0.1`, and `[::1]`; same-origin HTTP is allowed.
204
- - Query strings and fragments are ignored. Origin and pathname must otherwise match exactly, including case and trailing slash.
223
+ - Origin must match exactly. A parameter such as `:orderId` occupies a whole pathname segment and matches exactly one non-empty segment, never a `/`. Names start with an ASCII letter or `_`, followed by ASCII letters, digits, or `_`.
224
+ - Multiple parameters are allowed, for example `/api/accounts/:accountId/orders/:orderId`. Names are descriptive; repeating a name does not require equal values. Parameters are allowed only in the pathname, never in the origin.
225
+ - Every other segment matches literally. Rules without parameters keep exact matching; rules never become prefix matches. Path case and trailing slash remain significant.
226
+ - Escape a literal leading colon by doubling it: `/api/orders/::orderId` matches `/api/orders/:orderId` only, and `/api/orders/:::orderId` matches `/api/orders/::orderId` only. When upgrading from exact-only matching, change any existing literal colon-leading segment to this escaped form before enabling the new syntax.
227
+ - A colon-leading segment that is neither a valid parameter nor a `::` escape is invalid configuration, including `:`, `:123`, and `:order-id`. Invalid raw path segments are rejected even if URL dot-segment normalization would remove them. Other punctuation is literal; wildcard hosts, wildcard paths, regular expressions, and catch-all parameters are not supported.
228
+ - Query strings and fragments in rules and requests are ignored. `/api/orders/:id?include=details` still requires one `:id` segment; `?` does not make the parameter optional.
229
+ - Browser URL normalization applies, including dot-segment removal. The SDK does not decode percent escapes: `%2F` and `%5C` remain within one segment, and a literal `%3AorderId` differs from `:orderId`. Literal encoded segments must match their normalized URL spelling, including percent-escape case.
205
230
  - Relative application URLs use `document.baseURI` at the native call boundary: Fetch captures it when `fetch()` is called, and XHR captures it when `open()` is called. A later `<base>` change cannot retarget a delayed protected request.
206
231
  - Rules apply to every HTTP method.
207
232
  - Seamless mode covers Fetch and asynchronous XHR. It does not cover synchronous XHR, native form navigation, `sendBeacon`, WebSocket, EventSource, service-worker-owned traffic, or transports cached before SDK initialization.
208
233
  - Fetch requests whose effective mode is `no-cors` are sent unchanged because JavaScript cannot add the token header.
209
234
 
235
+ For `/api/orders/:orderId/items` on the page origin:
236
+
237
+ | Request URL | Matches? |
238
+ | --- | --- |
239
+ | `/api/orders/12345/items` | Yes |
240
+ | `/api/orders/abc-123/items` | Yes |
241
+ | `/api/orders/12345/items?include=details` | Yes |
242
+ | `/api/orders//items` | No: empty segment |
243
+ | `/api/orders/12345/items/extra` | No: extra segment |
244
+ | `/api/orders/12345/items/` | No: trailing slash |
245
+ | `/api/orders/12345/Items` | No: different case |
246
+ | Same pathname on another origin | No |
247
+
248
+ Absolute rules such as
249
+ `https://api.example.com/api/orders/:orderId/items` use the same
250
+ path syntax and require that exact origin. Exact rules and parameter rules can
251
+ coexist; overlapping rules still produce only one application request and one
252
+ token attachment. Invalid patterns follow the normal `invalid_config` behavior
253
+ of `init()` or script-tag initialization.
254
+
255
+ Matching only decides whether the frontend attaches a token. Configure backend
256
+ verification for every corresponding route, including dynamic routes; a browser
257
+ rule does not enable backend protection or bind token claims to that route.
258
+
210
259
  ## Integration behavior
211
260
 
212
261
  ### Fail-through and header precedence
@@ -1,18 +1,18 @@
1
1
  {
2
- "version": "2.0.0-stg.263",
2
+ "version": "2.0.0-stg.279",
3
3
  "algorithm": "sha384",
4
4
  "bundles": [
5
5
  {
6
6
  "name": "intellifend",
7
7
  "path": "intellifend.js",
8
- "version": "2.0.0-stg.263",
9
- "integrity": "sha384-E+o9twhbhpyu9Lefsc/acu+W9lhsd8HEFnz/7c/BxjCG1zgv682pQUwFMROELUFp"
8
+ "version": "2.0.0-stg.279",
9
+ "integrity": "sha384-TtARvTM567xNuCnn/jpph7nt6QmJwtZz+VFtu6Nj80tyTMDA3SIL++nNVB2k4tIJ"
10
10
  },
11
11
  {
12
12
  "name": "intellifend-esm",
13
13
  "path": "intellifend.mjs",
14
- "version": "2.0.0-stg.263",
15
- "integrity": "sha384-0fDXcTFm0c7pEpNb+ZbKG0D0LSGSs2LDVp7i/1CJ/rFenYZbi9qXOeglfg7Jo4Me"
14
+ "version": "2.0.0-stg.279",
15
+ "integrity": "sha384-mhSDs1GM9oafWm4Bxd9DTWPNbSkR1Qms+DOoZWQ8M7uDiHPNZH+fdzWc1U0Ij/Oe"
16
16
  }
17
17
  ]
18
18
  }
package/dist/index.d.ts CHANGED
@@ -11,7 +11,11 @@ export interface InitConfig {
11
11
  /** Overall time budget for one getToken() flow (create + solve + verify),
12
12
  * including retries, in milliseconds. Default 5 000. */
13
13
  timeoutMs?: number;
14
- /** Exact endpoint paths/URLs protected automatically through Fetch and async XHR. */
14
+ /** Endpoint paths/URLs protected automatically through Fetch and async XHR.
15
+ * Origin and literal path segments match exactly; :name matches one non-empty
16
+ * segment. Names use [A-Za-z_][A-Za-z0-9_]*; :: escapes a literal leading colon.
17
+ * Query/fragment are ignored; case and trailing slashes remain significant.
18
+ * Matching attaches tokens only; protect the corresponding backend routes too. */
15
19
  protect?: string[];
16
20
  /** Opts into bounded, page-memory-only browser signal collection. Default false. */
17
21
  telemetry?: boolean;
@@ -31,7 +35,8 @@ export declare const IntelliFend: {
31
35
  /**
32
36
  * Validates and stores the configuration. Synchronous: throws
33
37
  * IntelliFendError("invalid_config") on bad input. Unknown keys are ignored;
34
- * `protect` enables exact endpoint interception; `telemetry` opts into the
38
+ * `protect` enables exact-origin endpoint interception with optional named
39
+ * path parameters; `telemetry` opts into the
35
40
  * bounded signal collector.
36
41
  *
37
42
  * Re-init is allowed and replaces the configuration (last init wins); a