Skip to content

feat(badges): add compliance badge server and update README - #405

Open
alenmalhas wants to merge 1 commit into
compliance-framework:mainfrom
alenmalhas:feature/add-compliance-badge-endpoint
Open

alenmalhas wants to merge 1 commit into
compliance-framework:mainfrom
alenmalhas:feature/add-compliance-badge-endpoint

Conversation

@alenmalhas

@alenmalhas alenmalhas commented Nov 18, 2026 •

Copy link
Copy Markdown

SVG compliance badges

Summary

Add an optional server-side endpoint that generates SVG compliance badges from evidence selected by label names and values.

GET /badges/compliance.svg?repo=example%2Fproject&branch=main&event_type=CodeMerge

Motivation

Provide embeddable compliance indicators for repository READMEs and other documentation without requiring viewers to open CCF or authenticate. Ad hoc label queries avoid creating and maintaining saved evidence filters for each badge.

Implementation

  • Adds a dependency-free Node 22 service, an optional Docker badges target, and npm commands for running and testing it.
  • Converts query-string label/value pairs into equality conditions joined with AND.
  • Calls authenticated POST /api/evidence/search, using 50-record pages sorted by lastSeenAt descending.
  • Reads all result pages and aggregates evidence status.state values.
  • Returns red for any not-satisfied result, otherwise green for any satisfied result, or grey for empty/unknown results.
  • Leaves the Vue application and default static nginx deployment unchanged.

Why This Repository?

This approach treats badges as an optional presentation adapter over an existing API. It allows independent deployment without changing the evidence-search contract or coordinating an API release.

This is a delivery tradeoff, not a requirement that badges remain outside the API. An API-native implementation would avoid fetching evidence over HTTP and could remove the service’s session-cookie dependency. It would also require an explicit API-side policy for anonymous access to aggregate compliance results.

Authentication And Security

Badge viewers do not authenticate, but upstream evidence searches still do. The service requires CCF_BADGE_API_URL and CCF_BADGE_API_COOKIE_FILE; it does not bypass API authentication.

The cookie is read from a mounted secret on each lookup to support rotation. Visitor credentials are not forwarded, and credentials remain outside frontend configuration.

Deployment requires disclosure approval: arbitrary label queries expose aggregate results over evidence readable by the service identity. Use least-privilege access, ingress restrictions where appropriate, TLS, and rate limiting.

Reliability

  • Validates 1–50 label/value pairs.
  • Applies a five-second upstream timeout, sixteen-request concurrency limit, and 4 MiB response limit per page.
  • Returns 502 for upstream or malformed-response failures, 504 for timeouts, and 503 when busy.
  • Uses Cache-Control: no-store; failures are never rendered as misleading grey badges.

Verification

Both badge tests passed using an isolated Node-only Vitest configuration. Coverage includes query translation, pagination, SVG status precedence, credential rotation, validation, upstream failures, concurrency limits, and timeouts.

@coderabbitai

coderabbitai Bot commented Nov 18, 2026

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 6c19f73c-d250-42aa-85a0-0ce1fc7b6b82
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@gusfcarvalho

Copy link
Copy Markdown
Contributor

Hi @alenmalhas, sorry for the late reply!

As we discussed on our last call, this approach raises security concerns once we consider the whole CCF user base. Instead, I propose the following.

On API repo

1 - Opt in per saved evidence filter, not ad-hoc label queries. Make the badge a setting on the filter, set via POST/PUT /api/filters, e.g. "badge": {"enabled": true, "label": "compliance", "slug": "payments-service"}. A per-filter opt-in makes disclosure an explicit choice on one object that can be reviewed and turned off. Slugs are human-readable, unique across filters (a partial unique index on non-null slugs) and format-validated. Changing or clearing a slug revokes every embed using it. Saved filters are cheap to create and already carry SSP scope and control/component links.
2- Gate publishing behind its own permission. Enabling a badge is a disclosure decision, so it should need its own action (e.g. filter:publish, granted to admin by default), not plain filter:update, which contributors already have, and every authenticated user has under the builtin driver.

