Skip to content

Conversation

@JeroenDeDauw
Copy link
Member

@JeroenDeDauw JeroenDeDauw commented Jan 28, 2026

Builds on #471 and kept separate for easy review. "Files changed" tab correctly only shows the extra stuff

Reviewed by Jeroen and Claude

The CypherQueryFilter was blocking all function calls, but built-in Cypher functions like type(), labels(), count() are read-only and safe.

Changes

  • Allow read-only function calls (type, labels, count, etc.)
  • Block CALL (stored procedures can have side effects)
  • Block LOAD (file system access via LOAD CSV)
  • Add unicode escape normalization to prevent obfuscation attacks like \u000DCREATE
  • Update demo page to show relation types using type(r)
  • Add comprehensive security tests (55 test cases covering standard writes, case variations, procedure calls, file access, unicode obfuscation, subquery attacks, and more)

Security

The filter now blocks dangerous operations while allowing safe read-only functions:

Blocked Reason
CREATE, SET, DELETE, REMOVE, MERGE, DROP Write operations
CALL Stored procedures can have side effects
LOAD File system access via LOAD CSV

All 55 security test cases pass, covering obfuscation attempts like unicode escapes, comment hiding, subqueries, and case variations.

JeroenDeDauw and others added 4 commits January 28, 2026 20:40
Adds a demo parser function `{{#cypher_raw: query}}` that executes
read-only Cypher queries and displays the JSON-encoded results.

- Write queries are rejected using CypherQueryFilter
- Output is HTML-escaped and displayed in a code block
- Includes i18n messages for error states
- Adds demo page showing usage

Fixes #451

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Display each query in a syntax-highlighted code block above its
execution result so readers can see what query produced what output.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The CypherQueryFilter was blocking all function calls, but built-in
Cypher functions like type(), labels(), count() are read-only and safe.

Changes:
- Allow read-only function calls (type, labels, count, etc.)
- Block CALL (stored procedures can have side effects)
- Block LOAD (file system access via LOAD CSV)
- Add unicode escape normalization to prevent obfuscation attacks
- Add comprehensive security tests (55 test cases)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@JeroenDeDauw
Copy link
Member Author

image

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request enhances the cypher_raw parser function by allowing read-only Cypher functions (like type(), labels(), count()) while maintaining security by blocking dangerous operations. The change builds on PR #471 and adds comprehensive security measures including blocking CALL and LOAD operations, and normalizing unicode escape sequences to prevent obfuscation attacks.

Changes:

  • Modified CypherQueryFilter to allow read-only function calls while blocking CALL (stored procedures) and LOAD (file system access) operations
  • Added unicode escape normalization to prevent obfuscation attacks
  • Added 55 comprehensive security test cases covering various attack vectors
  • Updated demo page to showcase relationship querying using the type(r) function
  • Added parser function tests for the new functionality

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/CypherQueryFilter.php Added CALL and LOAD to blocked keywords, added unicode escape normalization, simplified logic by removing function call blocking, added null coalescing operators for safety
tests/phpunit/CypherQueryFilterTest.php Converted function call tests from rejection to allowance, added 55 comprehensive security test cases covering write operations, case variations, procedures, file access, unicode obfuscation, and subqueries
src/EntryPoints/CypherRawParserFunction.php New file implementing the parser function with proper HTML escaping and error handling
tests/phpunit/EntryPoints/CypherRawParserFunctionTest.php New comprehensive test file with 6 test cases covering empty queries, write query rejection, valid queries, exceptions, whitespace handling, and XSS prevention
src/EntryPoints/NeoWikiHooks.php Registered the cypher_raw parser function hook
i18n/en.json Added 4 error message translations for the parser function
i18n/qqq.json Added documentation for the 4 new i18n messages
i18n/_Magic.php New file registering the cypher_raw magic word
extension.json Registered ParserFirstCallInit hook and NeoWikiMagic message file
DemoData/Page/Main_Page.wikitext Added link to Cypher demo page
DemoData/Page/Cypher.wikitext New demo page showcasing query examples including the use of type(r) function

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI commented Jan 28, 2026

@JeroenDeDauw I've opened a new pull request, #475, to work on those changes. Once the pull request is ready, I'll request review from you.

JeroenDeDauw and others added 2 commits January 28, 2026 21:51
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@malberts malberts merged commit 8860909 into master Jan 29, 2026
10 checks passed
@malberts malberts deleted the allow-cypher-functions branch January 29, 2026 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants