Compare commits

...
Author SHA1 Message Date
Derek Ross 47f9edacfd fix: escape HTML in receipt print template to prevent injection 2026-04-12 12:58:57 -04:00
Derek Ross c229f40da8 feat: add Print Receipt button to completed transactions
Add a 'Print Receipt' option for completed credit purchase transactions
in the AI provider config dialog. Clicking it opens a print-friendly
receipt with Soapbox Technology, LLC business details (soapbox.pub,
[email protected]) in a standard receipt layout showing payment ID,
date, method, credits, processing fee, and total charged.

Follows the existing window.open() print pattern used by gift card QR
code printing. Adds i18n translations for all 6 supported languages.
2026-04-10 12:05:50 -04:00
Alex Gleason c285dbcd05 Merge branch 'fix/app-window-not-showing-on-mobile' into 'main'
fix: render AppDialog on mobile project view

See merge request soapbox-pub/shakespeare!108
2026-04-06 14:43:27 +00:00
Dmitriy E b80205a942 fix: render AppDialog on mobile project view 2026-04-06 15:13:12 +03:00
Alex Gleason 50f85f232d release: v9.11.2 2026-04-06 00:58:48 -05:00
Alex Gleason c5605c9be8 Derive private iframe.diy subdomains with HMAC-SHA256
The project ID used for the preview iframe subdomain is AI-generated
from user input. Using it directly as the iframe.diy subdomain lets
a crafted project name produce a subdomain that collides with another
project's origin, gaining access to its localStorage/IndexedDB.

Introduce a persistent random seed in localStorage (shakespeare:seed)
and derive the subdomain as base36(HMAC-SHA256(seed, prefix|identifier)).
The prefix ("preview") domain-separates different use-cases.
The subdomain is stable per device+project but unpredictable to
third parties.
2026-04-06 00:46:01 -05:00
14 changed files with 411 additions and 32 deletions

No files matched your search

