bobbai00 commented on code in PR #9043:
URL: https://github.com/apache/texera/pull/9043#discussion_r4645801476
##########
agent-service/src/server.ts:
##########
@@ -168,6 +168,22 @@ const agentsRouter = new Elysia({ prefix: "/agents" })
set.status = ERROR_STATUS[errorMessage] ?? 500;
return { error: errorMessage || "Internal server error" };
})
+ // Authenticate every agent request by verifying the Bearer JWT ourselves
+ // (defense in depth — the gateway ext_authz also checks it, but this also
+ // covers direct access, e.g. bare-metal dev). The WebSocket route is guarded
+ // separately in its open() handler via the access-token query param.
+ // Using onTransform ensures authentication runs before body schema
validation,
+ // so unauthenticated requests receive 401/403 rather than validation 400s.
+ .onTransform(({ request }) => {
Review Comment:
**Advisory:**
Item 1 of the PR description still calls this an `.onBeforeHandle` guard.
Running in `onTransform` is what puts authentication ahead of body validation,
so the squash commit should name the hook that does it. It can change in the
same edit that restores the generative-AI section.
##########
common/auth/src/main/scala/org/apache/texera/auth/JwtAuth.scala:
##########
@@ -53,11 +53,13 @@ object JwtAuth {
/**
* Build the claim set for `user`. The claim names are a contract with the
hand-written
- * TypeScript reader in
`frontend/src/app/common/service/user/auth.service.ts`, which is not
- * compiled against this file — so renaming one here silently breaks the
frontend. The `avatar`
- * claim was `googleAvatar` until the column and the value stopped being
Google-specific; the
- * TypeScript reader was renamed in the same change, and both sides still
accept the old name
- * so tokens issued before it keep working (see [[JwtParser]] for when that
can go).
+ * TypeScript readers in
`frontend/src/app/common/service/user/auth.service.ts` and
+ * `agent-service/src/config/jwt.ts`, which are not compiled against this
file — so
+ * renaming one here silently breaks the frontend and agent-service
authentication.
+ * The `avatar` claim was `googleAvatar` until the column and the value
stopped being
+ * Google-specific; the TypeScript reader was renamed in the same change,
and both sides
+ * still accept the old name so tokens issued before it keep working (see
[[JwtParser]]
+ * for when that can go).
Review Comment:
**Polish:**
Now that the doc names two TypeScript readers, "the TypeScript reader was
renamed ... both sides" no longer points at one, and agent-service reads no
avatar claim. The `[[JwtParser]]` pointer is stale too, since
[#8314](https://github.com/apache/texera/pull/8314) removed that note. The
removal condition now lives in
[auth.service.ts:261-263](https://github.com/apache/texera/blob/6e43673f40098b33b1d5b9546a404126c040b8df/frontend/src/app/common/service/user/auth.service.ts#L261-L263),
so the suggestion states it inline.
```suggestion
* The `avatar` claim was `googleAvatar` until the column and the value
stopped being
* Google-specific. The frontend reader and [[JwtParser]] still accept
the old name, because
* tokens issued before the rename stay valid for a week; the fallback
can go once they have
* all expired.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]