Skip to content
Open
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
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
## Remnawave Subscription Page

### INCY encrypted subscription links

This fork adds support for INCY encrypted deep links (`incy://crypt1/...`), similar to
the existing `HAPP_CRYPT4_LINK` placeholder for Happ.

**Setup:**
1. Install the dependency in `frontend`: `npm install @densds/link-encoder`
2. In your app-config JSON (Subscription Page settings), use the placeholder
`{{INCY_CRYPT1_LINK}}` as the `link` value for an INCY button.

Encryption happens entirely client-side, the same way `HAPP_CRYPT3_LINK` /
`HAPP_CRYPT4_LINK` already work: the subscription URL is built from the already-loaded,
already-validated subscription info (`constructSubscriptionUrl`), never from
unvalidated user input, so there's no backend endpoint involved and nothing for it to
expose.

Learn more about Remnawave [here](https://docs.rw/).

# Contributors
Expand Down
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@
"typescript": "~5.9.3",
"webpack-node-externals": "^3.0.0"
}
}
}
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@ services:
build:
context: .
dockerfile: Dockerfile
container_name: remnawave-subscription-page
hostname: remnawave-subscription-page
restart: always
env_file:
- .env
ports:
- '127.0.0.1:3010:3010'
networks:
- remnawave-network

networks:
remnawave-network:
driver: bridge
external: true
21 changes: 21 additions & 0 deletions frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@
<html lang="en" dir="ltr">
<head>
<meta charset="UTF-8" />

<script src="https://telegram.org/js/telegram-web-app.js"></script>
<script>
(function () {
// Telegram Desktop's embedded WebView2 blocks navigation to custom
// schemes (happ://, incy://, ...) even on a fully synchronous click.
// Bounce out to the system browser as early as possible — before the
// user can even see the Happ/Incy buttons — where deep links work
// normally. Mobile clients (android/ios) are left untouched: their
// WebViews already handle these schemes fine via a plain
// window.open() (see navigateToUrl in installation-guide.connector).
var tg = window.Telegram && window.Telegram.WebApp
if (tg && tg.platform === 'tdesktop') {
tg.openLink(window.location.href)
if (typeof tg.close === 'function') {
tg.close()
}
}
})()
</script>

<meta name="robots" content="noindex, nofollow" />
<meta name="color-scheme" content="dark only" />
<meta name="theme-color" content="#161B23" />
Expand Down
10 changes: 10 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
},
"dependencies": {
"@gfazioli/mantine-spinner": "4.1.8",
"@densds/link-encoder": "^2.0.0",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 security Unverified npm package @densds/link-encoder from PR author

@densds/link-encoder is published under the same namespace as this PR's author (densds) and returns no results in standard npm-registry searches. Unlike the existing @kastov/cryptohapp dependency (which is independently verifiable), this package has no visible GitHub repository, changelog, or community adoption. Since it handles subscription URL encryption on the client side — processing real user subscription URLs — it sits in a sensitive position. Before merging, the project maintainers should verify the package's source code and confirm its npm publish provenance matches the author's identity.

"@kastov/cryptohapp": "^1.1.2",
"@mantine/core": "9.4.1",
"@mantine/hooks": "9.4.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import {
UnstyledButton
} from '@mantine/core'
import { notifications } from '@mantine/notifications'
import { encryptLink } from '@densds/link-encoder'
import { useClipboard } from '@mantine/hooks'
import { useState } from 'react'
import { useEffect, useMemo, useState } from 'react'
import clsx from 'clsx'

import { constructSubscriptionUrl } from '@shared/utils/construct-subscription-url'
Expand All @@ -32,6 +33,16 @@ import classes from './installation-guide.module.css'

export type TBlockVariant = 'accordion' | 'cards' | 'minimal' | 'timeline'

// window.open (not location.href) is what actually hands off custom schemes
// (happ://, incy://, ...) to the OS from inside Telegram's Mini App WebView, same
// as the validated fix in the sibling shopbot project — as long as it's called
// synchronously, with no async gap burning through the click's user-activation
// window. It also keeps regular http(s) subscription links in a new tab instead
// of navigating the page itself away.
const navigateToUrl = (url: string) => {
window.open(url, '_blank')
}

