Skip to content

๐Ÿ›ก๏ธ Sentinel: [MEDIUM] API ํ‚ค ๊ฒ€์ฆ ์‹œ ์ฒ˜๋ฆฌ๋˜์ง€ ์•Š์€ ์˜ˆ์™ธ ์ˆ˜์ • - #490

Closed
seonghobae wants to merge 2 commits into
mainfrom
sentinel-fix-hmac-non-ascii-16646600909009856763
Closed

๐Ÿ›ก๏ธ Sentinel: [MEDIUM] API ํ‚ค ๊ฒ€์ฆ ์‹œ ์ฒ˜๋ฆฌ๋˜์ง€ ์•Š์€ ์˜ˆ์™ธ ์ˆ˜์ •#490
seonghobae wants to merge 2 commits into
mainfrom
sentinel-fix-hmac-non-ascii-16646600909009856763

Conversation

@seonghobae

@seonghobae seonghobae commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Verified succession

Exact predecessor 50e35b52f9e669fa163f325e77413b66e3fb10ac์˜ ์œ ํšจ ์š”๊ตฌ์‚ฌํ•ญ์€ non-ASCII X-API-Key๊ฐ€ hmac.compare_digest(str, str) ์˜ˆ์™ธ๋ฅผ ์ผ์œผํ‚ค์ง€ ์•Š๊ณ  ์ธ์ฆ ์‹คํŒจ๋กœ ์ฒ˜๋ฆฌ๋˜์–ด์•ผ ํ•œ๋‹ค๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. Canonical #520 exact cf730d007543ee828b7b8e77c9473288924047d4๊ฐ€ raw ASGI header bytes๋ฅผ ์ง์ ‘ ์ฝ์–ด ์ด ๊ณ„์•ฝ์„ ๋ณด์กดํ•˜๋ฉด์„œ configured Unicode credential success์™€ duplicate-header fail-closed๊นŒ์ง€ ๋” ๊ฐ•ํ•˜๊ฒŒ ๊ฒ€์ฆํ•ฉ๋‹ˆ๋‹ค.

#490์˜ decoded framework string UTF-8 ์žฌ์ธ์ฝ”๋”ฉ์€ Unicode credential์˜ raw byte identity๋ฅผ ํ›ผ์†ํ•  ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ ๋ณ„๋„ ์œ ํšจ source delta๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค. ์ƒˆ test_hmac.py, test_hmac_2.py, test_hmac_3.py๋Š” repository test harness์— ํ†ตํ•ฉ๋˜์ง€ ์•Š์€ ad-hoc server/socket/print repro scripts์ด๋ฉฐ, canonical #520์˜ executable unit/integration contracts๋ณด๋‹ค ์•ฝํ•˜๋ฏ€๋กœ ์Šน๊ณ„ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. Blanket .jules encoding ์ง€์นจ๋„ raw-ASGI boundary์™€ exactly-one header ์ •์ฑ…์œผ๋กœ ๊ต์ •๋œ canonical guidance๊ฐ€ ๋Œ€์ฒดํ•ฉ๋‹ˆ๋‹ค.

๋”ฐ๋ผ์„œ ๋ชจ๋“  ์œ ํšจ semantic/test intent๋Š” stronger successor #520์— ์™„์ „ ์Šน๊ณ„๋๊ณ , #520์€ protected main@90717c6e9954bf3b7a351137995ebe89975e46c2 ๋Œ€๋น„ behind_by=0์ธ non-force descendant์ž…๋‹ˆ๋‹ค.

@google-labs-jules

Copy link
Copy Markdown

๐Ÿ‘‹ Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a ๐Ÿ‘€ emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai

coderabbitai Bot commented Aug 27, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 12 minutes.

View limit details

Limit details: Youโ€™ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

โš™๏ธ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d2b4b5f8-dce6-419a-8307-c1c55c296491

๐Ÿ“ฅ Commits

Reviewing files that changed from the base of the PR and between a8e4956 and 50e35b5.

