Skip to content

Conversation

@ardafincan
Copy link
Contributor

  • What kind of change does this PR introduce?

This PR introduces agent API Origin Whitelisting feature for security purposes. User can define allowed origins for accessing agents via API calls.

@vercel
Copy link

vercel bot commented Oct 13, 2025

@ardafincan is attempting to deploy a commit to the Arc53 Team on Vercel.

A member of the Team first needs to authorize it.

@codecov
Copy link

codecov bot commented Oct 13, 2025

Codecov Report

❌ Patch coverage is 15.00000% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 42.64%. Comparing base (9b2383b) to head (3f4cbf3).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
application/api/answer/routes/base.py 7.14% 13 Missing ⚠️
application/api/answer/routes/answer.py 0.00% 2 Missing ⚠️
application/api/answer/routes/stream.py 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2062      +/-   ##
==========================================
+ Coverage   42.28%   42.64%   +0.35%     
==========================================
  Files         136      137       +1     
  Lines        9315     9478     +163     
==========================================
+ Hits         3939     4042     +103     
- Misses       5376     5436      +60     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ardafincan ardafincan changed the title Implemented API Origin Whitelisting Feat: Agent API Origin Whitelisting Oct 13, 2025
@vercel
Copy link

vercel bot commented Oct 15, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
oss-docsgpt Ready Ready Preview Comment Oct 15, 2025 6:07pm

@ardafincan
Copy link
Contributor Author

Hey @dartpain, you have any time to review this one?

@dartpain dartpain requested a review from siiddhantt October 30, 2025 11:12
agent = agents_collection.find_one({"key": api_key})

request_origin = request.headers.get("Origin")
granted_origins = json.loads(agent.get("granted_origins", "[]"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

This would crash with AttributeError if agent is not found, could add a null check like in check_usage()


if granted_origins == []:
return None
elif request_origin in granted_origins or (str(request_origin)+"/") in granted_origins:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Trailing slashes and case differences might cause valid requests to fail. Might want to normalize the URLs before comparing them.

return None

return make_response(
jsonify({"success": "True", "message": "You are not authorized for this action."}),
Copy link
Collaborator

Choose a reason for hiding this comment

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

"True"

Should make this boolean for consistency.

value={originInput}
onChange={(e) => setOriginInput(e.target.value)}
placeholder="Enter origin URL (https://example.com)"
pattern="^https|http://.+"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wouldn't ^https?://.+ be a better regex to use?

/>
<button
type="button"
onClick={() => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider refactoring this into a shared handleAddOrigin() as there is duplicated code just before.

data["tools"] = []
if "sources" in data:
try:
data["sources"] = json.loads(data["sources"])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add granted_origins to early JSON parsing (like sources/tools):

if "granted_origins" in data:
    try:
        data["granted_origins"] = json.loads(data["granted_origins"])
    except json.JSONDecodeError:
        data["granted_origins"] = []

data = request.get_json()
else:
data = request.form.to_dict()
json_fields = ["tools", "sources", "json_schema"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add "granted_origins" to json_fields list for early parsing:

json_fields = ["tools", "sources", "json_schema", "granted_origins"]

This ensures consistency with how other JSON fields are handled.

<div className="space-y-2">
{agent.granted_origins.map((origin, index) => (
<div
key={index}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could improve it by using a unique key instead of index keys, maybe key={origin}?

@siiddhantt
Copy link
Collaborator

siiddhantt commented Nov 3, 2025

Hi @ardafincan thanks for the PR!
Could you also add tests to improve coverage and verify implementation. Tests like Valid/invalid origin checks, Missing Origin header, Invalid API key, Multiple origins, URL normalization edge cases would significantly improve coverage!

@ardafincan
Copy link
Contributor Author

Hey @siiddhantt, thanks for your detailed review. I am a bit busy this week, but I will handle the changes and test additions you wanted as soon as possible.

@siiddhantt
Copy link
Collaborator

No worries @ardafincan thanks for contributing!

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.

2 participants