+5
View File
@@ -1,5 +1,10 @@
# Changelog
## [9.11.2] - 2026-04-06
### Fixed
- Derive private preview subdomains with HMAC to prevent cross-project origin collisions on iframe.diy
## [9.11.1] - 2026-04-05
### Changed
+27 -2
View File
@@ -1,12 +1,12 @@
{
"name": "shakespeare.diy",
"version": "9.11.0",
"version": "9.11.2",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "shakespeare.diy",
"version": "9.11.0",
"version": "9.11.2",
"license": "AGPL-3.0-or-later",
"dependencies": {
"@capacitor/app": "^8.1.0",
@@ -5001,6 +5001,7 @@
"cpu": [
"arm"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -5014,6 +5015,7 @@
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -5027,6 +5029,7 @@
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -5040,6 +5043,7 @@
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -5053,6 +5057,7 @@
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -5066,6 +5071,7 @@
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -5079,6 +5085,7 @@
"cpu": [
"arm"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -5092,6 +5099,7 @@
"cpu": [
"arm"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -5105,6 +5113,7 @@
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -5118,6 +5127,7 @@
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -5131,6 +5141,7 @@
"cpu": [
"loong64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -5144,6 +5155,7 @@
"cpu": [
"loong64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -5157,6 +5169,7 @@
"cpu": [
"ppc64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -5170,6 +5183,7 @@
"cpu": [
"ppc64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -5183,6 +5197,7 @@
"cpu": [
"riscv64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -5196,6 +5211,7 @@
"cpu": [
"riscv64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -5209,6 +5225,7 @@
"cpu": [
"s390x"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -5222,6 +5239,7 @@
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -5235,6 +5253,7 @@
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -5248,6 +5267,7 @@
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -5261,6 +5281,7 @@
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -5274,6 +5295,7 @@
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -5287,6 +5309,7 @@
"cpu": [
"ia32"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -5300,6 +5323,7 @@
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -5313,6 +5337,7 @@
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
+1 -1
View File
@@ -3,7 +3,7 @@
"description": "Build custom apps with AI assistance using Shakespeare, an open-source development environment",
"homepage": "https://shakespeare.diy",
"license": "AGPL-3.0-or-later",
"version": "9.11.1",
"version": "9.11.2",
"type": "module",
"author": {
"name": "shakespeare.diy",
+5
View File
@@ -1,5 +1,10 @@
# Changelog
## [9.11.2] - 2026-04-06
### Fixed
- Derive private preview subdomains with HMAC to prevent cross-project origin collisions on iframe.diy
## [9.11.1] - 2026-04-05
### Changed
+236
View File
@@ -895,6 +895,231 @@ export function AIProviderConfigDialog({
}
};
const escapeHtml = (str: string): string =>
str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;');
const handlePrintReceipt = (payment: Payment) => {
const receiptDate = new Date((payment.completed_at ?? payment.created_at) * 1000);
const formattedDate = new Intl.DateTimeFormat('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric',
}).format(receiptDate);
const formattedTime = new Intl.DateTimeFormat('en-US', {
hour: '2-digit',
minute: '2-digit',
}).format(receiptDate);
const paymentMethodDisplay = payment.method === 'stripe' ? t('creditCard') : t('lightning');
const statusDisplay = payment.status.charAt(0).toUpperCase() + payment.status.slice(1);
const printWindow = window.open('', '_blank');
if (!printWindow) {
toast({
title: t('printFailed'),
description: t('failedToOpenPrintWindow'),
variant: 'destructive',
});
return;
}
const printHTML = `
<!DOCTYPE html>
<html>
<head>
<title>${t('receipt')} - ${escapeHtml(payment.id)}</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
padding: 40px 20px;
background: white;
color: #000;
}
.receipt {
max-width: 600px;
margin: 0 auto;
border: 1px solid #e0e0e0;
padding: 48px 40px;
}
.header {
text-align: center;
padding-bottom: 28px;
border-bottom: 2px solid #000;
margin-bottom: 28px;
}
.company-name {
font-size: 20px;
font-weight: 700;
letter-spacing: 0.5px;
margin-bottom: 6px;
}
.company-detail {
font-size: 13px;
color: #555;
line-height: 1.6;
}
.company-detail a {
color: #555;
text-decoration: none;
}
.receipt-title {
text-align: center;
font-size: 14px;
font-weight: 600;
letter-spacing: 2px;
text-transform: uppercase;
color: #333;
margin-bottom: 28px;
}
.details-grid {
display: grid;
grid-template-columns: 140px 1fr;
gap: 8px 16px;
margin-bottom: 28px;
font-size: 14px;
}
.details-grid dt {
color: #666;
font-weight: 500;
}
.details-grid dd {
color: #000;
}
.divider {
border: none;
border-top: 1px solid #e0e0e0;
margin: 0 0 28px 0;
}
.line-items {
margin-bottom: 28px;
}
.line-item {
display: flex;
justify-content: space-between;
padding: 6px 0;
font-size: 14px;
}
.line-item-label {
color: #333;
}
.line-item-value {
font-variant-numeric: tabular-nums;
}
.line-item-total {
border-top: 1px solid #000;
margin-top: 8px;
padding-top: 10px;
font-weight: 700;
font-size: 15px;
}
.footer {
text-align: center;
padding-top: 28px;
border-top: 1px solid #e0e0e0;
}
.footer p {
font-size: 13px;
color: #666;
line-height: 1.6;
}
@media print {
body {
padding: 0;
}
.receipt {
border: none;
padding: 0;
max-width: 100%;
}
}
</style>
</head>
<body>
<div class="receipt">
<div class="header">
<div class="company-name">Soapbox Technology, LLC</div>
<div class="company-detail">
<a href="https://soapbox.pub">soapbox.pub</a><br />
[email protected]
</div>
</div>
<div class="receipt-title">${t('receipt')}</div>
<dl class="details-grid">
<dt>${t('receiptNumber')}</dt>
<dd>${escapeHtml(payment.id)}</dd>
<dt>${t('date')}</dt>
<dd>${formattedDate} ${formattedTime}</dd>
<dt>${t('status')}</dt>
<dd>${escapeHtml(statusDisplay)}</dd>
<dt>${t('paymentMethodLabel')}</dt>
<dd>${paymentMethodDisplay}</dd>
${payment.description ? `<dt>${t('description')}</dt><dd>${escapeHtml(payment.description)}</dd>` : ''}
</dl>
<hr class="divider" />
<div class="line-items">
<div class="line-item">
<span class="line-item-label">${t('credits')}</span>
<span class="line-item-value">${formatCurrency(payment.amount)}</span>
</div>
${payment.fee > 0 ? `
<div class="line-item">
<span class="line-item-label">${t('processingFee')}</span>
<span class="line-item-value">${formatCurrency(payment.fee)}</span>
</div>
` : ''}
<div class="line-item line-item-total">
<span class="line-item-label">${t('totalCharged')}</span>
<span class="line-item-value">${formatCurrency(payment.total)}</span>
</div>
</div>
<div class="footer">
<p>${t('thankYouForPurchase')}</p>
</div>
</div>
</body>
</html>
`;
printWindow.document.write(printHTML);
printWindow.document.close();
printWindow.onload = () => {
setTimeout(() => {
printWindow.print();
}, 250);
};
};
const handleDownloadCSV = () => {
if (!giftcards || giftcards.length === 0) return;
@@ -1307,6 +1532,17 @@ export function AIProviderConfigDialog({
)}
</div>
)}
{payment.status === 'completed' && (
<Button
variant="ghost"
size="sm"
onClick={() => handlePrintReceipt(payment)}
className="h-6 px-2 text-xs"
>
<Printer className="h-3 w-3 mr-1" />
{t('printReceipt')}
</Button>
)}
</div>
</div>
))}
+24 -23
View File
@@ -1,5 +1,5 @@
import { encodeBase64 } from '@std/encoding/base64';
import { useState, useEffect, useCallback, useRef } from 'react';
import { useState, useEffect, useCallback, useRef, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { useProjectsManager } from '@/hooks/useProjectsManager';
import { useFS } from '@/hooks/useFS';
@@ -25,6 +25,7 @@ import { Terminal as TerminalComponent } from '@/components/Terminal';
import { useSearchParams } from 'react-router-dom';
import { useAppContext } from '@/hooks/useAppContext';
import { isMediaFile } from '@/lib/fileUtils';
import { deriveIframeSubdomain } from '@/lib/iframeSubdomain';
import { getPreviewInjectedScript } from '@/lib/previewInjectedScript';
interface PreviewPaneProps {
@@ -68,6 +69,13 @@ export function PreviewPane({ projectId, activeTab, onToggleView, isPreviewable
const { t } = useTranslation();
const { config } = useAppContext();
const { previewDomain } = config;
// Derive a private, stable subdomain from a device-local seed + the project ID.
// This prevents malicious project names from colliding with another project's
// origin on iframe.diy, protecting localStorage/IndexedDB isolation.
const previewSubdomain = useMemo(() => deriveIframeSubdomain('preview', projectId), [projectId]);
const previewOrigin = useMemo(() => `https://${previewSubdomain}.${previewDomain}`, [previewSubdomain, previewDomain]);
const [selectedFile, setSelectedFile] = useState<string | null>(null);
const [fileContent, setFileContent] = useState<string>('');
const [isLoading, setIsLoading] = useState(false);
@@ -183,18 +191,15 @@ export function PreviewPane({ projectId, activeTab, onToggleView, isPreviewable
const sendResponse = useCallback((message: JSONRPCResponse) => {
if (iframeRef.current?.contentWindow) {
const targetOrigin = `https://${projectId}.${previewDomain}`;
iframeRef.current.contentWindow.postMessage(message, targetOrigin);
iframeRef.current.contentWindow.postMessage(message, previewOrigin);
}
}, [projectId, previewDomain]);
}, [previewOrigin]);
const sendError = useCallback((message: JSONRPCResponse) => {
if (iframeRef.current?.contentWindow) {
const targetOrigin = `https://${projectId}.${previewDomain}`;
iframeRef.current.contentWindow.postMessage(message, targetOrigin);
iframeRef.current.contentWindow.postMessage(message, previewOrigin);
}
}, [projectId, previewDomain]);
}, [previewOrigin]);
const handleConsoleMessage = useCallback((message: {
jsonrpc: '2.0';
@@ -256,10 +261,9 @@ export function PreviewPane({ projectId, activeTab, onToggleView, isPreviewable
method,
params: params || {},
};
const targetOrigin = `https://${projectId}.${previewDomain}`;
iframeRef.current.contentWindow.postMessage(message, targetOrigin);
iframeRef.current.contentWindow.postMessage(message, previewOrigin);
}
}, [projectId, previewDomain]);
}, [previewOrigin]);
const sendNavigationCommand = useCallback((method: string, params?: Record<string, unknown>) => {
if (iframeRef.current?.contentWindow) {
@@ -269,10 +273,9 @@ export function PreviewPane({ projectId, activeTab, onToggleView, isPreviewable
params: params || {},
id: Date.now()
};
const targetOrigin = `https://${projectId}.${previewDomain}`;
iframeRef.current.contentWindow.postMessage(message, targetOrigin);
iframeRef.current.contentWindow.postMessage(message, previewOrigin);
}
}, [projectId, previewDomain]);
}, [previewOrigin]);
const navigateIframe = useCallback((url: string) => {
// Send semantic path directly (e.g., "/about", "/contact")
@@ -307,16 +310,15 @@ export function PreviewPane({ projectId, activeTab, onToggleView, isPreviewable
try {
// Parse the URL and validate origin
const url = new URL(fetchRequest.url);
const expectedOrigin = `https://${projectId}.${previewDomain}`;
if (url.origin !== expectedOrigin) {
console.log(`Invalid origin: ${url.origin}, expected: ${expectedOrigin}`);
if (url.origin !== previewOrigin) {
console.log(`Invalid origin: ${url.origin}, expected: ${previewOrigin}`);
sendError({
jsonrpc: '2.0',
error: {
code: -32003,
message: 'Invalid URL - origin mismatch',
data: { url: fetchRequest.url, expectedOrigin }
data: { url: fetchRequest.url, expectedOrigin: previewOrigin }
},
id
});
@@ -446,14 +448,13 @@ export function PreviewPane({ projectId, activeTab, onToggleView, isPreviewable
id
});
}
}, [projectId, projectsManager, sendResponse, sendError, previewDomain, injectScript]);
}, [projectId, projectsManager, sendResponse, sendError, previewOrigin, injectScript]);
// Setup messaging protocol for iframe communication
useEffect(() => {
const handleMessage = (event: MessageEvent) => {
// Verify origin for security
const expectedOrigin = `https://${projectId}.${previewDomain}`;
if (event.origin !== expectedOrigin) {
if (event.origin !== previewOrigin) {
return;
}
@@ -477,7 +478,7 @@ export function PreviewPane({ projectId, activeTab, onToggleView, isPreviewable
window.addEventListener('message', handleMessage);
return () => window.removeEventListener('message', handleMessage);
}, [handleFetch, handleConsoleMessage, handleUpdateNavigationState, sendNotification, projectId, previewDomain]);
}, [handleFetch, handleConsoleMessage, handleUpdateNavigationState, sendNotification, previewOrigin]);
useEffect(() => {
if (selectedFile) {
@@ -710,7 +711,7 @@ export function PreviewPane({ projectId, activeTab, onToggleView, isPreviewable
<iframe
key={projectId}
ref={iframeRef}
src={`https://${projectId}.${previewDomain}/`}
src={`${previewOrigin}/`}
className="w-full h-full border-0"
title="Project Preview"
/>
+54
View File
@@ -0,0 +1,54 @@
import { hmac } from '@noble/hashes/hmac';
import { sha256 } from '@noble/hashes/sha256';
import { bytesToHex } from '@noble/hashes/utils';
const SEED_STORAGE_KEY = 'shakespeare:seed';
/**
* Encode a hex string as a zero-padded 50-character base36 string.
* Replicates the encoding used for nsite subdomains.
*/
function hexToBase36(hex: string): string {
let n = 0n;
for (let i = 0; i < hex.length; i++) {
n = n * 16n + BigInt(parseInt(hex[i], 16));
}
return n.toString(36).padStart(50, '0');
}
/**
* Get or create a device-local random seed persisted in localStorage.
* This is a general-purpose secret used to derive private identifiers
* (e.g. iframe.diy subdomains) that must not be predictable by third parties.
*/
function getSeed(): string {
const stored = localStorage.getItem(SEED_STORAGE_KEY);
if (stored) return stored;
const seed = crypto.randomUUID();
localStorage.setItem(SEED_STORAGE_KEY, seed);
return seed;
}
/**
* Derive a stable, private subdomain label for an iframe.diy iframe.
*
* Uses HMAC-SHA256 with the device-local seed as the key and
* `prefix|identifier` as the message. Because the seed is secret to
* this device, a third party cannot predict or collide with another
* app's subdomain, preventing cross-app localStorage/IndexedDB access
* on iframe.diy.
*
* The `prefix` acts as a domain separator so that different use-cases
* (e.g. "preview", "sandbox") produce distinct subdomains even for the
* same identifier.
*
* The result is a 50-character base36 string (256 bits of entropy) that
* fits within the 63-character subdomain label limit.
*/
export function deriveIframeSubdomain(prefix: string, identifier: string): string {
const seed = getSeed();
const enc = new TextEncoder();
const mac = hmac(sha256, enc.encode(seed), enc.encode(`${prefix}|${identifier}`));
return hexToBase36(bytesToHex(mac));
}
+9 -1
View File
@@ -573,5 +573,13 @@
"failedToDuplicateProject": "Failed to duplicate project",
"newProjectName": "New Project Name",
"duplicateProjectDescription": "Create a copy of this project with a new name",
"resume": "Resume"
"resume": "Resume",
"printReceipt": "Print Receipt",
"receipt": "Receipt",
"receiptNumber": "Receipt #",
"date": "Date",
"status": "Status",
"paymentMethodLabel": "Payment Method",
"totalCharged": "Total Charged",
"thankYouForPurchase": "Thank you for your purchase!"
}
+9 -1
View File
@@ -487,5 +487,13 @@
"failedToDuplicateProject": "An kasa kwafin aikin",
"newProjectName": "Sunan Sabon Aikin",
"duplicateProjectDescription": "Ƙirƙiri kwafin wannan aikin da sabon suna",
"resume": "Ci gaba"
"resume": "Ci gaba",
"printReceipt": "Buga Rasidi",
"receipt": "Rasidi",
"receiptNumber": "Rasidi #",
"date": "Kwanan wata",
"status": "Matsayi",
"paymentMethodLabel": "Hanyar Biyan Kuɗi",
"totalCharged": "Jimlar da aka Caji",
"thankYouForPurchase": "Mun gode da sayan ku!"
}
+9 -1
View File
@@ -484,5 +484,13 @@
"failedToDuplicateProject": "Ọ dara ada imepụta ọrụ",
"newProjectName": "Aha Ọrụ Ọhụrụ",
"duplicateProjectDescription": "Mepụta oyiri nke ọrụ a na aha ọhụrụ",
"resume": "Gaa n'ihu"
"resume": "Gaa n'ihu",
"printReceipt": "Bipụta Risịịtị",
"receipt": "Risịịtị",
"receiptNumber": "Risịịtị #",
"date": "Ụbọchị",
"status": "Ọnọdụ",
"paymentMethodLabel": "Ụzọ Ịkwụ Ụgwọ",
"totalCharged": "Nchịkọta Ego a Gbara",
"thankYouForPurchase": "Daalụ maka ịzụta gị!"
}
+9 -1
View File
@@ -496,5 +496,13 @@
"failedToDuplicateProject": "Falha ao duplicar projeto",
"newProjectName": "Nome do Novo Projeto",
"duplicateProjectDescription": "Criar uma cópia deste projeto com um novo nome",
"resume": "Retomar"
"resume": "Retomar",
"printReceipt": "Imprimir Recibo",
"receipt": "Recibo",
"receiptNumber": "Recibo Nº",
"date": "Data",
"status": "Status",
"paymentMethodLabel": "Método de Pagamento",
"totalCharged": "Total Cobrado",
"thankYouForPurchase": "Obrigado pela sua compra!"
}
+9 -1
View File
@@ -484,5 +484,13 @@
"failedToDuplicateProject": "O kuna lati ṣe ẹda iṣẹ akanṣe",
"newProjectName": "Orukọ Iṣẹ Akanṣe Tuntun",
"duplicateProjectDescription": "Ṣẹda ẹda ti iṣẹ akanṣe yii pẹlu orukọ tuntun",
"resume": "Tẹsiwaju"
"resume": "Tẹsiwaju",
"printReceipt": "Tẹ Ìwé Ẹ̀rí",
"receipt": "Ìwé Ẹ̀rí",
"receiptNumber": "Ìwé Ẹ̀rí #",
"date": "Ọjọ́",
"status": "Ipò",
"paymentMethodLabel": "Ọ̀nà Ìsanwó",
"totalCharged": "Àpapọ̀ tí a gba",
"thankYouForPurchase": "A dúpẹ́ fún rírà rẹ!"
}
+9 -1
View File
@@ -496,5 +496,13 @@
"failedToDuplicateProject": "复制项目失败",
"newProjectName": "新项目名称",
"duplicateProjectDescription": "使用新名称创建此项目的副本",
"resume": "继续"
"resume": "继续",
"printReceipt": "打印收据",
"receipt": "收据",
"receiptNumber": "收据编号",
"date": "日期",
"status": "状态",
"paymentMethodLabel": "支付方式",
"totalCharged": "总收费",
"thankYouForPurchase": "感谢您的购买!"
}
+5
View File
@@ -389,6 +389,11 @@ export function ProjectView() {
open={deleteDialogOpen}
onOpenChange={setDeleteDialogOpen}
/>
<AppDialog
projectId={project.id}
open={appDialogOpen}
onOpenChange={setAppDialogOpen}
/>
</>
)}
</div>