Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion analytics/loaders/OneDollarScript.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useScriptAsDataURI } from "@deco/deco/hooks";
import {
DEFAULT_COLLECTOR_ADDRESS,
USE_SITE_DOMAIN_FOR_ANALYTICS_SCRIPT,
} from "../../website/components/OneDollarStats.tsx";
import { Script } from "../../website/types.ts";
import { type Flag } from "@deco/deco";
Expand Down Expand Up @@ -80,7 +81,11 @@ const loader = (props: Props): Script => {
data-autocollect="false"
data-hash-routing="true"
data-url="${collector}"
src="/live/invoke/website/loaders/analyticsScript.ts?url=${staticScriptUrl}"
src="${
USE_SITE_DOMAIN_FOR_ANALYTICS_SCRIPT
? `/live/invoke/website/loaders/analyticsScript.ts?url=${staticScriptUrl}`
: staticScriptUrl
}"
></script>`;

const script = `<script defer src="${
Expand Down
7 changes: 6 additions & 1 deletion website/components/OneDollarStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ const oneDollarSnippet = () => {

export const DEFAULT_COLLECTOR_ADDRESS = "https://d.lilstts.com/events";

export const USE_SITE_DOMAIN_FOR_ANALYTICS_SCRIPT =
Deno.env.get("USE_SITE_DOMAIN_FOR_ANALYTICS_SCRIPT") === "true";

function Component({ collectorAddress, staticScriptUrl }: Props) {
const collector = collectorAddress ?? DEFAULT_COLLECTOR_ADDRESS;
const staticScript = staticScriptUrl ?? DEFAULT_ANALYTICS_SCRIPT_URL;
Expand All @@ -101,7 +104,9 @@ function Component({ collectorAddress, staticScriptUrl }: Props) {
data-autocollect="false"
data-hash-routing="true"
data-url={collector}
src={`/live/invoke/website/loaders/analyticsScript.ts?url=${staticScript}`}
src={USE_SITE_DOMAIN_FOR_ANALYTICS_SCRIPT
? `/live/invoke/website/loaders/analyticsScript.ts?url=${staticScript}`
: staticScript}
Comment on lines +107 to +109
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

URL-encode staticScript when proxying through /live/invoke.
Unencoded query values can break when the URL includes & or #, leading to failed script loads.

✅ Suggested fix
-        src={USE_SITE_DOMAIN_FOR_ANALYTICS_SCRIPT
-          ? `/live/invoke/website/loaders/analyticsScript.ts?url=${staticScript}`
-          : staticScript}
+        src={USE_SITE_DOMAIN_FOR_ANALYTICS_SCRIPT
+          ? `/live/invoke/website/loaders/analyticsScript.ts?url=${encodeURIComponent(staticScript)}`
+          : staticScript}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
src={USE_SITE_DOMAIN_FOR_ANALYTICS_SCRIPT
? `/live/invoke/website/loaders/analyticsScript.ts?url=${staticScript}`
: staticScript}
src={USE_SITE_DOMAIN_FOR_ANALYTICS_SCRIPT
? `/live/invoke/website/loaders/analyticsScript.ts?url=${encodeURIComponent(staticScript)}`
: staticScript}
🤖 Prompt for AI Agents
In `@website/components/OneDollarStats.tsx` around lines 107 - 109, When building
the proxied analytics URL in the OneDollarStats component, the query value uses
raw staticScript which can break if it contains characters like & or #; update
the src construction that checks USE_SITE_DOMAIN_FOR_ANALYTICS_SCRIPT to pass
encodeURIComponent(staticScript) (referencing the OneDollarStats component, the
staticScript variable and the USE_SITE_DOMAIN_FOR_ANALYTICS_SCRIPT flag) so the
script URL is properly URL-encoded when proxied through /live/invoke.

/>
<script defer src={useScriptAsDataURI(oneDollarSnippet)} />
</Head>
Expand Down
Loading