Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

Add Linux xattr download attribution (#7854)

Ezra Ellette9c7166f188c8
diff --git a/.github/scripts/release-workflows.test.ts b/.github/scripts/release-workflows.test.ts
index f7cdaa931..dabf3ddf7 100644
--- a/.github/scripts/release-workflows.test.ts
+++ b/.github/scripts/release-workflows.test.ts
@@ -2,7 +2,8 @@
// https://screenpipe.com
import { expect, test } from "bun:test";
-import { readFileSync } from "node:fs";
+import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
+import { tmpdir } from "node:os";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
import { dispatchEnterprise, reportEnterprise } from "./enterprise-release.cjs";
@@ -16,6 +17,36 @@ const sha = "01afe5afda5fa75f3e4d733ef9a934b975347f48";
const context = { repo: { owner: "screenpipe", repo: "screenpipe" }, runId: 123, ref: "refs/heads/main" };
const platformJobs = ["resolve-release", "localization", "release-enterprise-windows", "release-enterprise-linux", "release-enterprise-macos"];
+test("Linux carrier preparation preserves recovery of older app revisions", () => {
+ const step = app.jobs["publish-tauri"].steps.find((step: any) => step.name === "Prepare Linux xattr download carrier");
+ const script = step.run.replaceAll("${{ matrix.target }}", "x86_64-unknown-linux-gnu");
+ for (const revision of ["missing", "legacy", "current"]) {
+ const fixture = mkdtempSync(join(tmpdir(), "screenpipe-linux-release-"));
+ try {
+ const bundle = join(fixture, "apps/screenpipe-app-tauri/src-tauri/target/x86_64-unknown-linux-gnu/release/bundle");
+ mkdirSync(join(bundle, "appimage"), { recursive: true });
+ mkdirSync(join(fixture, "scripts"));
+ writeFileSync(join(fixture, "apps/screenpipe-app-tauri/src-tauri/Cargo.toml"),
+ '# screenpipe — AI that knows everything you\'ve seen, said, or heard\n# https://screenpipe.com\nversion = "1.2.3"\n');
+ const image = Buffer.alloc(1024);
+ image.set([0x7f, 0x45, 0x4c, 0x46, 2, 1]);
+ image.set([0x41, 0x49, 2], 8);
+ image[18] = 62;
+ writeFileSync(join(bundle, "appimage/screenpipe_1.2.3_amd64.AppImage"), image);
+ if (revision !== "missing") {
+ writeFileSync(join(fixture, "scripts/package-attribution-carrier.py"), revision === "current"
+ ? readFileSync(join(root, "scripts/package-attribution-carrier.py"))
+ : '# screenpipe — AI that knows everything you\'ve seen, said, or heard\n# https://screenpipe.com\nraise RuntimeError("legacy packager must not be called")\n');
+ }
+ const result = Bun.spawnSync(["bash", "-c", script], { cwd: fixture, stdout: "pipe", stderr: "pipe" });
+ expect(result.exitCode, new TextDecoder().decode(result.stderr)).toBe(0);
+ expect(existsSync(join(bundle, "attribution/screenpipe-attribution.tar"))).toBe(revision === "current");
+ expect(existsSync(join(bundle, "attribution/screenpipe-attribution-linux.json"))).toBe(revision === "current");
+ expect(readFileSync(join(bundle, "appimage/screenpipe_1.2.3_amd64.AppImage"))).toEqual(image);
+ } finally { rmSync(fixture, { recursive: true, force: true }); }
+ }
+});
+
function api(dispatchFails = false) {
const calls: { method: string; args: any }[] = [];
const github = { rest: {
diff --git a/.github/workflows/release-app.yml b/.github/workflows/release-app.yml
index 007649758..dff6247d0 100644
--- a/.github/workflows/release-app.yml
+++ b/.github/workflows/release-app.yml
@@ -1641,6 +1641,35 @@ jobs:
--platform "$PLATFORM" --release "$VERSION"
done
+ - name: Prepare Linux xattr download carrier
+ if: matrix.os_type == 'linux'
+ shell: bash
+ run: |
+ set -euo pipefail
+ # Recovery builds can select app source from before this carrier.
+ # Only prepare metadata when the matching app revision supports it.
+ if [[ ! -f scripts/package-attribution-carrier.py ]] || ! grep -q -- '--linux-xattr' scripts/package-attribution-carrier.py; then
+ echo "Linux app revision predates xattr carriers; retaining ordinary AppImage"
+ exit 0
+ fi
+ BUNDLE_DIR="apps/screenpipe-app-tauri/src-tauri/target/${{ matrix.target }}/release/bundle"
+ VERSION=$(grep '^version = ' apps/screenpipe-app-tauri/src-tauri/Cargo.toml | sed 's/version = "\(.*\)"/\1/')
+ for appimage in "$BUNDLE_DIR"/appimage/*.AppImage; do
+ python3 scripts/package-attribution-carrier.py --artifact "$appimage" \
+ --output "$BUNDLE_DIR/attribution" --platform linux --release "$VERSION" --linux-xattr
+ done
+
+ - name: Upload Linux dry-run artifacts
+ if: matrix.os_type == 'linux' && github.event.inputs.dry_run == 'true'
+ uses: actions/upload-artifact@v4
+ with:
+ name: consumer-linux-${{ matrix.target }}
+ path: |
+ apps/screenpipe-app-tauri/src-tauri/target/${{ matrix.target }}/release/bundle/appimage/*.AppImage
+ apps/screenpipe-app-tauri/src-tauri/target/${{ matrix.target }}/release/bundle/attribution/*
+ if-no-files-found: error
+ compression-level: 0
+
- name: Upload macOS dry-run artifacts
if: matrix.os_type == 'macos' && github.event.inputs.dry_run == 'true'
uses: actions/upload-artifact@v4
@@ -1710,6 +1739,7 @@ jobs:
"${BUNDLE_DIR}"/appimage/*.AppImage \
"${BUNDLE_DIR}"/appimage/*.tar.gz \
"${BUNDLE_DIR}"/appimage/*.sig \
+ "${BUNDLE_DIR}"/attribution/* \
"${BUNDLE_DIR}"/deb/*.deb
# Sentry uploads run AFTER R2 so they don't delay release artifacts
diff --git a/.github/workflows/test-release-workflows.yml b/.github/workflows/test-release-workflows.yml
index fa7e62c38..a4b63de17 100644
--- a/.github/workflows/test-release-workflows.yml
+++ b/.github/workflows/test-release-workflows.yml
@@ -28,6 +28,9 @@ on:
- .github/scripts/setup-release-sccache.sh
- .github/scripts/prepare-mlx-cache.sh
- .github/scripts/finalize-macos-updater.sh
+ - scripts/package-attribution-carrier.py
+ - scripts/test_attribution_carrier.py
+ - infra/release-artifact-uploader/**
push:
branches: [main]
paths:
@@ -51,6 +54,9 @@ on:
- .github/scripts/setup-release-sccache.sh
- .github/scripts/prepare-mlx-cache.sh
- .github/scripts/finalize-macos-updater.sh
+ - scripts/package-attribution-carrier.py
+ - scripts/test_attribution_carrier.py
+ - infra/release-artifact-uploader/**
permissions:
contents: read
@@ -64,6 +70,10 @@ jobs:
with:
bun-version: "1.3.10"
- run: bun test ./.github/scripts/release-workflows.test.ts ./.github/scripts/release-performance.test.ts ./.github/actions/install-windows-frontend-dependencies/prune-dependencies.test.ts
+ - name: Verify Linux xattr carrier with real GNU tar extraction
+ run: python3 -B scripts/test_attribution_carrier.py
+ - name: Verify scoped artifact upload admission
+ run: bun test ./infra/release-artifact-uploader/src/index.test.js
localization-generation:
if: github.event_name == 'workflow_dispatch'
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/acquisition_handoff.rs b/apps/screenpipe-app-tauri/src-tauri/src/acquisition_handoff.rs
index 31cfd59c8..79bca763f 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/acquisition_handoff.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/acquisition_handoff.rs
@@ -181,7 +181,50 @@ fn carrier_from(directory: &std::path::Path) -> Option<String> {
fn carrier() -> Option<String> {
// AppImages execute from a temporary mount; APPIMAGE is the original file.
let path = std::path::PathBuf::from(std::env::var_os("APPIMAGE")?);
- grant_from_filename(path.file_name()?.to_str()?, ".AppImage")
+ linux_carrier_from(&path)
+}
+
+#[cfg(any(target_os = "linux", all(test, target_os = "macos")))]
+fn linux_carrier_from(path: &std::path::Path) -> Option<String> {
+ linux_xattr_grant(path)
+ .or_else(|| grant_from_filename(path.file_name()?.to_str()?, ".AppImage"))
+}
+
+#[cfg(any(target_os = "linux", all(test, target_os = "macos")))]
+fn linux_xattr_grant(path: &std::path::Path) -> Option<String> {
+ use std::{ffi::CString, os::unix::ffi::OsStrExt};
+ let path = CString::new(path.as_os_str().as_bytes()).ok()?;
+ let name = c"user.screenpipe.acquisition-grant";
+ // The protocol carries exactly one canonical UUID (36 ASCII bytes).
+ let mut bytes = [0u8; 36];
+ let read = |buffer: *mut libc::c_void, length: usize| {
+ #[cfg(target_os = "linux")]
+ unsafe { libc::getxattr(path.as_ptr(), name.as_ptr(), buffer, length) }
+ #[cfg(target_os = "macos")]
+ unsafe { libc::getxattr(path.as_ptr(), name.as_ptr(), buffer, length, 0, 0) }
+ };
+ let size = read(bytes.as_mut_ptr().cast(), bytes.len());
+ if size < 0 {
+ let error = std::io::Error::last_os_error();
+ #[cfg(target_os = "linux")]
+ let absent = error.raw_os_error() == Some(libc::ENODATA);
+ #[cfg(target_os = "macos")]
+ let absent = error.raw_os_error() == Some(libc::ENOATTR);
+ if !absent {
+ // On ERANGE the read returns no length; query it without allocating.
+ let actual_bytes = if error.raw_os_error() == Some(libc::ERANGE) {
+ Some(read(std::ptr::null_mut(), 0))
+ } else { None };
+ tracing::warn!(%error, ?actual_bytes, expected_bytes = bytes.len(), "Linux acquisition xattr unreadable; trying filename attribution");
+ }
+ return None;
+ }
+ let grant = std::str::from_utf8(&bytes).ok();
+ if size != bytes.len() as isize || !grant.is_some_and(uuid4) {
+ tracing::warn!(actual_bytes = size, expected_bytes = bytes.len(), "Linux acquisition xattr invalid; trying filename attribution");
+ return None;
+ }
+ grant.map(str::to_owned)
}
// Retirement never waits for the optional credential store. A late credential
@@ -357,6 +400,79 @@ async fn send(client: &reqwest::Client, origin: &reqwest::Url, action: &str, p:
#[cfg(test)]
mod tests {
use super::*;
+ #[cfg(any(target_os = "linux", target_os = "macos"))]
+ fn set_linux_xattr(path: &std::path::Path, value: &[u8]) {
+ use std::{ffi::CString, os::unix::ffi::OsStrExt};
+ let path = CString::new(path.as_os_str().as_bytes()).unwrap();
+ let name = c"user.screenpipe.acquisition-grant";
+ #[cfg(target_os = "linux")]
+ let result = unsafe { libc::setxattr(path.as_ptr(), name.as_ptr(), value.as_ptr().cast(), value.len(), 0) };
+ #[cfg(target_os = "macos")]
+ let result = unsafe { libc::setxattr(path.as_ptr(), name.as_ptr(), value.as_ptr().cast(), value.len(), 0, 0) };
+ assert_eq!(result, 0, "{}", std::io::Error::last_os_error());
+ }
+
+ #[cfg(any(target_os = "linux", target_os = "macos"))]
+ #[test]
+ fn linux_xattr_survives_rename_and_preserves_filename_compatibility() {
+ let dir = tempfile::tempdir().unwrap();
+ let grant = "12345678-1234-4234-8234-123456789012";
+ let path = dir.path().join(format!("screenpipe-{grant}.AppImage"));
+ std::fs::write(&path, b"unchanged AppImage bytes").unwrap();
+ assert_eq!(linux_carrier_from(&path), Some(grant.into()));
+ let xattr_grant = "abcdefab-cdef-4abc-9def-abcdefabcdef";
+ set_linux_xattr(&path, xattr_grant.as_bytes());
+ assert_eq!(linux_carrier_from(&path), Some(xattr_grant.into()));
+ let renamed = dir.path().join("renamed.AppImage");
+ std::fs::rename(&path, &renamed).unwrap();
+ assert_eq!(linux_carrier_from(&renamed), Some(xattr_grant.into()));
+ for invalid in [
+ PLACEHOLDER.as_bytes(), &grant.as_bytes()[..35],
+ b"12345678-1234-4234-8234-123456789012\n",
+ b"12345678-1234-4234-7234-123456789012",
+ b"12345678-1234-4234-8234-12345678901X", &[0xff; 36],
+ ] {
+ set_linux_xattr(&renamed, invalid);
+ assert!(linux_carrier_from(&renamed).is_none());
+ }
+ // A broken attribute does not invalidate older personalized downloads.
+ std::fs::rename(&renamed, &path).unwrap();
+ assert_eq!(linux_carrier_from(&path), Some(grant.into()));
+ assert_eq!(std::fs::read(&path).unwrap(), b"unchanged AppImage bytes");
+ let ordinary = dir.path().join("screenpipe.AppImage");
+ std::fs::write(&ordinary, b"ordinary download").unwrap();
+ assert!(linux_carrier_from(&ordinary).is_none());
+ }
+
+ #[cfg(any(target_os = "linux", target_os = "macos"))]
+ #[tokio::test]
+ async fn linux_xattr_failures_survive_support_collection_and_rotation_without_grants() {
+ let dir = tempfile::tempdir().unwrap();
+ let current = dir.path().join("screenpipe-app.2026-11-02.log");
+ let artifact = dir.path().join("[email protected]");
+ std::fs::write(&artifact, b"AppImage fixture").unwrap();
+ let grant = "12345678-1234-4234-8234-123456789012";
+ let subscriber = tracing_subscriber::fmt().with_ansi(false)
+ .with_writer(std::fs::File::create(&current).unwrap()).finish();
+ tracing::subscriber::with_default(subscriber, || {
+ set_linux_xattr(&artifact, &grant.as_bytes()[..35]);
+ assert!(linux_carrier_from(&artifact).is_none());
+ set_linux_xattr(&artifact, format!("{grant}\n").as_bytes());
+ assert!(linux_carrier_from(&artifact).is_none());
+ });
+ std::fs::rename(&current, dir.path().join("screenpipe-app.2026-11-02.1.log")).unwrap();
+ std::fs::write(&current, b"after rotation\n").unwrap();
+ let report = crate::diagnostic_logs::collect_redacted_from_dirs_at_root(
+ &[dir.path().to_path_buf()], dir.path().to_path_buf()
+ ).await.unwrap();
+ for expected in ["Linux acquisition xattr invalid", "actual_bytes=35", "expected_bytes=36",
+ "Linux acquisition xattr unreadable", "Some(37)", "trying filename attribution"] {
+ assert!(report.contains(expected), "missing {expected}: {report}");
+ }
+ assert!(!report.contains(grant));
+ assert!(!report.contains("[email protected]"));
+ }
+
#[test]
fn portable_filenames_reject_placeholders_and_ambiguous_names() {
let grant = "12345678-1234-4234-8234-123456789012";
diff --git a/docs/macos-acquisition-handoff.md b/docs/macos-acquisition-handoff.md
index 616948dbd..4c48a0f72 100644
--- a/docs/macos-acquisition-handoff.md
+++ b/docs/macos-acquisition-handoff.md
@@ -21,6 +21,10 @@ signed screenpipe-<UUID>.exe -> NSIS validates filename -> installed token
signed screenpipe-<UUID>.AppImage -> APPIMAGE filename -> credential-store proof
-> claim -> authenticated bind
+
+AppImage -> PAX tar with user.screenpipe.acquisition-grant -> Worker personalizes xattr
+ -> extract preserving xattrs -> APPIMAGE xattr -> existing credential-store proof
+ -> claim -> authenticated bind
```
Retries reuse the same request and verifier. Saved proof survives app updates
@@ -79,11 +83,46 @@ in the versioned release filename. The NSIS bootstrap PE machine is not treated
as payload architecture. Filename personalization preserves the signed bytes.
Use `--platform windows` for x86_64 and `--platform windows-arm` for ARM64.
+For Linux xattr downloads, use the same versioned AppImage with `--linux-xattr`:
+
+```sh
+python3 scripts/package-attribution-carrier.py \
+ --artifact /path/to/screenpipe_VERSION_amd64.AppImage --platform linux \
+ --release VERSION --linux-xattr --output /path/to/new-output-directory
+```
+
+This prepares `screenpipe-attribution.tar` and `screenpipe-attribution-linux.json`.
+The schema-3 manifest identifies `carrier: linux-xattr`, platform, release, tar
+size/SHA-256, the placeholder and absolute `grant_offset`, and the enclosed
+AppImage name/size/SHA-256. The archive has one executable `screenpipe.AppImage`
+with PAX `SCHILY.xattr.user.screenpipe.acquisition-grant` metadata. The website
+replaces only the 36-byte opaque UUID in that metadata. AppImage bytes remain
+unchanged. The consumer Linux release job prepares and uploads these versioned
+artifacts alongside the ordinary AppImage; dry runs retain both as CI artifacts.
+
+A browser cannot directly set this custom xattr on a raw HTTP download. Extract
+the personalized tar with an extractor that preserves Linux xattrs; GNU tar
+requires the explicit flag:
+
+```sh
+tar --xattrs -xf screenpipe-attribution.tar
+./screenpipe.AppImage
+```
+
+The app reads the original path from `APPIMAGE`, preferring its xattr to the
+legacy filename grant. Renaming on the same filesystem preserves the xattr.
+Extraction without xattrs or copying to a filesystem that strips them loses
+optional attribution for this archive. Existing personalized raw AppImages
+continue to use their filenames. Missing or malformed carriers do not prevent
+recording; unreadable or invalid attributes report the failure category and
+expected UUID width without logging the grant or local file path. The saved
+proof, consent, account and retirement rules are unchanged.
+
The script never uploads artifacts or changes publication pointers. Production
activation and versioned-artifact publication have not been performed. Human
publication remains required. An ordinary, unpersonalized download installs and
runs normally without optional attribution. Renaming a personalized Windows or
-Linux download before its first install/launch can lose attribution.
+raw Linux download before its first install/launch can lose attribution.
The signature-exempt xattr and ZIP extraction behavior are documented by
[Apple Developer Technical Support](https://developer.apple.com/forums/thread/796303).
@@ -95,5 +134,8 @@ Before enabling website carrier admission, verify actual production artifacts,
app startup, restart, login/logout, trial/purchase, updater recovery, and provider
readback. The macOS test uses an ad-hoc signed fixture; Windows NSIS tests exercise
the real grant macro but mock installer signature/version metadata boundaries;
-Linux uses a synthetic AppImage header. These local tests do not prove the full
+Linux packaging uses a synthetic AppImage header. The Linux carrier regression
+also runs GNU tar with and without xattrs and checks rename and fresh-process
+readback. Native reader tests exercise filesystem attributes, UUID validation,
+rename and filename compatibility on Unix. These tests do not prove the full
production download or signing path.
diff --git a/infra/release-artifact-uploader/src/index.js b/infra/release-artifact-uploader/src/index.js
index eee0f7a38..329d10f85 100644
--- a/infra/release-artifact-uploader/src/index.js
+++ b/infra/release-artifact-uploader/src/index.js
@@ -60,8 +60,11 @@ export function artifactKey(scope, version, target, filename) {
throw new Error("invalid version");
}
if (!TARGETS.has(target)) throw new Error("unsupported target");
- const carrierManifest = scope === "consumer" && target.endsWith("-apple-darwin") &&
- filename === "screenpipe-attribution.json";
+ const carrierArtifact = scope === "consumer" && (
+ (target.endsWith("-apple-darwin") && filename === "screenpipe-attribution.json") ||
+ (target === "x86_64-unknown-linux-gnu" &&
+ ["screenpipe-attribution.tar", "screenpipe-attribution-linux.json"].includes(filename))
+ );
if (
!filename ||
filename.length > 255 ||
@@ -70,7 +73,7 @@ export function artifactKey(scope, version, target, filename) {
filename.includes("/") ||
filename.includes("\\") ||
filename.includes("\0") ||
- (!carrierManifest && !ARTIFACT_SUFFIXES.some((suffix) => filename.endsWith(suffix)))
+ (!carrierArtifact && !ARTIFACT_SUFFIXES.some((suffix) => filename.endsWith(suffix)))
) {
throw new Error("invalid artifact filename");
}
diff --git a/infra/release-artifact-uploader/src/index.test.js b/infra/release-artifact-uploader/src/index.test.js
index d40206a2b..911e5121c 100644
--- a/infra/release-artifact-uploader/src/index.test.js
+++ b/infra/release-artifact-uploader/src/index.test.js
@@ -6,6 +6,20 @@ import { describe, expect, test } from "bun:test";
import { artifactKey, handleRequest } from "./index.js";
describe("release artifact capability boundary", () => {
+ test("admits only the exact consumer Linux xattr artifacts", () => {
+ for (const filename of ["screenpipe-attribution.tar", "screenpipe-attribution-linux.json"]) {
+ expect(artifactKey("consumer", "2.7.130", "x86_64-unknown-linux-gnu", filename))
+ .toBe(`releases/2.7.130/x86_64-unknown-linux-gnu/${filename}`);
+ for (const target of ["aarch64-apple-darwin", "x86_64-apple-darwin", "x86_64-pc-windows-msvc", "aarch64-pc-windows-msvc"]) {
+ expect(() => artifactKey("consumer", "2.7.130", target, filename)).toThrow();
+ }
+ expect(() => artifactKey("enterprise", "2.7.130", "x86_64-unknown-linux-gnu", filename)).toThrow();
+ }
+ for (const filename of ["another.tar", "latest.json", "beta/latest.json", "published.json", "other-manifest.json"]) {
+ expect(() => artifactKey("consumer", "2.7.130", "x86_64-unknown-linux-gnu", filename)).toThrow();
+ }
+ });
+
test("admits only the consumer Mac carrier manifest alongside ordinary artifacts", () => {
for (const target of ["aarch64-apple-darwin", "x86_64-apple-darwin"]) {
expect(artifactKey("consumer", "2.7.130", target, "screenpipe-attribution.json"))
diff --git a/scripts/package-attribution-carrier.py b/scripts/package-attribution-carrier.py
index 624c87b82..0bc713fd5 100644
--- a/scripts/package-attribution-carrier.py
+++ b/scripts/package-attribution-carrier.py
@@ -13,10 +13,12 @@ import shutil
import struct
import subprocess
import sys
+import tarfile
import tempfile
import zipfile
PLACEHOLDER = '00000000-0000-4000-8000-000000000000'
+LINUX_XATTR = 'user.screenpipe.acquisition-grant'
def package(app, output, platform, release):
@@ -103,9 +105,7 @@ def package(app, output, platform, release):
return archive, manifest
-def package_filename(artifact, output, platform, release):
- """Copy an immutable executable; only its delivered filename is personalized."""
- artifact, output = Path(artifact).resolve(), Path(output).resolve()
+def validate_artifact(artifact, platform, release):
if not re.fullmatch(r'\d+\.\d+\.\d+(?:-[A-Za-z0-9.-]+)?', release):
raise ValueError('valid release required')
if not re.search(r'(?:^|[_-])' + re.escape(release) + r'(?:[_-]|\.)', artifact.name):
@@ -131,6 +131,12 @@ def package_filename(artifact, output, platform, release):
versions = {str(metadata.get(key, '')).strip() for key in ('ProductVersion', 'FileVersion')}
if release not in versions:
raise ValueError('release must match Windows version metadata')
+
+
+def package_filename(artifact, output, platform, release):
+ """Copy an immutable executable; only its delivered filename is personalized."""
+ artifact, output = Path(artifact).resolve(), Path(output).resolve()
+ validate_artifact(artifact, platform, release)
size = artifact.stat().st_size
if not 100 <= size <= 2147483647:
raise ValueError('carrier size outside streaming limit')
@@ -157,6 +163,58 @@ def package_filename(artifact, output, platform, release):
return target, manifest
+def package_linux_xattr(artifact, output, platform, release):
+ """PAX metadata personalizes the file's xattr without changing AppImage bytes."""
+ if platform != 'linux':
+ raise ValueError('Linux xattr carrier requires platform linux')
+ artifact, output = Path(artifact).resolve(), Path(output).resolve()
+ validate_artifact(artifact, platform, release)
+ original_size = artifact.stat().st_size
+ original_digest = hashlib.sha256()
+ with artifact.open('rb') as source:
+ for block in iter(lambda: source.read(1024 * 1024), b''):
+ original_digest.update(block)
+ with tempfile.TemporaryDirectory(prefix='screenpipe-linux-carrier-') as tmp:
+ member = tarfile.TarInfo('screenpipe.AppImage')
+ member.size = original_size
+ member.mode = 0o755
+ member.pax_headers = {'SCHILY.xattr.' + LINUX_XATTR: PLACEHOLDER}
+ prefix = member.tobuf(format=tarfile.PAX_FORMAT)
+ if prefix.count(PLACEHOLDER.encode()) != 1:
+ raise ValueError('ambiguous or absent Linux xattr placeholder')
+ prepared = Path(tmp) / 'screenpipe-attribution.tar'
+ with tarfile.open(prepared, 'w', format=tarfile.PAX_FORMAT) as archive:
+ with artifact.open('rb') as source:
+ archive.addfile(member, source)
+ # Check the exact archived bytes, including a source modified mid-copy.
+ archived_digest = hashlib.sha256()
+ with tarfile.open(prepared) as archive:
+ source = archive.extractfile(member.name)
+ for block in iter(lambda: source.read(1024 * 1024), b''):
+ archived_digest.update(block)
+ if artifact.stat().st_size != original_size or archived_digest.digest() != original_digest.digest():
+ raise ValueError('artifact changed during copy')
+ digest = hashlib.sha256()
+ with prepared.open('rb') as source:
+ for block in iter(lambda: source.read(1024 * 1024), b''):
+ digest.update(block)
+ output.mkdir(parents=True, exist_ok=True)
+ archive = output / prepared.name
+ manifest = output / 'screenpipe-attribution-linux.json'
+ if archive.exists() or manifest.exists():
+ raise ValueError('refusing to overwrite prepared artifacts')
+ result = dict(schema=3, carrier='linux-xattr', platform=platform, release=release,
+ size=prepared.stat().st_size, sha256=digest.hexdigest(),
+ placeholder=PLACEHOLDER, grant_offset=prefix.index(PLACEHOLDER.encode()),
+ appimage=dict(name=member.name, size=member.size, sha256=original_digest.hexdigest()))
+ with prepared.open('rb') as source, archive.open('xb') as destination:
+ shutil.copyfileobj(source, destination, 1024 * 1024)
+ with manifest.open('x') as destination:
+ json.dump(result, destination, indent=2)
+ destination.write('\n')
+ return archive, manifest
+
+
def windows_metadata(artifact):
"""Read signature and version using Windows' supported PowerShell APIs."""
if sys.platform != 'win32':
@@ -180,7 +238,10 @@ if __name__ == '__main__':
parser.add_argument('--output', required=True)
parser.add_argument('--platform', choices=['macos-arm', 'macos-intel', 'linux', 'windows', 'windows-arm'], required=True)
parser.add_argument('--release', required=True)
+ parser.add_argument('--linux-xattr', action='store_true', help='prepare a Linux PAX tar xattr carrier')
args = parser.parse_args()
- prepare = package if args.app else package_filename
+ if args.linux_xattr and (not args.artifact or args.platform != 'linux'):
+ parser.error('--linux-xattr requires --artifact and --platform linux')
+ prepare = package_linux_xattr if args.linux_xattr else package if args.app else package_filename
for artifact in prepare(args.app or args.artifact, args.output, args.platform, args.release):
print(artifact)
diff --git a/scripts/test_attribution_carrier.py b/scripts/test_attribution_carrier.py
index 7f9035790..0338ec91b 100644
--- a/scripts/test_attribution_carrier.py
+++ b/scripts/test_attribution_carrier.py
@@ -4,12 +4,14 @@
import importlib.util
import hashlib
import json
+import os
import sys
from pathlib import Path
import plistlib
import shutil
import subprocess
import tempfile
+import tarfile
import unittest
from unittest import mock
@@ -19,6 +21,68 @@ spec.loader.exec_module(carrier)
class CarrierTest(unittest.TestCase):
+ def test_linux_xattr_tar_preserves_appimage_and_exact_patch_location(self):
+ with tempfile.TemporaryDirectory() as tmp:
+ root = Path(tmp)
+ artifact = root / 'screenpipe_1.2.3_amd64.AppImage'
+ content = bytearray(2049)
+ content[:6] = b'\x7fELF\x02\x01'
+ content[8:11] = b'AI\x02'
+ content[18] = 62
+ # The same bytes in the executable must never be personalized.
+ content[100:136] = carrier.PLACEHOLDER.encode()
+ artifact.write_bytes(content)
+ prepared, manifest = carrier.package_linux_xattr(artifact, root / 'out', 'linux', '1.2.3')
+ data = json.loads(manifest.read_text())
+ self.assertEqual(data['schema'], 3)
+ self.assertEqual(data['carrier'], 'linux-xattr')
+ self.assertEqual(data['size'], prepared.stat().st_size)
+ self.assertEqual(data['sha256'], hashlib.sha256(prepared.read_bytes()).hexdigest())
+ self.assertEqual(data['appimage'], dict(name='screenpipe.AppImage', size=len(content),
+ sha256=hashlib.sha256(content).hexdigest()))
+ grant = '12345678-1234-4234-8234-123456789012'
+ patched = bytearray(prepared.read_bytes())
+ offset = data['grant_offset']
+ self.assertEqual(patched[offset:offset+36], carrier.PLACEHOLDER.encode())
+ patched[offset:offset+36] = grant.encode()
+ personalized = root / 'personalized.tar'
+ personalized.write_bytes(patched)
+ with tarfile.open(personalized) as archive:
+ members = archive.getmembers()
+ self.assertEqual(len(members), 1)
+ member = members[0]
+ self.assertTrue(member.isfile())
+ self.assertEqual(member.mode, 0o755)
+ self.assertEqual(member.offset_data, 1536)
+ self.assertEqual(member.pax_headers, {'SCHILY.xattr.' + carrier.LINUX_XATTR: grant})
+ self.assertEqual(archive.extractfile(member).read(), content)
+ self.assertEqual(artifact.read_bytes(), content)
+ with self.assertRaisesRegex(ValueError, 'overwrite'):
+ carrier.package_linux_xattr(artifact, root / 'out', 'linux', '1.2.3')
+ with self.assertRaisesRegex(ValueError, 'version'):
+ carrier.package_linux_xattr(artifact, root / 'wrong-version', 'linux', '1.2.4')
+ with self.assertRaisesRegex(ValueError, 'platform linux'):
+ carrier.package_linux_xattr(artifact, root / 'wrong-platform', 'windows', '1.2.3')
+ if sys.platform == 'linux':
+ restored = root / 'restored'
+ restored.mkdir()
+ subprocess.run(['tar', '--xattrs', '-xf', str(personalized), '-C', str(restored)], check=True)
+ executable = restored / member.name
+ self.assertEqual(executable.read_bytes(), content)
+ self.assertEqual(executable.stat().st_mode & 0o777, 0o755)
+ renamed = restored / 'renamed.AppImage'
+ executable.rename(renamed)
+ self.assertEqual(os.getxattr(renamed, carrier.LINUX_XATTR), grant.encode())
+ # Verify persistence from a fresh process, without in-memory state.
+ received = subprocess.check_output([
+ sys.executable, '-c', 'import os,sys;sys.stdout.buffer.write(os.getxattr(sys.argv[1],sys.argv[2]))',
+ str(renamed), carrier.LINUX_XATTR])
+ self.assertEqual(received, grant.encode())
+ ordinary = root / 'without-xattrs'
+ ordinary.mkdir()
+ subprocess.run(['tar', '--no-xattrs', '-xf', str(personalized), '-C', str(ordinary)], check=True)
+ self.assertNotIn(carrier.LINUX_XATTR, os.listxattr(ordinary / member.name))
+
@unittest.skipUnless(sys.platform == "darwin", "requires macOS signing tools")
def test_signed_archive_metadata_and_overwrite_boundaries(self):
with tempfile.TemporaryDirectory(prefix='screenpipe-carrier-test-') as tmp: