Skip to content

fix(plugins): encode uid in linear/hive/manual-import URL contexts - #13659

Open
Da7em-T wants to merge 1 commit into
BasedHardware:mainfrom
Da7em-T:fix/plugin-uid-encoding-extra
Open

Da7em-T wants to merge 1 commit into
BasedHardware:mainfrom
Da7em-T:fix/plugin-uid-encoding-extra

Conversation

@Da7em-T

@Da7em-T Da7em-T commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Follow-up to the setup-page uid reflection fix — same defect class in three more plugins:

  • omi-linear-app: oauth_url built as f"/auth/linear?uid={uid}" and rendered into href targets in setup.html; two post-OAuth/disconnect redirects used /?uid={uid} raw. &/# in uid corrupted the query (verified: uid=x&error=injected#frag produced /auth/linear?uid=x&error=injected#frag).
  • omi-hive-app: three RedirectResponse(url=f"/?uid={uid}...") sites, including the API-key error path — a & in uid injected extra query params into the setup page URL.
  • import/manual-import: user_id interpolated raw into the OMI API POST query.

Fix: urllib.parse.quote(value, safe="") in each URL context; the linear template now renders a uid_q context var for href query params while uid stays for display.

Failure-Class: none

Test plan

  • python3 plugins/test_uid_reflection_extra.py — 5/5 pass, hermetic (FastAPI/Flask/requests/openai stubbed); drives the real home, connect_api_key, disconnect_*, and submit_memories handlers
  • Verified on pre-fix code: /auth/linear?uid=x&error=injected#frag (injection survives)
  • Registered as plugin-uid-query-encoding-extra-tests in .github/checks-manifest.yaml (local + ci lanes)

Generated with Devin

Review in cubic

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

@cubic-dev-ai cubic-dev-ai 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.

3 issues found across 6 files

Confidence score: 3/5

  • .github/checks-manifest.yaml still interpolates raw uid into setup-page href and form-action query targets, leaving the defect this PR addresses in the hive template; apply the same escaping fix to these occurrences.
  • plugins/test_uid_reflection_extra.py checks setup.html source text rather than rendered behavior, so the tests may pass while the generated links remain unsafe; label these as static tripwires and add behavioral coverage.
  • plugins/import/manual-import/app.py passes non-string JSON uid values to quote(), causing a 500 for inputs such as numeric, boolean, or list IDs; validate the type and return an appropriate client error.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name=".github/checks-manifest.yaml">

<violation number="1" location=".github/checks-manifest.yaml:951">
P2: The hive setup template still interpolates raw uid into href/form-action query targets (`/disconnect?uid={{ uid }}` at setup.html:486, `/settings/api-key?uid={{ uid }}` at :541), the exact defect this PR fixed in linear's template (`uid={{ uid }}` -> `uid={{ uid_q }}`). The home() handler passes only raw `uid` to the template context, so a uid containing & or # still corrupts the rendered URL. The newly registered regression test covers hive redirects but, unlike the linear template assert, never checks hive's template. Mirror the linear fix: pass an encoded `uid_q` from home() and render it in both hrefs.</violation>
</file>

<file name="plugins/import/manual-import/app.py">

<violation number="1" location="plugins/import/manual-import/app.py:312">
P3: `quote()` raises `TypeError` for any non-string `user_id`, and the `if not user_id` guard only rejects falsy values, so a JSON numeric/bool/list `uid` (e.g. `"uid": 123`) now returns a 500 from the outer except clause. Normalize to `str` before quoting.</violation>
</file>

<file name="plugins/test_uid_reflection_extra.py">

<violation number="1" location="plugins/test_uid_reflection_extra.py:155">
P3: The `uid={{ uid_q }}` / `uid={{ uid }}` template checks read setup.html source text, so they are static tripwires rather than behavior checks. Per AGENTS.md, source-string assertions must be labeled as static tripwires. Add a brief comment noting these verify the template text only and that the behavior contract is the `oauth_url` assertion above.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic


