Standard Alerts Cannot Know Every Museum Policy
A museum application might contain a private accession field used for conservation notes and a public export endpoint that serves catalog listings. The default security query suite can identify many familiar problems, yet it cannot understand every organization-specific rule about which notes may appear in a public JSON response. A custom CodeQL query can help reviewers find code paths worth investigating before a release.
In a hypothetical app, an API handler copies an object into a serializer shared by public and staff-only views. The aim is not to prove data leaked. Instead, a security engineer wants a repeatable alert when a potentially restricted field could reach a public response without the expected authorization check. Frame the query as a review trigger with a clear threat model, not an all-knowing privacy detector.
Map the Source, Transformation, and Sink
Before writing a query, document the source of restricted data, the authorized transformation, and the output surface. A source might be a database property for internal notes; a sink might be a public catalog response or export function. The actual architecture determines whether a flow is risky. Avoid marking every reference to a sensitive field as a vulnerability.
Sketch two versions of the path: one that passes through a reliable, tested redaction and authorization function, and one that bypasses it. Use a deliberately small fixture repository to verify the difference. This gives the custom CodeQL rule a concrete purpose and supplies regression examples for future refactors. Never use real donor records as test fixtures.

Understand What a Custom Query Can Do
GitHub documents custom CodeQL queries as extensions to built-in vulnerability analysis and project-specific coding checks. Queries use `.ql` files and may be shared in packs. The CodeQL CLI analyzes a language-specific database; results depend on the extractor, installed packs, and the modeled data-flow logic. A custom query is not a runtime authorization mechanism.
Choose an initial query scope narrow enough to maintain. For example, detect calls to a designated public serializer that receive a restricted record type without an approved sanitizer in the flow model. If the language or framework lacks appropriate models, be explicit about detection gaps and test the custom logic against representative source code. The query may need updates whenever application architecture changes.
Give the Rule Valid and Useful Metadata
Queries intended for interpreted `database analyze` results need metadata. GitHub documents fields such as a lowercase query ID and a kind including `problem` or `path-problem`, according to result type. For a flow with meaningful source-to-sink steps, a path-style result can be more actionable than a generic location warning. Follow current metadata guidance rather than relying on a sketch in this article.
Write a short explanation of why the path matters, which data types are in scope, and how developers can verify authorization. Provide a correction path that does not advise simply silencing the query. If the team includes custom documentation in the query pack, make sure the output can be interpreted by reviewers who have not authored the rule.

Run the Query Against Positive and Negative Fixtures
Create two synthetic fixtures: a safe path using a public projection with a deliberate allowlist, and an unsafe path that forwards restricted fields. Run the query and inspect whether it distinguishes them. Also test wrappers, helper functions, aliases, and error handlers, because real applications rarely fit a straight-line example.
A false positive is a prompt to refine the model, not evidence of a breach. A false negative is more serious because the scanner might silently miss an alternate serialization route. Record test repository revision, CodeQL version, query pack version, and language. Keep the fixture set in source control so future maintainers can reproduce the intent without viewing private collection data.

Review Alerts in the Release Process
Use the custom rule alongside existing scanning and unit tests, not as their replacement. A reviewer should inspect the source path, check the live authorization model, and decide whether the flow represents a reachable public route. Some findings may be harmless because a preceding permission layer applies, while others may expose a genuine bypass that merits blocking the release.
Document every material decision. If the rule reveals a defect, fix the code, add a regression test that verifies unauthorized users cannot retrieve the field, and rerun scanning. If the query is wrong, revise the custom model and preserve why the alert was dismissed. Suppressing alerts without explanation erases precisely the learning the custom rule was meant to provide.
Keep Security Boundaries Outside the Scanner
Access control belongs in the application and data layer. A passing CodeQL run does not verify that live permissions are configured correctly, that caches do not leak restricted responses, or that deployed secrets are protected. Test anonymous and staff roles on a safe staging instance with synthetic records, and inspect what a real client receives.
Do not place production credentials, genuine restricted images, or personal data into CodeQL test cases. Control who can modify query packs and the workflows that run them. A modified security rule could make a build look clean by omission. Use protected reviews for both application code and custom security policy changes.
Treat the Query as a Living Detection Rule
Review query findings after significant serializer, ORM, or API framework changes. Version the rule and its fixtures together, and track where the team saw a false positive or missed a path. If the application adds another public output format, extend the threat model before reusing the old rule unchanged.
The result is a more focused review queue, not a guarantee of no private-data exposure. A good custom CodeQL query makes potentially dangerous paths visible to trained maintainers and encourages durable tests. It does not authorize publication of any record or supersede the museum’s data-governance decisions.
How We Research
We reviewed the following official developer documentation on November 8, 2026: GitHub: Custom CodeQL queries; GitHub: Writing custom queries for the CodeQL CLI; GitHub: Code scanning with CodeQL. We compared the documented parameters, data flow and stated limitations with this hypothetical editorial scenario. The diagrams are original instructional illustrations, not real vendor screenshots or outputs. We did not submit private archive material, run a production API evaluation, measure tool accuracy, obtain legal consent, or test a live service configuration. Product behavior, access rules, quotas and supported settings may change; confirm the latest documentation and your organization’s policies before deployment.
Frequently Asked Questions
No. It analyzes modeled source code paths; runtime configuration and unmodeled flows require separate tests.
A versioned way to organize and share queries and their dependencies. Use official documentation for the supported language and pack format.
No. Confirm reachability and authorization with a security reviewer before classifying an alert.
Use synthetic fixtures instead, so test artifacts do not become another private-data exposure.
No. Release still requires access-control tests, review of source permissions, and other security checks.