๐Ÿ“’ Files selected for processing (5)
  • .jules/sentinel.md
  • saas_web.py
  • test_hmac.py
  • test_hmac_2.py
  • test_hmac_3.py

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

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

@devin-ai-integration devin-ai-integration 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.

Devin Review found 3 potential issues.

Devin Review

Comment thread saas_web.py

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

๐Ÿ“ Info: API keys still sourced from environment

get_configured_api_keys reads CODEC_CARVER_API_KEYS from os.environ, the anti-pattern AGENTS.md marks for migration to the credential registry. Unchanged by this PR and outside the diff, but noted since adjacent auth code is being edited.

(Refers to this code)

Devin Review

Was this helpful? React with ๐Ÿ‘ or ๐Ÿ‘Ž to provide feedback.

Comment thread test_hmac.py
Comment on lines +1 to +53
from fastapi import FastAPI, Request
from fastapi.testclient import TestClient
from fastapi.responses import JSONResponse
import hmac
import traceback
import uvicorn
import httpx
import asyncio

app = FastAPI()

configured_keys = ["validkey"]

@app.middleware("http")
async def require_api_key(request: Request, call_next):
provided_key = request.headers.get("x-api-key", "")
try:
if not any(hmac.compare_digest(provided_key, key) for key in configured_keys):
return JSONResponse(status_code=401, content={"error": "Invalid or missing API key"})
except Exception as e:
print("Exception:", e)
traceback.print_exc()
return JSONResponse(status_code=500, content={"error": "Server error"})
return await call_next(request)

@app.get("/test")
def test():
return {"status": "ok"}

async def run_test():
config = uvicorn.Config(app, port=8888, log_level="info")
server = uvicorn.Server(config)
task = asyncio.create_task(server.serve())
await asyncio.sleep(1) # wait for server to start

# Use raw socket to bypass httpx ascii check
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("127.0.0.1", 8888))

# send raw bytes
req = b"GET /test HTTP/1.1\r\nHost: 127.0.0.1:8888\r\nx-api-key: invalid\xc3\xb1\r\n\r\n"
s.sendall(req)

resp = s.recv(4096)
print("Response:\n", resp.decode('latin1'))
s.close()

server.should_exit = True
await task

if __name__ == "__main__":
asyncio.run(run_test())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

๐ŸŸก Debug scratch files break the docstring-coverage gate

Three new root-level scripts (run_test even boots a live uvicorn server) carry no module or function docstrings. The repo mandates 100% interrogate coverage and excludes only scripts/tests/fuzz, so these root files fail the gate.

Prompt for agents
test_hmac.py, test_hmac_2.py, and test_hmac_3.py are manual debugging scripts left over from developing the hmac fix (test_hmac.py starts a real uvicorn server on port 8888 and uses raw sockets). They should not be committed: they add no automated test value (CI only runs unittest discover under tests/), and they violate the repo's 100% docstring-coverage rule since interrogate scans root-level files and only excludes scripts/tests/fuzz. Remove all three files. If a regression test for the non-ASCII API-key case is desired, add it as a proper unittest under tests/ with docstrings, using FastAPI TestClient rather than a live server.
Devin Review

Was this helpful? React with ๐Ÿ‘ or ๐Ÿ‘Ž to provide feedback.

Comment thread saas_web.py
provided_key = request.headers.get("x-api-key", "")
if not any(
hmac.compare_digest(provided_key, key) for key in configured_keys
hmac.compare_digest(provided_key.encode("utf-8"), key.encode("utf-8")) for key in configured_keys

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

๐Ÿ“ Info: UTF-8 encoding fix resolves the TypeError

require_api_key encodes both operands to bytes before comparison. Starlette decodes headers as latin-1, so the provided key can hold non-ASCII code points; str.encode('utf-8') never raises, removing the prior TypeError. ASCII comparison semantics are unchanged.

Devin Review

Was this helpful? React with ๐Ÿ‘ or ๐Ÿ‘Ž to provide feedback.

@seonghobae seonghobae closed this Sep 3, 2026
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.

1 participant