Skip to content

fix(functions): route exactly and answer an empty 404, as deployed functions do - #327

Merged
chhavi-mandowara-cstk merged 1 commit into
v2-devfrom
CL-8970
Dec 4, 2026
Merged

chhavi-mandowara-cstk merged 1 commit into
v2-devfrom
CL-8970

Conversation

@chhavi-mandowara-cstk

Copy link
Copy Markdown
Contributor

What was wrong

Deployed, nginx (contentfly-nginx, upstream_proxy.set_proxy_target) sends a request to a cloud function only when its path matches the function's route exactly:

  • Exact path: a host-entry key equal to the URI (details[ngx.var.uri]).
  • [param] route: a Lua pattern that must match the whole URI (string.match(uri, pattern) == uri).

The deployment agent (setup_cloud_functions.go) gives every functions-folder file one of those two route types. HANDLE_ALL is only for a framework's SSR server. Anything else falls through to static hosting, and nginx answers 404 with its own page.

launch:functions:serve used Express's defaults:

  • /Hello ran hello.js (case-insensitive);
  • /hello/ ran it too (trailing slash allowed);
  • a path no function claims got Express's Cannot GET /… HTML page.

The lambda-node-bridge answers an unmatched path with an empty 404.

This is CL-8970 gap 7.

The change (src/functions/cloud-functions.ts)

  • app.set('case sensitive routing', true) and app.set('strict routing', true), set before the first app.use so the router picks them up.
  • answerNotFound: a request no route matched gets an empty 404, placed after the function routes. It is not an error handler, so a body that fails to parse still goes to answerRequestError (the existing malformed-JSON 400 test is unchanged).
  • AGENTS.md. The approved V1 differences now describe exact routing and the empty 404, and that deployed, nginx answers such a request itself.
  • .talismanrc. Refreshed checksums for cloud-functions.test.ts and AGENTS.md (test code and prose, no credentials).

Tests

src/functions/cloud-functions.test.ts:

  • matches a route only in its exact case, as deployed functions do: /Hello gives 404 and /hello gives 200. It failed before (200).
  • does not match a route with a trailing slash, as deployed functions do: /hello/ and /items/42/ give 404, and /items/42 gives 200. It failed before (200).
  • answers an empty 404 for a path no function claims, as deployed functions do: the existing 404 test, which now also asserts an empty body. It failed before (Express's HTML page).

Full suite in the pre-push hook: 189 suites, 3831 tests passed. Every hook ran (Snyk included), with no --no-verify.

E2E (http-sanity cloud-functions checks, AWS expectations)

Against launch:functions:serve, with the 28 checks from e2e PR contentstack/contentfly-e2e-tests#501:

  • v2-dev 424a26d: 23/28. /Query and /query/ answer 200.
  • This branch: 25/28. The 3 new routing checks pass, and no check got worse. The 3 still failing are gaps 8 and 10.

The new checks assert only the status (404). Deployed, these requests never reach a function and nginx answers with its own page, the same on AWS, Azure and GCP, so they have no known gap.

Not changed

  • nginx normalises the URI before matching (it decodes %XX and merges //), so /hell%6F reaches hello.js deployed but not under serve. That is path encoding, gap 11.
  • Method. Every function still answers every method, as before.

Jira: https://contentstack.atlassian.net/browse/CL-8970


Generated by Claude Code

…nctions do

Deployed, nginx sends a request to a cloud function only when its path
matches the function's route exactly: an exact-path entry keyed by the
URI, or for a [param] route a Lua pattern that must match the whole path.
Serve used Express's defaults, so /Hello ran hello.js, /hello/ did too,
and a path no function claims got Express's "Cannot GET" HTML page.

Serve now turns on Express's case sensitive routing and strict routing,
and answers a request no route matched with an empty 404, as the
lambda-node-bridge does. Error responses (a malformed body) still go to
answerRequestError, since answerNotFound is not an error handler.

AGENTS.md records the change, and the .talismanrc checksums of the two
touched files are refreshed.
@chhavi-mandowara-cstk
chhavi-mandowara-cstk requested a review from a team as a code owner December 4, 2026 10:27
@snyk-io

snyk-io Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues
✅ Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

🔒 Security Scan Results

ℹ️ Note: Only vulnerabilities with available fixes (upgrades or patches) are counted toward thresholds.

Check Type Count (with fixes) Without fixes Threshold Result
🔴 Critical Severity 0 0 10 ✅ Passed
🟠 High Severity 0 2 25 ✅ Passed
🟡 Medium Severity 0 10 500 ✅ Passed
🔵 Low Severity 0 0 1000 ✅ Passed

⏱️ SLA Breach Summary

✅ No SLA breaches detected. All vulnerabilities are within acceptable time thresholds.

Severity Breaches (with fixes) Breaches (no fixes) SLA Threshold (with/no fixes) Status
🔴 Critical 0 0 15 / 30 days ✅ Passed
🟠 High 0 0 30 / 120 days ✅ Passed
🟡 Medium 0 0 90 / 365 days ✅ Passed
🔵 Low 0 0 180 / 365 days ✅ Passed

ℹ️ Vulnerabilities Without Available Fixes (Informational Only)

The following vulnerabilities were detected but do not have fixes available (no upgrade or patch). These are excluded from failure thresholds:

  • Critical without fixes: 0
  • High without fixes: 2
  • Medium without fixes: 10
  • Low without fixes: 0

✅ BUILD PASSED - All security checks passed

@chhavi-mandowara-cstk
chhavi-mandowara-cstk merged commit 2213aa2 into v2-dev Dec 4, 2026
8 checks passed
@chhavi-mandowara-cstk
chhavi-mandowara-cstk deleted the CL-8970 branch December 4, 2026 11:44
tejas-contentstack pushed a commit that referenced this pull request Dec 4, 2026
Brings in the functions fixes from #327, #328 and #329. The only
conflict was .talismanrc, the AGENTS.md checksum line: both sides had
changed it, so it is recomputed with Talisman for the merged AGENTS.md.
All of our other .talismanrc entries are kept as they were.

#claude_code#
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
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.

4 participants