3- The API renders the SVG.

  • GET /api/filters/:id/badge.svg: authenticated (filter:read), so the UI can preview a badge before it's published.
  • GET /api/public/badges/.svg: no auth, 404 unless the slug belongs to a filter with the badge enabled, and available regardless of StrictDisablePublicAgentEndpoints.

4 - Both expose only the aggregate state, never individual evidence. The aggregation already exists in GET /api/evidence/compliance-by-filter/:id, so this is a thin wrapper plus a small SVG template: one grouped query, rendered at the source, with cache headers set there. READMEs can embed it directly, with no third-party badge service (shields.io etc.) and no extra runtime. Note that badges only render where the API is reachable; on github.com that means the public route must be exposed to the internet.

This UI PR

1 - Drop the Node service and repurpose the PR for the UI side:

2- the badge toggle and slug field on the dashboard, with a note that published badges are visible to anyone with the URL;

  • a preview via the authenticated route;
  • a copy button for the embed snippet, e.g. [![Compliance](<API_URL>/api/public/badges/.svg)](<UI_URL>/dashboards/).

Would you be up for doing the API side along those lines? Happy to help shape it.

@alenmalhas

Copy link
Copy Markdown
Author

Hi @alenmalhas, sorry for the late reply!

As we discussed on our last call, this approach raises security concerns once we consider the whole CCF user base. Instead, I propose the following.

On API repo

1 - Opt in per saved evidence filter, not ad-hoc label queries. Make the badge a setting on the filter, set via POST/PUT /api/filters, e.g. "badge": {"enabled": true, "label": "compliance", "slug": "payments-service"}. A per-filter opt-in makes disclosure an explicit choice on one object that can be reviewed and turned off. Slugs are human-readable, unique across filters (a partial unique index on non-null slugs) and format-validated. Changing or clearing a slug revokes every embed using it. Saved filters are cheap to create and already carry SSP scope and control/component links. 2- Gate publishing behind its own permission. Enabling a badge is a disclosure decision, so it should need its own action (e.g. filter:publish, granted to admin by default), not plain filter:update, which contributors already have, and every authenticated user has under the builtin driver.

3- The API renders the SVG.

  • GET /api/filters/:id/badge.svg: authenticated (filter:read), so the UI can preview a badge before it's published.
  • GET /api/public/badges/.svg: no auth, 404 unless the slug belongs to a filter with the badge enabled, and available regardless of StrictDisablePublicAgentEndpoints.

4 - Both expose only the aggregate state, never individual evidence. The aggregation already exists in GET /api/evidence/compliance-by-filter/:id, so this is a thin wrapper plus a small SVG template: one grouped query, rendered at the source, with cache headers set there. READMEs can embed it directly, with no third-party badge service (shields.io etc.) and no extra runtime. Note that badges only render where the API is reachable; on github.com that means the public route must be exposed to the internet.

This UI PR

1 - Drop the Node service and repurpose the PR for the UI side:

2- the badge toggle and slug field on the dashboard, with a note that published badges are visible to anyone with the URL;

  • a preview via the authenticated route;
  • a copy button for the embed snippet, e.g. [![Compliance](<API_URL>/api/public/badges/.svg)](<UI_URL>/dashboards/).

Would you be up for doing the API side along those lines? Happy to help shape it.

Hi @gusfcarvalho , thanks for your details response and proposal.

Have you agreed with Doug-Read about above approach please?

The reason that I am asking is that for API repo pr#557 Doug stated his concerns about generating SVG in API project.
compliance-framework/api#557 (comment)

I don't mind following above proposal as long as it's agreed with Foug and anyone who is interested in API project.

What do you think?

@gusfcarvalho

gusfcarvalho commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Yes, this is shared understanding between ourselves :)

Please note the closed PR you linked would still pose a risk, so it would still be unacceptable. (as it's not really implementing the above)

@alenmalhas

alenmalhas commented Nov 25, 2026 •

Copy link
Copy Markdown
Author

Yes, this is shared understanding between ourselves :)

Please note the closed PR you linked would still pose a risk, so it would still be unacceptable. (as it's not really implementing the above)

Thanks for confirming @gusfcarvalho ; much appreciated.

Is below spec captures the details you want us to implement in API project please?
compliance-framework/api#585

If all good I will start implementing, else I will wait for your feedback.

This branch has not been deployed

No deployments
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