interface IProps {
BlockRenderer: React.ComponentType<IBlockRendererProps>
hasPlatformApps: Record<TSubscriptionPagePlatformKey, boolean>
Expand Down Expand Up @@ -81,10 +92,61 @@ export const InstallationGuideConnector = (props: IProps) => {
subscription.user.shortUuid
)

const hasIncyButton = useMemo(
() =>
Object.values(platforms).some((platformConfig) =>
platformConfig?.apps.some((app) =>
app.blocks.some((block) =>
block.buttons.some((button) => button.link === '{{INCY_CRYPT1_LINK}}')
)
)
),
[platforms]
)

const [incyCryptLink, setIncyCryptLink] = useState<string | undefined>(undefined)
const [incyCryptLoading, setIncyCryptLoading] = useState(() => hasIncyButton)

useEffect(() => {
if (!hasIncyButton) return

let cancelled = false

// name is capped at 128 chars per @densds/link-encoder's encryptLink contract
const name = subscription.user.username.slice(0, 128)

encryptLink(subscriptionUrl, { name })
.then((link) => {
if (!cancelled) setIncyCryptLink(link)
})
.catch(() => {
// incyCryptLink stays undefined; handleButtonClick surfaces
// the "not ready" notification when the user clicks the button
})
.finally(() => {
if (!cancelled) setIncyCryptLoading(false)
})

return () => {
cancelled = true
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [hasIncyButton, subscriptionUrl, subscription.user.username])

const handleButtonClick = (button: TSubscriptionPageButtonConfig) => {
let formattedUrl: string | undefined

if (button.type === 'subscriptionLink' || button.type === 'copyButton') {
if (button.link === '{{INCY_CRYPT1_LINK}}') {
if (!incyCryptLink) {
notifications.show({
title: 'Error',
message: 'INCY link is not ready yet, please try again in a moment',
color: 'red'
})
return
}
formattedUrl = incyCryptLink
} else if (button.type === 'subscriptionLink' || button.type === 'copyButton') {
formattedUrl = TemplateEngine.formatWithMetaInfo(button.link, {
username: subscription.user.username,
subscriptionUrl
Expand All @@ -104,13 +166,17 @@ export const InstallationGuideConnector = (props: IProps) => {
break
}
case 'external': {
window.open(button.link, '_blank')
if (formattedUrl) {
navigateToUrl(formattedUrl)
} else {
window.open(button.link, '_blank')
}
break
}
case 'subscriptionLink': {
if (!formattedUrl) return

window.open(formattedUrl, '_blank')
navigateToUrl(formattedUrl)
break
Comment on lines 176 to 180

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 subscriptionLink now navigates in-place for all subscription buttons

The change from window.open(formattedUrl, '_blank') to window.location.href = formattedUrl applies to every button with type 'subscriptionLink', not just INCY ones. Any subscription-link button that resolves to a regular https:// URL will now silently navigate the current tab away from the subscription page, discarding the loaded session. Only deep-link protocols (e.g. incy://, vpn://) are unaffected because the browser hands them off to the OS without actually navigating. If the intent is to support deep links from a subscriptionLink button, a narrower guard (e.g. checking the resulting URL protocol) would prevent the regression for https links.

}
default:
Expand All @@ -129,6 +195,7 @@ export const InstallationGuideConnector = (props: IProps) => {
{buttons.map((button, index) => (
<Button
key={index}
disabled={button.link === '{{INCY_CRYPT1_LINK}}' && incyCryptLoading}
leftSection={
<span
dangerouslySetInnerHTML={{
Expand All @@ -137,6 +204,7 @@ export const InstallationGuideConnector = (props: IProps) => {
style={{ display: 'flex', alignItems: 'center' }}
/>
}
loading={button.link === '{{INCY_CRYPT1_LINK}}' && incyCryptLoading}
onClick={() => handleButtonClick(button)}
radius="md"
variant={variant}
Expand Down