Tiktok Auth sending client secret on login #1877

Closed
opened 2026-03-13 09:10:11 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @arslan2012 on GitHub (Sep 8, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Just follow the docs

import { betterAuth } from "better-auth"

export const auth = betterAuth({
    socialProviders: {
        tiktok: { 
            clientSecret: process.env.TIKTOK_CLIENT_SECRET as string, 
            clientKey: process.env.TIKTOK_CLIENT_KEY as string, 
        }, 
    },
})
import { createAuthClient } from "better-auth/client"
const authClient =  createAuthClient()

const signIn = async () => {
    const data = await authClient.signIn.social({
        provider: "tiktok"
    })
}

Current vs. Expected behavior

Current behavior
await fetch("https://XXX/api/auth/sign-in/social", {
    "body": "{\"provider\":\"tiktok\"}",
});

returns

{"url":"https://www.tiktok.com/v2/auth/authorize?scope=user.info.profile&response_type=code&client_key=XXX&client_secret=XXXXXXXXXXX&redirect_uri=https%3A%2F%2FXXX%2Fapi%2Fauth%2Fcallback%2Ftiktok&state=XXX","redirect":true}
Expected behavior

client_secret should not be sent over

What version of Better Auth are you using?

1.3.8

System info

{
  "system": {
    "platform": "linux",
    "arch": "x64",
    "version": "#1 SMP PREEMPT_DYNAMIC Fri, 15 Aug 2025 16:04:43 +0000",
    "release": "6.16.1-arch1-1",
    "cpuCount": 16,
    "cpuModel": "AMD Ryzen 7 5800X 8-Core Processor",
    "totalMemory": "31.26 GB",
    "freeMemory": "19.28 GB"
  },
  "node": {
    "version": "v22.15.1",
    "env": "development"
  },
  "packageManager": {
    "name": "pnpm",
    "version": "10.14.0"
  },
  "frameworks": [
    {
      "name": "react",
      "version": "^19.1.1"
    }
  ],
  "databases": [
    {
      "name": "@prisma/client",
      "version": "^6.13.0"
    }
  ],
  "betterAuth": {
    "version": "Unknown",
    "config": {
      "emailAndPassword": {
        "enabled": false
      },
      "socialProviders": {
        "tiktok": {
          "clientId": "[REDACTED]",
          "clientSecret": "[REDACTED]",
          "clientKey": "sbaw3esl4woq39irvq"
        }
      }
    }
  }
}

Which area(s) are affected? (Select all that apply)

Client

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  database: prismaAdapter(db, {
    provider: 'mysql',
  }),
  emailAndPassword: {
    enabled: false,
  },
  socialProviders: {
    tiktok: {
      // @ts-expect-error TikTok does not use clientId
      clientId: process.env.TIKTOK_CLIENT_ID as string,
      clientSecret: process.env.TIKTOK_CLIENT_SECRET as string,
      clientKey: process.env.TIKTOK_CLIENT_KEY as string,
    },
  },
});

Additional context

No response

Originally created by @arslan2012 on GitHub (Sep 8, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Just follow the docs ```typescript:auth.ts import { betterAuth } from "better-auth" export const auth = betterAuth({ socialProviders: { tiktok: { clientSecret: process.env.TIKTOK_CLIENT_SECRET as string, clientKey: process.env.TIKTOK_CLIENT_KEY as string, }, }, }) ``` ```typescript:auth-client.ts import { createAuthClient } from "better-auth/client" const authClient = createAuthClient() const signIn = async () => { const data = await authClient.signIn.social({ provider: "tiktok" }) } ``` ### Current vs. Expected behavior ##### Current behavior ```js await fetch("https://XXX/api/auth/sign-in/social", { "body": "{\"provider\":\"tiktok\"}", }); ``` returns ```json {"url":"https://www.tiktok.com/v2/auth/authorize?scope=user.info.profile&response_type=code&client_key=XXX&client_secret=XXXXXXXXXXX&redirect_uri=https%3A%2F%2FXXX%2Fapi%2Fauth%2Fcallback%2Ftiktok&state=XXX","redirect":true} ``` ##### Expected behavior client_secret should not be sent over ### What version of Better Auth are you using? 1.3.8 ### System info ```bash { "system": { "platform": "linux", "arch": "x64", "version": "#1 SMP PREEMPT_DYNAMIC Fri, 15 Aug 2025 16:04:43 +0000", "release": "6.16.1-arch1-1", "cpuCount": 16, "cpuModel": "AMD Ryzen 7 5800X 8-Core Processor", "totalMemory": "31.26 GB", "freeMemory": "19.28 GB" }, "node": { "version": "v22.15.1", "env": "development" }, "packageManager": { "name": "pnpm", "version": "10.14.0" }, "frameworks": [ { "name": "react", "version": "^19.1.1" } ], "databases": [ { "name": "@prisma/client", "version": "^6.13.0" } ], "betterAuth": { "version": "Unknown", "config": { "emailAndPassword": { "enabled": false }, "socialProviders": { "tiktok": { "clientId": "[REDACTED]", "clientSecret": "[REDACTED]", "clientKey": "sbaw3esl4woq39irvq" } } } } } ``` ### Which area(s) are affected? (Select all that apply) Client ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ database: prismaAdapter(db, { provider: 'mysql', }), emailAndPassword: { enabled: false, }, socialProviders: { tiktok: { // @ts-expect-error TikTok does not use clientId clientId: process.env.TIKTOK_CLIENT_ID as string, clientSecret: process.env.TIKTOK_CLIENT_SECRET as string, clientKey: process.env.TIKTOK_CLIENT_KEY as string, }, }, }); ``` ### Additional context _No response_
GiteaMirror added the social-providersecurity labels 2026-03-13 09:10:11 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Sep 8, 2025):