- id: plugin-uid-query-encoding-extra-tests
command: ["python3", "plugins/test_uid_reflection_extra.py"]
triggers: ["plugins/omi-linear-app/**", "plugins/omi-hive-app/**", "plugins/import/manual-import/**", "plugins/test_uid_reflection_extra.py", ".github/checks-manifest.yaml"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: The hive setup template still interpolates raw uid into href/form-action query targets (/disconnect?uid={{ uid }} at setup.html:486, /settings/api-key?uid={{ uid }} at :541), the exact defect this PR fixed in linear's template (uid={{ uid }} -> uid={{ uid_q }}). The home() handler passes only raw uid to the template context, so a uid containing & or # still corrupts the rendered URL. The newly registered regression test covers hive redirects but, unlike the linear template assert, never checks hive's template. Mirror the linear fix: pass an encoded uid_q from home() and render it in both hrefs.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At .github/checks-manifest.yaml, line 951:

<comment>The hive setup template still interpolates raw uid into href/form-action query targets (`/disconnect?uid={{ uid }}` at setup.html:486, `/settings/api-key?uid={{ uid }}` at :541), the exact defect this PR fixed in linear's template (`uid={{ uid }}` -> `uid={{ uid_q }}`). The home() handler passes only raw `uid` to the template context, so a uid containing & or # still corrupts the rendered URL. The newly registered regression test covers hive redirects but, unlike the linear template assert, never checks hive's template. Mirror the linear fix: pass an encoded `uid_q` from home() and render it in both hrefs.</comment>

<file context>
@@ -946,6 +946,12 @@ checks:
 
+  - id: plugin-uid-query-encoding-extra-tests
+    command: ["python3", "plugins/test_uid_reflection_extra.py"]
+    triggers: ["plugins/omi-linear-app/**", "plugins/omi-hive-app/**", "plugins/import/manual-import/**", "plugins/test_uid_reflection_extra.py", ".github/checks-manifest.yaml"]
+    lanes: ["local", "ci"]
+    reason: "the client-controlled uid/user_id was interpolated raw into linear's setup oauth_url + template hrefs, hive's redirect Location headers, and manual-import's API query; & or # in the value corrupted the query string (verified param injection)"
</file context>


# Send the request to OMI API with dynamic user_id (still using the facts endpoint)
response = requests.post(f"{API_URL}?uid={user_id}", headers=headers, data=json.dumps(memory_data))
response = requests.post(f"{API_URL}?uid={quote(user_id, safe='')}", headers=headers, data=json.dumps(memory_data))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3: quote() raises TypeError for any non-string user_id, and the if not user_id guard only rejects falsy values, so a JSON numeric/bool/list uid (e.g. "uid": 123) now returns a 500 from the outer except clause. Normalize to str before quoting.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At plugins/import/manual-import/app.py, line 312:

<comment>`quote()` raises `TypeError` for any non-string `user_id`, and the `if not user_id` guard only rejects falsy values, so a JSON numeric/bool/list `uid` (e.g. `"uid": 123`) now returns a 500 from the outer except clause. Normalize to `str` before quoting.</comment>

<file context>
@@ -308,7 +309,7 @@ def submit_memories():
 
             # Send the request to OMI API with dynamic user_id (still using the facts endpoint)
-            response = requests.post(f"{API_URL}?uid={user_id}", headers=headers, data=json.dumps(memory_data))
+            response = requests.post(f"{API_URL}?uid={quote(user_id, safe='')}", headers=headers, data=json.dumps(memory_data))
 
             # Record result
</file context>
Suggested change
response = requests.post(f"{API_URL}?uid={quote(user_id, safe='')}", headers=headers, data=json.dumps(memory_data))
response = requests.post(f"{API_URL}?uid={quote(str(user_id), safe='')}", headers=headers, data=json.dumps(memory_data))

Comment on lines +155 to +156
assert "uid={{ uid_q }}" in template
assert "uid={{ uid }}" not in template

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3: The uid={{ uid_q }} / uid={{ uid }} template checks read setup.html source text, so they are static tripwires rather than behavior checks. Per AGENTS.md, source-string assertions must be labeled as static tripwires. Add a brief comment noting these verify the template text only and that the behavior contract is the oauth_url assertion above.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At plugins/test_uid_reflection_extra.py, line 155:

<comment>The `uid={{ uid_q }}` / `uid={{ uid }}` template checks read setup.html source text, so they are static tripwires rather than behavior checks. Per AGENTS.md, source-string assertions must be labeled as static tripwires. Add a brief comment noting these verify the template text only and that the behavior contract is the `oauth_url` assertion above.</comment>

<file context>
@@ -0,0 +1,211 @@
+    assert ctx["oauth_url"] == expected, ctx["oauth_url"]
+    # the template must render the encoded value into the href targets
+    template = (PLUGINS / "omi-linear-app" / "templates" / "setup.html").read_text()
+    assert "uid={{ uid_q }}" in template
+    assert "uid={{ uid }}" not in template
+
</file context>
Suggested change
assert "uid={{ uid_q }}" in template
assert "uid={{ uid }}" not in template
# Static tripwire: template source must reference uid_q, never raw uid.
assert "uid={{ uid_q }}" in template
assert "uid={{ uid }}" not in template

@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks @Da7em-T — reviewed all six changed files; the fix pattern is applied consistently and the hermetic regression suite passes when run isolated (5/5, stdlib-only stubs, no network/subprocess).

Per-file notes:

  • plugins/omi-linear-app/main.py — home() computes uid_q = urllib.parse.quote(uid, safe="") after the if not uid early return, so the None case can't reach quote(); oauth_url and both redirects (linear_callback, disconnect_linear) are encoded. Clean.
  • plugins/omi-linear-app/templates/setup.html — hrefs now render {{ uid_q }} while uid stays for display context; right split. One residual nit (pre-existing, untouched here): the setDefaultTeam() JS at the bottom of this template reads the decoded uid from URLSearchParams and re-interpolates it raw into the /settings/default-team?uid=${uid} fetch — same corruption class for &/# uids. Low severity (same-origin setup page); fine as a follow-up.
  • plugins/omi-hive-app/main.py — all three RedirectResponse sites encoded, including the API-key error path where a & in uid previously injected an extra error param; no raw {uid} interpolations remain in the file.
  • plugins/import/manual-import/app.py — quote(user_id, safe="") on the OMI API POST query. Correct.
  • plugins/test_uid_reflection_extra.py — genuinely hermetic (stdlib + sys.modules stubs; no subprocess/network/file writes) and drives the real handlers, including submit_memories. Verified 5/5 pass.
  • .github/checks-manifest.yaml — new check id plugin-uid-query-encoding-extra-tests is unique and its triggers cover every touched path; Hygiene passes on it.

CI note: "Dart Analyze & Tests" is red on app/test/providers/deletion_consistency_test.dart and app/test/widgets/chat_content_blocks_test.dart — that failure is pre-existing (it reproduces on the sibling Python-only PRs in this series) and is not caused by this change.

This PR is independently mergeable (no file overlap with #13658 despite being its follow-up), but since it's one of a same-day batch of PRs from a new account touching uid handling across many plugins, a human maintainer should confirm the series-wide fix pattern and landing order before merge.

Feedback by AI on behalf of David — leaving for human maintainer review of the uid-encoding series pattern and landing order.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

backend/plugins uid-encoding fix (linear/hive/manual-import), well-tested, root cause clear. CI: Dart Analyze & Tests fails on a stale-base compile error (app/test/widgets/chat_content_blocks_test.dart) unrelated to this diff and already fixed on current origin/main — leaving approved, not merging per hard floor.

@Git-on-my-level

Copy link
Copy Markdown
Member

Follow-up notes after the maintainer approval on this head — both verified against the tree, neither blocking this diff:

  1. The review finding on plugins/omi-hive-app/templates/setup.html checks out: it still carries three raw uid interpolations of exactly the class this PR fixes. They're untouched here (this PR's hive scope was the three RedirectResponse sites in main.py, all correctly encoded), so this is follow-up material rather than a gap in the PR:

    • L486: <a href="/disconnect?uid={{ uid }}" ...>
    • L541: <form action="/settings/api-key?uid={{ uid }}" ...>
    • L617–618: JS re-interpolating the URLSearchParams uid into the /settings/default-project?uid=${uid}&... fetch — the linear template's setDefaultTeam() fetch has the same JS pattern (noted in the earlier review)

    A third follow-up in this series could reuse the uid_q context-var pattern from plugins/omi-linear-app/main.py for the href/form targets, plus encodeURIComponent() in the two JS fetches.

  2. On the test note: the template assertions in test_linear_setup_oauth_url_encodes_uid are source-text checks ("uid={{ uid_q }}" in template), so they act as tripwires — they wouldn't catch a rendering regression that keeps the exact string but changes behavior. The behavioral handler tests alongside them (which drive the real home/redirect/submit_memories code paths) are the substantive coverage, so this is fine as-is.

Fix as scoped is correct and well tested; nothing further needed from this PR.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level Git-on-my-level removed the needs-maintainer-review Needs a human maintainer to sign off before merge label Sep 13, 2026

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Real query/param-injection fix (uid corrupts oauth_url/redirects in linear/hive/manual-import); scoped, hermetic tests added, verified against backend behavior.

@aryanorastar

Copy link
Copy Markdown
Collaborator

Keeping this open on 8b4ed22b8a07.

DIRTY + Dart Analyze red; linear/hive/manual-import uid encode + tests; kodjima APPROVE ≠ merge.

kodjima APPROVE is the size gate, not maintainer merge.

I am not approving or merging this SHA.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Follow-up to the uid-reflection fix covering linear/hive/manual-import: same defect class, scoped percent-encoding fixes with hermetic tests demonstrating query-param injection pre-fix. Only red check is the same pre-existing unrelated Dart compile error.

@aryanorastar

Copy link
Copy Markdown
Collaborator

Manual import, Hive, and Linear on main still interpolate a raw uid. This head quotes those sinks, and the test pins a hostile uid. 8b4ed22b8a07 conflicts, so rebase it. This stays open and unapproved.

— Astar, on behalf of @aryanorastar

@aryanorastar

Copy link
Copy Markdown
Collaborator

Keeping this open. Not approving 8b4ed22b8a07. origin/main linear already urllib.parse.quote (main.py:445). CONFLICTING/DIRTY, CI FAILURE. Rebase leftover; do not approve.

— Astar, on behalf of @aryanorastar

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants