Skip to content

Harden policy validation checks - #683

Closed
coderabbitai[bot] wants to merge 3 commits into
fix/sarif-filter-printable-nulfrom
coderabbit/fix-policy-checks/dfd712e9
Closed

Harden policy validation checks#683
coderabbitai[bot] wants to merge 3 commits into
fix/sarif-filter-printable-nulfrom
coderabbit/fix-policy-checks/dfd712e9

Conversation

@coderabbitai

@coderabbitai coderabbitai Bot commented Aug 28, 2026

Copy link
Copy Markdown

Expand language-policy detection to catch more TypeScript runtime claims while excluding quoted historical text, fix pipeline and awk exit handling, and make missing YAML parsers fail workflow validation. Validation: Bash syntax checks and both policy scripts exited successfully; the workflow script reported no tracked workflows.

View coding task

@coderabbitai

coderabbitai Bot commented Aug 28, 2026

Copy link
Copy Markdown
Author

Important

Review skipped

This PR was authored by the user configured for CodeRabbit reviews. CodeRabbit does not review PRs authored by this user. It's recommended to use a dedicated user account to post CodeRabbit review feedback.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 198a7e5e-3fec-44b0-a1a5-47bd80257428

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Comment @coderabbitai help to get the list of available commands.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.

Run reviewer

TIP This summary will be updated as you push new changes.

@codacy-production codacy-production Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

While the PR is technically up to Codacy standards, several functional risks were identified during review. The hardening of policy validation introduces a logic flaw in the live() function; by discarding entire lines containing quoted text, the script may ignore legitimate policy violations appearing on the same line.

Additionally, the workflow validation script now mandates a YAML parser and exits with a failure status even if no workflows are present in the repository, which may lead to breaking CI in environments that do not require these checks. There is also a lack of automated test coverage for the expanded regex patterns and filtering logic, making the hardening difficult to verify.

About this PR

  • The check-workflows-parse.sh script exits with code 1 if no parser is found before checking if workflows actually exist. This could cause unnecessary CI failures in repositories that contain no workflows but lack the required tooling in their runner environment.
  • The PR lacks automated tests (e.g., BATS or shell unit tests) to verify the expanded regex patterns and the new line-filtering logic for quotes. Without these, it is difficult to ensure the hardening works as intended across different edge cases.

Test suggestions

  • Verify 'Supports TypeScript' triggers a failure in standard policy text.
  • Verify 'Supports TypeScript' is ignored when inside a markdown blockquote ('>').
  • Verify 'Supports TypeScript' is ignored when wrapped in double quotes (") or curly quotes (“”).
  • Verify a policy table with an empty first cell ('blanking scar') causes the script to fail.
  • Verify check-workflows-parse.sh returns exit code 1 when no YAML parser is available in the environment.
Prompt proposal for missing tests
Consider implementing these tests if applicable:
1. Verify 'Supports TypeScript' triggers a failure in standard policy text.
2. Verify 'Supports TypeScript' is ignored when inside a markdown blockquote ('>').
3. Verify 'Supports TypeScript' is ignored when wrapped in double quotes (") or curly quotes (“”).
4. Verify a policy table with an empty first cell ('blanking scar') causes the script to fail.
5. Verify `check-workflows-parse.sh` returns exit code 1 when no YAML parser is available in the environment.

TIP Improve review quality by adding custom instructions
TIP How was this review? Give us feedback

# 2. The rule that told repos not to declare dependencies at all. hyperpolymath/ubicity
# a phrase inside a blockquote or quotation marks is HISTORY, not policy
live(){ grep -vE '^[[:space:]]*>' "$1" | grep -vE '"[^"]*'"$2"'[^"]*"|“[^”]*'"$2"'[^”]*”'; }
live(){ grep -vE '^[[:space:]]*>' "$1" | grep -vE '"[^"]*('"$2"')[^"]*"|“[^”]*('"$2"')[^”]*”'; }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 MEDIUM RISK

The current implementation of live using grep -vE to exclude quoted patterns can lead to false negatives. If a line contains both a legitimate violation and a quoted historical reference, the entire line is discarded. Instead of excluding the whole line, modify the function to strip the quoted substrings before performing the violation check.

Comment thread tools/policy/check-workflows-parse.sh Outdated
# "no typescript ... that should not exist at all."
if grep -nE 'Executes .\.ts. directly|JS/TS runtime' "$f" >/dev/null; then
fail "$f:$(grep -nE 'Executes .\.ts. directly|JS/TS runtime' "$f" | head -1 | cut -d: -f1)" \
typescript_runtime='Executes .\.ts. directly|JS/TS runtime|[Ss]upports? TypeScript|[Rr]uns? [^[:alnum:][:space:]]*\.ts[^[:alnum:][:space:]]* files?'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚪ LOW RISK

Suggestion: The regex pattern .\.ts. uses unescaped dots as wildcards, which may be too broad for a policy gate and lead to false positives. Refine this to use literal characters (like backticks or quotes) common in markdown documentation to ensure more precise matching.

@JoshuaJewell JoshuaJewell left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This fixes some of the previous issues. However, live() removes the entire line when it finds a quoted historical match - please strip or mask the quoted substring instead. The workflow checker should also discover workflow files before requiring a parser, so repositories with no workflows can still take the documented “nothing to check” path.

Please add reproducible fixtures for quoted history, quoted history plus a live violation on the same line, the blank-cell case, no workflows, and workflows without a parser. The current Actions runs all ended in startup failure and Sonar’s quality gate is failing, so the changes are not otherwise adequately verified.

Co-authored-by: codacy-production[bot] <61871480+codacy-production[bot]@users.noreply.github.com>
Signed-off-by: Jonathan D.A. Jewell <6759885+hyperpolymath@users.noreply.github.com>
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
B Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

hyperpolymath added a commit that referenced this pull request Aug 29, 2026
## Outcome

Consolidates the sound intent of #661, #682, and #683 onto current
`main` without importing their stacked/conflicting history.

- adds a NUL-safe language-policy invariant gate
- masks quoted historical substrings instead of discarding whole lines
- discovers tracked workflows before requiring a YAML parser
- fails closed when workflows exist but no parser is available
- uses a portable byte-level forbidden-control check
- wires both gates into the reusable governance workflow
- adds executable positive and negative fixtures

## Planted controls

Verified locally:

- quoted history: pass
- quoted history plus a live violation on the same line: fail
- blockquoted history: pass
- blank policy cell: fail
- no workflows and no parser: pass
- workflow present and no parser: fail
- valid workflow YAML: pass
- invalid workflow YAML: fail
- all 157 currently tracked Standards workflows: parse

Also passed `just validate`, `just test`, `bash -n`, and `git diff
--check`.

Supersedes #661, #682, and #683 after merge.
@hyperpolymath

Copy link
Copy Markdown
Owner

Superseded by merged #690. Its useful partial reviewer fixes were independently verified and incorporated together with the missing quote filtering, workflow-script checkout, forbidden-control logic, and regression fixtures (4d104d3).

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.

2 participants