You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
New options to disable automatic escaping of labels and relationship types have been added to the `.build` method on clauses, inside the new object `unsafeEscapeOptions`:
6
+
7
+
-`disableLabelEscaping` (defaults to `false`): If set to true, node labels will not be escaped if unsafe.
8
+
-`disableRelationshipTypeEscaping` (defaults to `false`): If set to true, relationship types will not be escaped if unsafe
Copy file name to clipboardexpand all lines: docs/modules/ROOT/pages/how-to/customize-cypher.adoc
+89
Original file line number
Diff line number
Diff line change
@@ -346,3 +346,92 @@ And the following parameters:
346
346
The callback passed into `Raw` is producing the string `this0.prop = $myParam`.
347
347
To achieve this, it uses the utility method `utils.compileCypher` and passes the variable `movie` and the `context` parameter, which then returns the string `this0`.
348
348
Finally, the custom parameter `$myParam` is returned in the tuple `[cypher, params]`, ensuring that it is available when executing `match.build()`.
349
+
350
+
351
+
== Disable automatic escaping
352
+
353
+
[WARNING]
354
+
====
355
+
Changing these options may lead to code injection and unsafe Cypher.
356
+
====
357
+
358
+
Cypher Builder automatically escapes unsafe strings that could lead to code injection. This behavior can be configured using the `unsafeEscapeOptions` parameter in the `.build` method of clauses:
359
+
360
+
- `disableLabelEscaping` (defaults to `false`): If set to `true`, node labels will not be escaped, even if unsafe.
361
+
- `disableRelationshipTypeEscaping` (defaults to `false`): If set to `true`, relationship types will not be escaped, even if unsafe.
362
+
363
+
For example:
364
+
365
+
[source, javascript]
366
+
----
367
+
const personNode = new Cypher.Node();
368
+
const movieNode = new Cypher.Node();
369
+
370
+
const matchQuery = new Cypher.Match(
371
+
new Cypher.Pattern(personNode, {
372
+
labels: ["Person"],
373
+
properties: {
374
+
["person name"]: new Cypher.Literal(`Uneak "Seveer`),
375
+
},
376
+
})
377
+
.related({ type: "ACTED IN" })
378
+
.to(movieNode, { labels: ["A Movie"] })
379
+
).return(personNode);
380
+
381
+
const queryResult = matchQuery.build({
382
+
unsafeEscapeOptions: {
383
+
disableLabelEscaping: true,
384
+
disableRelationshipTypeEscaping: true,
385
+
},
386
+
});
387
+
----
388
+
389
+
This query will generate the following (invalid) Cypher:
390
+
391
+
392
+
[source]
393
+
----
394
+
MATCH (this0:Person { `person name`: "Uneak \"Seveer" })-[:ACTED IN]->(this1:A Movie)
395
+
RETURN this0
396
+
----
397
+
398
+
Instead of the default (safe) Cypher:
399
+
400
+
[source, cypher]
401
+
----
402
+
MATCH (this0:Person { `person name`: "Uneak \"Seveer" })-[:`ACTED IN`]->(this1:`A Movie`)
403
+
RETURN this0
404
+
----
405
+
406
+
=== Manually escaping labels and types
407
+
408
+
If automatic escaping is disabled, strings used for labels and relationship types must be escaped manually. This can be done using the following utility functions:
409
+
410
+
* `Cypher.utils.escapeLabel(str)`
411
+
* `Cypher.utils.escapeType(str)`
412
+
413
+
In the previous example, labels and types can be escaped manually to produce valid Cypher:
414
+
415
+
[source, javascript]
416
+
----
417
+
const personNode = new Cypher.Node();
418
+
const movieNode = new Cypher.Node();
419
+
420
+
const matchQuery = new Cypher.Match(
421
+
new Cypher.Pattern(personNode, {
422
+
labels: [Cypher.utils.escapeLabel("Person")],
423
+
properties: {
424
+
["person name"]: new Cypher.Literal(`Uneak "Seveer`),
0 commit comments