This is a critical security bug: the TikTok provider in Better Auth is including client_secret in the authorization URL sent to the client, which should never happen in any OAuth flow. The client_secret must remain server-side and only be used when exchanging the authorization code for tokens. Exposing it in the URL allows anyone with access to the browser or network traffic to compromise your TikTok app credentials, which can lead to account takeover or abuse reference.

This is not intentional and is almost certainly a bug in the provider implementation. There is currently no documented workaround or override mechanism. Until this is fixed upstream, you should avoid using the TikTok provider in production, as it exposes your app’s secrets to end users and attackers.

If you need a temporary workaround, you could fork the package and remove client_secret from the authorization URL construction in packages/better-auth/src/social-providers/tiktok.ts, but this requires maintaining your own patched version.

Keep an eye on the repository for a fix, as this is a high-priority security issue.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

@dosubot[bot] commented on GitHub (Sep 8, 2025): <!-- Answer --> This is a critical security bug: the TikTok provider in Better Auth is including client_secret in the authorization URL sent to the client, which should never happen in any OAuth flow. The client_secret must remain server-side and only be used when exchanging the authorization code for tokens. Exposing it in the URL allows anyone with access to the browser or network traffic to compromise your TikTok app credentials, which can lead to account takeover or abuse [reference](https://github.com/better-auth/better-auth/blob/a7eaa049e448464ad8501f46136048091a072f43/packages/better-auth/src/social-providers/tiktok.ts). This is not intentional and is almost certainly a bug in the provider implementation. There is currently no documented workaround or override mechanism. Until this is fixed upstream, you should avoid using the TikTok provider in production, as it exposes your app’s secrets to end users and attackers. If you need a temporary workaround, you could fork the package and remove client_secret from the authorization URL construction in `packages/better-auth/src/social-providers/tiktok.ts`, but this requires maintaining your own patched version. Keep an eye on the repository for a fix, as this is a high-priority security issue. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/37c747ae-3265-4047-9705-0b72a926f735?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/37c747ae-3265-4047-9705-0b72a926f735?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/37c747ae-3265-4047-9705-0b72a926f735?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/37c747ae-3265-4047-9705-0b72a926f735?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/37c747ae-3265-4047-9705-0b72a926f735?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/37c747ae-3265-4047-9705-0b72a926f735?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/37c747ae-3265-4047-9705-0b72a926f735?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/4509)
Author
Owner

@arslan2012 commented on GitHub (Sep 8, 2025):

@dosu found the exact line of the issue
e15113737a/packages/better-auth/src/social-providers/tiktok.ts (L139)

This is a critical security bug: the TikTok provider in Better Auth is including client_secret in the authorization URL sent to the client, which should never happen in any OAuth flow. The client_secret must remain server-side and only be used when exchanging the authorization code for tokens. Exposing it in the URL allows anyone with access to the browser or network traffic to compromise your TikTok app credentials, which can lead to account takeover or abuse reference.

This is not intentional and is almost certainly a bug in the provider implementation. There is currently no documented workaround or override mechanism. Until this is fixed upstream, you should avoid using the TikTok provider in production, as it exposes your app’s secrets to end users and attackers.

If you need a temporary workaround, you could fork the package and remove client_secret from the authorization URL construction in packages/better-auth/src/social-providers/tiktok.ts, but this requires maintaining your own patched version.

Keep an eye on the repository for a fix, as this is a high-priority security issue.

To reply, just mention @dosu.

How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other Chat with Dosu Join Discord Share on X

@arslan2012 commented on GitHub (Sep 8, 2025): @dosu found the exact line of the issue https://github.com/better-auth/better-auth/blob/e15113737a5e7b524c188fe07305fc8f310464ce/packages/better-auth/src/social-providers/tiktok.ts#L139 > This is a critical security bug: the TikTok provider in Better Auth is including client_secret in the authorization URL sent to the client, which should never happen in any OAuth flow. The client_secret must remain server-side and only be used when exchanging the authorization code for tokens. Exposing it in the URL allows anyone with access to the browser or network traffic to compromise your TikTok app credentials, which can lead to account takeover or abuse [reference](https://github.com/better-auth/better-auth/blob/a7eaa049e448464ad8501f46136048091a072f43/packages/better-auth/src/social-providers/tiktok.ts). > > This is not intentional and is almost certainly a bug in the provider implementation. There is currently no documented workaround or override mechanism. Until this is fixed upstream, you should avoid using the TikTok provider in production, as it exposes your app’s secrets to end users and attackers. > > If you need a temporary workaround, you could fork the package and remove client_secret from the authorization URL construction in `packages/better-auth/src/social-providers/tiktok.ts`, but this requires maintaining your own patched version. > > Keep an eye on the repository for a fix, as this is a high-priority security issue. > > _To reply, just mention [@dosu](https://go.dosu.dev/dosubot)._ > > How did I do? [Good](https://app.dosu.dev/response-feedback/37c747ae-3265-4047-9705-0b72a926f735?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/37c747ae-3265-4047-9705-0b72a926f735?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/37c747ae-3265-4047-9705-0b72a926f735?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/37c747ae-3265-4047-9705-0b72a926f735?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/37c747ae-3265-4047-9705-0b72a926f735?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/37c747ae-3265-4047-9705-0b72a926f735?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/37c747ae-3265-4047-9705-0b72a926f735?feedback_type=other) [![Chat with Dosu](https://camo.githubusercontent.com/d9ffebb979729c9ef0fc4e3090dbae5b17cabbfec8afe378ada6b81913d6ad8a/68747470733a2f2f646f73752e6465762f646f73752d636861742d62616467652e737667)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github) [![Join Discord](https://camo.githubusercontent.com/d562c2df5e4567ea41d37f1d91a4da0839d8341037045b103b2da268998de17f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6a6f696e2d3538363546323f6c6f676f3d646973636f7264266c6f676f436f6c6f723d7768697465266c6162656c3d)](https://go.dosu.dev/discord-bot) [![Share on X](https://camo.githubusercontent.com/4649f705e2396d6f328dbc8e800a0509c9c17b3b20253b36706c393df124b93d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f582d73686172652d626c61636b)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/4509)
Author
Owner

@dosubot[bot] commented on GitHub (Sep 8, 2025):

You nailed the root cause: the TikTok provider in Better Auth is still including client_secret in the authorization URL sent to the client, which is a critical security vulnerability. This secret should only ever be used server-side during token exchange, never exposed to browsers or users. Recent PRs have cleaned up type definitions and fixed unrelated bugs, but none have addressed this issue—the bug remains present in the latest code as of September 2025 (source).

There’s no official workaround or config to prevent this. The only safe options right now are to avoid using the TikTok provider in production, or fork and patch the code to remove client_secret from the authorization URL construction yourself.

If you need help with the patch, let me know!

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

@dosubot[bot] commented on GitHub (Sep 8, 2025): <!-- Answer --> You nailed the root cause: the TikTok provider in Better Auth is still including `client_secret` in the authorization URL sent to the client, which is a critical security vulnerability. This secret should only ever be used server-side during token exchange, never exposed to browsers or users. Recent PRs have cleaned up type definitions and fixed unrelated bugs, but none have addressed this issue—the bug remains present in the latest code as of September 2025 ([source](https://github.com/better-auth/better-auth/blob/a7eaa049e448464ad8501f46136048091a072f43/packages/better-auth/src/social-providers/tiktok.ts)). There’s no official workaround or config to prevent this. The only safe options right now are to avoid using the TikTok provider in production, or fork and patch the code to remove `client_secret` from the authorization URL construction yourself. If you need help with the patch, let me know! <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/fa20ba5b-b89f-49fe-9cd5-900a81a15a70?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/fa20ba5b-b89f-49fe-9cd5-900a81a15a70?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/fa20ba5b-b89f-49fe-9cd5-900a81a15a70?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/fa20ba5b-b89f-49fe-9cd5-900a81a15a70?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/fa20ba5b-b89f-49fe-9cd5-900a81a15a70?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/fa20ba5b-b89f-49fe-9cd5-900a81a15a70?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/fa20ba5b-b89f-49fe-9cd5-900a81a15a70?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/4509)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1877