Skip to content

Commit

Permalink
fix(store): Sanitize username and Agent Name in URLs (#9096)
Browse files Browse the repository at this point in the history
[fix(store): Sanitize username and Agent Name in
URLs](28b86d4)

---------

Co-authored-by: abhi1992002 <abhimanyu1992002@gmail.com>
  • Loading branch information
Swiftyos and Abhi1992002 authored Dec 20, 2024
1 parent 4cc8616 commit a8339d0
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 9 deletions.
7 changes: 7 additions & 0 deletions autogpt_platform/backend/backend/server/v2/store/routes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import typing
import urllib.parse

import autogpt_libs.auth.depends
import autogpt_libs.auth.middleware
Expand Down Expand Up @@ -150,6 +151,9 @@ async def get_agent(
It returns the store listing agents details.
"""
try:
username = urllib.parse.unquote(username).lower()
# URL decode the agent name since it comes from the URL path
agent_name = urllib.parse.unquote(agent_name)
agent = await backend.server.v2.store.db.get_store_agent_details(
username=username, agent_name=agent_name
)
Expand Down Expand Up @@ -185,6 +189,8 @@ async def create_review(
The created review
"""
try:
username = urllib.parse.unquote(username).lower()
agent_name = urllib.parse.unquote(agent_name)
# Create the review
created_review = await backend.server.v2.store.db.create_store_review(
user_id=user_id,
Expand Down Expand Up @@ -255,6 +261,7 @@ async def get_creator(username: str) -> backend.server.v2.store.model.CreatorDet
- Creator Details Page
"""
try:
username = urllib.parse.unquote(username).lower()
creator = await backend.server.v2.store.db.get_store_creator_details(
username=username.lower()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ export default async function Page({

const breadcrumbs = [
{ name: "Store", link: "/store" },
{ name: agent.creator, link: `/store/creator/${agent.creator}` },
{
name: agent.creator,
link: `/store/creator/${encodeURIComponent(agent.creator)}`,
},
{ name: agent.agent_name, link: "#" },
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const AgentInfo: React.FC<AgentInfoProps> = ({
by
</div>
<Link
href={`/store/creator/${creator}`}
href={`/store/creator/${encodeURIComponent(creator)}`}
className="font-geist text-base font-medium text-neutral-800 hover:underline dark:text-neutral-200 sm:text-lg lg:text-xl"
>
{creator}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const BecomeACreator: React.FC<BecomeACreatorProps> = ({
</h2>

{/* Content Container */}
<div className="absolute left-1/2 top-1/2 mt-[60px] w-full max-w-[900px] -translate-x-1/2 -translate-y-1/2 px-4 pt-16 text-center sm:mt-0 md:px-6 lg:px-0">
<div className="absolute left-1/2 top-1/2 w-full max-w-[900px] -translate-x-1/2 -translate-y-1/2 px-4 pt-16 text-center md:px-6 lg:px-0">
<h2 className="font-poppins underline-from-font decoration-skip-ink-none mb-6 text-center text-[48px] font-semibold leading-[54px] tracking-[-0.012em] text-neutral-950 dark:text-neutral-50 md:mb-8 lg:mb-12">
Build AI agents and share
<br />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export const AgentsSection: React.FC<AgentsSectionProps> = ({
const displayedAgents = allAgents.slice(0, 9);

const handleCardClick = (creator: string, slug: string) => {
router.push(`/store/agent/${creator}/${slug}`);
router.push(
`/store/agent/${encodeURIComponent(creator)}/${encodeURIComponent(slug)}`,
);
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const FeaturedCreators: React.FC<FeaturedCreatorsProps> = ({
const router = useRouter();

const handleCardClick = (creator: string) => {
router.push(`/store/creator/${creator}`);
router.push(`/store/creator/${encodeURIComponent(creator)}`);
};

// Only show first 4 creators
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ export const FeaturedSection: React.FC<FeaturedSectionProps> = ({
const router = useRouter();

const handleCardClick = (creator: string, slug: string) => {
router.push(`/store/agent/${creator}/${slug}`);
router.push(
`/store/agent/${encodeURIComponent(creator)}/${encodeURIComponent(slug)}`,
);
};

const handlePrevSlide = useCallback(() => {
Expand Down
12 changes: 9 additions & 3 deletions autogpt_platform/frontend/src/lib/autogpt-server-api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,11 @@ export default class BackendAPI {
username: string,
agentName: string,
): Promise<StoreAgentDetails> {
return this._get(`/store/agents/${username}/${agentName}`);
return this._get(
`/store/agents/${encodeURIComponent(username)}/${encodeURIComponent(
agentName,
)}`,
);
}

getStoreCreators(params?: {
Expand All @@ -283,7 +287,7 @@ export default class BackendAPI {
}

getStoreCreator(username: string): Promise<CreatorDetails> {
return this._get(`/store/creator/${username}`);
return this._get(`/store/creator/${encodeURIComponent(username)}`);
}

getStoreSubmissions(params?: {
Expand Down Expand Up @@ -330,7 +334,9 @@ export default class BackendAPI {
console.log("Reviewing agent: ", username, agentName, review);
return this._request(
"POST",
`/store/agents/${username}/${agentName}/review`,
`/store/agents/${encodeURIComponent(username)}/${encodeURIComponent(
agentName,
)}/review`,
review,
);
}
Expand Down

0 comments on commit a8339d0

Please sign in to comment.