@networkpro/web 1.24.5 → 1.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24,14 +24,30 @@ jobs:
24
24
  steps:
25
25
  - name: Check commit source
26
26
  run: |
27
- # Only trigger warning if commit wasn't from a merge or bot
28
- if [[ "${{ github.event.head_commit.message }}" != *"Merge pull request"* ]] && \
29
- [[ "${{ github.actor }}" != "dependabot[bot]" ]]; then
30
- echo "::warning ::⚠️ Direct commit to ${GITHUB_REF##*/} by $GITHUB_ACTOR."
31
- echo "### ⚠️ Direct Commit Detected" >> $GITHUB_STEP_SUMMARY
32
- echo "A commit was pushed directly to \`${GITHUB_REF##*/}\` by **${GITHUB_ACTOR}**." >> $GITHUB_STEP_SUMMARY
33
- echo "" >> $GITHUB_STEP_SUMMARY
34
- echo "💡 It's recommended to use pull requests for traceability and CI validation." >> $GITHUB_STEP_SUMMARY
35
- else
36
- echo " Merge or bot commit detected no action needed."
27
+ commit_msg="${{ github.event.head_commit.message }}"
28
+ actor="${{ github.actor }}"
29
+ branch="${GITHUB_REF##*/}"
30
+
31
+ echo "📝 Commit message: $commit_msg"
32
+ echo "👤 Actor: $actor"
33
+ echo "🌿 Branch: $branch"
34
+
35
+ # Define known safe patterns (merge or bot commits)
36
+ if echo "$commit_msg" | grep -Eq "Merge pull request|See merge request|Merge branch|(#\d+)$"; then
37
+ echo "✅ Merge-related commit detected — no warning."
38
+ exit 0
37
39
  fi
40
+
41
+ if [[ "$actor" == "dependabot[bot]" ]] || [[ "$actor" == "renovate[bot]" ]] || [[ "$actor" == "github-actions[bot]" ]]; then
42
+ echo "🤖 Bot commit detected — skipping warning."
43
+ exit 0
44
+ fi
45
+
46
+ # Otherwise, warn for direct commits
47
+ echo "::warning ::⚠️ Direct commit to $branch by $actor."
48
+ {
49
+ echo "### ⚠️ Direct Commit Detected"
50
+ echo "A commit was pushed directly to \`$branch\` by **$actor**."
51
+ echo ""
52
+ echo "💡 It's recommended to use pull requests for traceability and CI validation."
53
+ } >> $GITHUB_STEP_SUMMARY
package/CHANGELOG.md CHANGED
@@ -22,6 +22,71 @@ This project attempts to follow [Keep a Changelog](https://keepachangelog.com/en
22
22
 
23
23
  ---
24
24
 
25
+ ## [1.25.0]
26
+
27
+ ### Added
28
+
29
+ - Introduced unified environment detection utility (`src/lib/utils/env.js`) with full **JSDoc typing**.
30
+ - Normalizes `process.env` and `import.meta.env` usage across SSR (Node) and client contexts.
31
+ - Safely handles browser environments where `process` is undefined.
32
+ - Provides standardized flags for:
33
+ - `isDev`, `isProd`, `isAudit`, `isCI`, and `isTest`
34
+ - Enables consistent environment checks across analytics, CSP, and runtime logic.
35
+
36
+ - Added hybrid **environment + host-based analytics guard** in `src/lib/stores/posthog.js`.
37
+ - Automatically disables PostHog tracking in `audit` mode or when hostname matches `*.audit.netwk.pro`.
38
+ - Prevents analytics initialization during development and test contexts.
39
+ - Uses the shared `detectEnvironment()` utility for centralized logic.
40
+ - Improves runtime logging for environment-specific behavior.
41
+
42
+ ### Changed
43
+
44
+ - Updated `hooks.server.js` to include a dedicated **audit environment block** for Content Security Policy (CSP).
45
+ - Hardened audit CSP by removing all analytics-related sources (`posthog.com`, `posthog-assets.com`).
46
+ - Redirects CSP violation reporting to the mock endpoint (`/api/mock-csp`) in audit mode.
47
+ - Preserves full HSTS and other production security headers for audit deployments.
48
+ - Added clear separation between `test`, `audit`, and `prod` security policies.
49
+ - Improved console debugging for environment detection (`NODE_ENV`, `ENV_MODE`).
50
+
51
+ - Refactored **environment detection logic** for improved reliability across client and server contexts.
52
+ - Added unified environment resolver at `src/lib/utils/env.js` to standardize detection for `dev`, `prod`, `audit`, `ci`, and `test` modes.
53
+ - Ensures consistent handling of both `process.env.*` (Node/SSR) and `import.meta.env.*` (Vite/client) variables.
54
+ - Prevents mismatched behavior between browser-side analytics (`posthog.js`) and server-side policies (`hooks.server.js`).
55
+ - Automatically falls back to `'unknown'` if no explicit mode is set, avoiding build-time exceptions.
56
+
57
+ - Refactored **Branch Guard** workflow (`.github/workflows/branch-guard.yml`) for improved accuracy and reduced noise.
58
+ - Adjusted detection logic to **ignore merge commits**, Dependabot updates, and automated actions.
59
+ - Ensures workflow warnings are shown **only for true direct commits** to protected branches (`master`, `main`).
60
+ - Simplified step output and summary formatting for clearer reporting in the Actions log and job summary.
61
+ - Maintains lightweight permissions (`contents: read`) and executes entirely without repository writes.
62
+ - Improves reliability of branch protection monitoring without affecting CI or merge operations.
63
+
64
+ ### Fixed
65
+
66
+ - Resolved client-side crash in browser environments caused by `process.env` being undefined.
67
+ - Implemented defensive checks in `env.js` for `process` availability.
68
+ - Eliminated reference errors during client-side initialization of analytics.
69
+
70
+ ### Developer Experience
71
+
72
+ - Simplified future configuration by consolidating environment checks into a single typed utility.
73
+ - Improved maintainability and Vercel compatibility by ensuring `.env.audit` and `PUBLIC_ENV_MODE` variables propagate correctly to both client and server environments.
74
+
75
+ ### Developer Notes
76
+
77
+ - When deploying audit builds, ensure Vercel environment variables include:
78
+
79
+ ```bash
80
+ ENV_MODE=audit
81
+ PUBLIC_ENV_MODE=audit
82
+ ```
83
+
84
+ This enables analytics filtering and CSP hardening for the audit environment.
85
+
86
+ - Audit deployments retain full HTTPS and security headers but omit telemetry and external CSP reporting.
87
+
88
+ ---
89
+
25
90
  ## [1.24.5]
26
91
 
27
92
  ### Added
@@ -54,6 +119,9 @@ This project attempts to follow [Keep a Changelog](https://keepachangelog.com/en
54
119
 
55
120
  - For instructions on installing and configuring the new dependencies, please see the **[Editor Configuration](https://github.com/netwk-pro/netwk-pro.github.io/wiki/Editor-Configuration#automation)** section of the [Wiki](https://github.com/netwk-pro/netwk-pro.github.io/wiki).
56
121
 
122
+ > **Note:** Version `1.24.4` was merged but not tagged or released.
123
+ > Subsequent updates are reflected in `v1.24.5` and later.
124
+
57
125
  ---
58
126
 
59
127
  ## [1.24.4]
@@ -1515,7 +1583,8 @@ This project attempts to follow [Keep a Changelog](https://keepachangelog.com/en
1515
1583
 
1516
1584
  <!-- Link references -->
1517
1585
 
1518
- [Unreleased]: https://github.com/netwk-pro/netwk-pro.github.io/compare/v1.24.5...HEAD
1586
+ [Unreleased]: https://github.com/netwk-pro/netwk-pro.github.io/compare/v1.25.0...HEAD
1587
+ [1.25.0]: https://github.com/netwk-pro/netwk-pro.github.io/releases/tag/v1.25.0
1519
1588
  [1.24.5]: https://github.com/netwk-pro/netwk-pro.github.io/releases/tag/v1.24.5
1520
1589
  [1.24.4]: https://github.com/netwk-pro/netwk-pro.github.io/releases/tag/v1.24.4
1521
1590
  [1.24.3]: https://github.com/netwk-pro/netwk-pro.github.io/releases/tag/v1.24.3
package/cspell.json CHANGED
@@ -27,6 +27,7 @@
27
27
  "heliboard",
28
28
  "homescreen",
29
29
  "HREFTOP",
30
+ "HSTS",
30
31
  "Izzy",
31
32
  "Keybase",
32
33
  "keypair",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@networkpro/web",
3
3
  "private": false,
4
- "version": "1.24.5",
4
+ "version": "1.25.0",
5
5
  "description": "Locking Down Networks, Unlocking Confidence™ | Security, Networking, Privacy — Network Pro Strategies",
6
6
  "keywords": [
7
7
  "advisory",
@@ -35,9 +35,11 @@
35
35
  },
36
36
  "scripts": {
37
37
  "dev": "vite dev",
38
+ "dev:audit": "vite --mode audit",
38
39
  "start": "npm run dev",
39
40
  "dev:vercel": "vercel dev",
40
41
  "build": "vite build",
42
+ "build:audit": "vite build --mode audit",
41
43
  "build:vercel": "vercel build",
42
44
  "preview": "vite preview",
43
45
  "css:bundle": "node scripts/bundleCss.js",
@@ -6,33 +6,25 @@ SPDX-License-Identifier: CC-BY-4.0 OR GPL-3.0-or-later
6
6
  This file is part of Network Pro.
7
7
  ========================================================================== */
8
8
 
9
+ import { detectEnvironment } from '$lib/utils/env.js';
10
+
9
11
  /**
10
12
  * SvelteKit server hook to set Content Security Policy (CSP) header.
11
13
  * @type {import('@sveltejs/kit').Handle}
12
14
  */
13
15
  export async function handle({ event, resolve }) {
14
- // Create the response
15
16
  const response = await resolve(event);
17
+ const { isAudit, isTest, isProd } = detectEnvironment();
16
18
 
17
- // Determine environment flags
18
- // Default to development policy if neither test nor prod
19
- const isTestEnvironment =
20
- process.env.NODE_ENV === 'development' ||
21
- process.env.ENV_MODE === 'dev' ||
22
- process.env.ENV_MODE === 'ci';
23
- const isProdEnvironment =
24
- process.env.NODE_ENV === 'production' || process.env.ENV_MODE === 'prod';
25
-
26
- console.log('[CSP Debug] NODE_ENV:', process.env.NODE_ENV);
27
- console.log('[CSP Debug] ENV_MODE:', process.env.ENV_MODE);
19
+ console.log('[CSP Debug ENV]', detectEnvironment());
28
20
 
29
21
  // Determine report URI
30
22
  const reportUri =
31
- isProdEnvironment && !isTestEnvironment
23
+ isProd && !isTest && !isAudit
32
24
  ? 'https://csp.netwk.pro/.netlify/functions/csp-report'
33
25
  : '/api/mock-csp';
34
26
 
35
- // Construct base policy
27
+ // Base hardened policy
36
28
  const cspDirectives = [
37
29
  "default-src 'self';",
38
30
  "script-src 'self' 'unsafe-inline' https://us.i.posthog.com https://us-assets.i.posthog.com;",
@@ -45,40 +37,45 @@ export async function handle({ event, resolve }) {
45
37
  "object-src 'none';",
46
38
  "frame-ancestors 'none';",
47
39
  'upgrade-insecure-requests;',
48
- // Report CSP violations to external endpoint hosted at csp.netwk.pro
49
- `report-uri ${reportUri};`,
50
- 'report-to csp-endpoint;',
51
40
  ];
52
41
 
53
- // Loosen up CSP for test environments (and allow local PostHog proxy)
54
- if (isTestEnvironment) {
42
+ // 🧪 Looser CSP for local/CI test environments
43
+ if (isTest) {
55
44
  cspDirectives[1] =
56
45
  "script-src 'self' 'unsafe-inline' 'unsafe-eval' http://localhost:* ws://localhost:*;";
57
- cspDirectives[2] =
58
- "script-src-elem 'self' 'unsafe-inline' 'unsafe-eval' http://localhost:* ws://localhost:*;";
59
- cspDirectives[3] = "style-src 'self' 'unsafe-inline' http://localhost:*;";
60
- cspDirectives[4] = "img-src 'self' data: http://localhost:*;";
61
- cspDirectives[5] =
46
+ cspDirectives[2] = "style-src 'self' 'unsafe-inline' http://localhost:*;";
47
+ cspDirectives[3] = "img-src 'self' data: http://localhost:*;";
48
+ cspDirectives[4] =
62
49
  "connect-src 'self' http://localhost:* ws://localhost:* https://us.i.posthog.com https://us-assets.i.posthog.com;";
63
50
  }
64
51
 
65
- response.headers.set(
66
- 'Report-To',
67
- JSON.stringify({
68
- group: 'csp-endpoint',
69
- max_age: 10886400, // 18 weeks
70
- endpoints: [
71
- {
72
- url: 'https://csp.netwk.pro/.netlify/functions/csp-report',
73
- },
74
- ],
75
- include_subdomains: true,
76
- }),
77
- );
52
+ // 🧩 Hardened CSP for audit environment — no analytics, no CSP reporting
53
+ if (isAudit) {
54
+ cspDirectives[1] = "script-src 'self' 'unsafe-inline';";
55
+ cspDirectives[2] = "style-src 'self' 'unsafe-inline';";
56
+ cspDirectives[3] = "img-src 'self' data:;";
57
+ cspDirectives[4] = "connect-src 'self';";
58
+ }
59
+
60
+ // 📋 Attach CSP report directives ONLY in production
61
+ if (isProd && !isAudit && !isTest) {
62
+ cspDirectives.push(`report-uri ${reportUri};`, 'report-to csp-endpoint;');
78
63
 
64
+ response.headers.set(
65
+ 'Report-To',
66
+ JSON.stringify({
67
+ group: 'csp-endpoint',
68
+ max_age: 10886400, // 18 weeks
69
+ endpoints: [{ url: reportUri }],
70
+ include_subdomains: true,
71
+ }),
72
+ );
73
+ }
74
+
75
+ // ✅ Apply final CSP
79
76
  response.headers.set('Content-Security-Policy', cspDirectives.join(' '));
80
77
 
81
- // Set other security headers
78
+ // Standard security headers
82
79
  response.headers.set(
83
80
  'Permissions-Policy',
84
81
  [
@@ -103,10 +100,10 @@ export async function handle({ event, resolve }) {
103
100
  response.headers.set('Referrer-Policy', 'strict-origin-when-cross-origin');
104
101
  response.headers.set('X-Frame-Options', 'DENY');
105
102
 
106
- if (process.env.ENV_MODE !== 'test' && process.env.ENV_MODE !== 'ci') {
103
+ if (!isTest) {
107
104
  response.headers.set(
108
105
  'Strict-Transport-Security',
109
- 'max-age=31536000; includeSubDomains;', // No preload here
106
+ 'max-age=31536000; includeSubDomains;',
110
107
  );
111
108
  }
112
109
 
@@ -120,8 +117,5 @@ export async function handle({ event, resolve }) {
120
117
  export function handleError({ error, event }) {
121
118
  console.error('🔴 SSR Error in route:', event.url.pathname);
122
119
  console.error(error);
123
-
124
- return {
125
- message: 'A server-side error occurred',
126
- };
120
+ return { message: 'A server-side error occurred' };
127
121
  }
@@ -15,6 +15,7 @@ import {
15
15
  remindUserToReconsent,
16
16
  trackingPreferences,
17
17
  } from '$lib/stores/trackingPreferences.js';
18
+ import { detectEnvironment } from '$lib/utils/env.js';
18
19
  import { get, writable } from 'svelte/store';
19
20
 
20
21
  /**
@@ -38,24 +39,39 @@ let ph = null;
38
39
  /**
39
40
  * Initializes the PostHog analytics client if tracking is permitted.
40
41
  * Uses dynamic import to avoid SSR failures.
42
+ *
41
43
  * @returns {Promise<void>}
42
44
  */
43
45
  export async function initPostHog() {
44
46
  if (initialized || typeof window === 'undefined') return;
45
- const isDev = import.meta.env.MODE === 'development';
46
- if (isDev) {
47
- console.info('[PostHog] Skipping init in development mode.');
47
+
48
+ const { isAudit, isDev, isTest, mode } = detectEnvironment();
49
+
50
+ // 🌐 Hybrid hostname + environment guard
51
+ const host = window.location.hostname;
52
+ const isAuditHost = /(^|\.)audit\.netwk\.pro$/i.test(host);
53
+ const effectiveAudit = isAudit || isAuditHost;
54
+
55
+ if (effectiveAudit) {
56
+ console.info(`[PostHog] Skipping analytics (${mode} mode, host: ${host}).`);
57
+ return;
58
+ }
59
+
60
+ // 🧱 Skip entirely in dev/test contexts
61
+ if (isDev || isTest) {
62
+ console.info('[PostHog] Skipping init in dev/test mode.');
48
63
  return;
49
64
  }
50
65
 
66
+ // 🚀 Production analytics logic (with user consent)
51
67
  initialized = true;
52
68
 
53
69
  const { enabled } = get(trackingPreferences);
54
70
  trackingEnabled.set(enabled);
55
- showReminder.set(get(remindUserToReconsent)); // use derived store instead
71
+ showReminder.set(get(remindUserToReconsent));
56
72
 
57
73
  if (!enabled) {
58
- console.log('[PostHog] Tracking is disabled — skipping init.');
74
+ console.log('[PostHog] Tracking disabled — user opted out.');
59
75
  return;
60
76
  }
61
77
 
@@ -63,6 +79,7 @@ export async function initPostHog() {
63
79
  const posthogModule = await import('posthog-js');
64
80
  ph = posthogModule.default;
65
81
 
82
+ // ✅ Initialize PostHog
66
83
  // cspell:disable-next-line
67
84
  ph.init('phc_Qshfo6AXzh4pS7aPigfqyeo4qj1qlyh7gDuHDeVMSR0', {
68
85
  api_host: '/relay-MSR0/',
@@ -0,0 +1,74 @@
1
+ /* ==========================================================================
2
+ src/lib/utils/env.js
3
+
4
+ Copyright © 2025 Network Pro Strategies (Network Pro™)
5
+ SPDX-License-Identifier: CC-BY-4.0 OR GPL-3.0-or-later
6
+ This file is part of Network Pro.
7
+ ========================================================================== */
8
+
9
+ /**
10
+ * @file env.js
11
+ * @description Unified environment detection utility.
12
+ * Normalizes process.env and import.meta.env for consistent behavior
13
+ * across SvelteKit server (SSR), client (browser), and build-time contexts.
14
+ *
15
+ * Supports: dev, prod, ci, test, audit.
16
+ *
17
+ * @module src/lib/utils
18
+ * @author Scott Lopez
19
+ * @updated 2025-11-02
20
+ *
21
+ * @example
22
+ * import { detectEnvironment } from '$lib/utils/env.js';
23
+ * const { isAudit, isProd } = detectEnvironment();
24
+ * if (isAudit) console.log('Running in audit mode');
25
+ */
26
+
27
+ /**
28
+ * @typedef {object} EnvironmentInfo
29
+ * @property {string} mode - The detected environment mode (`dev`, `prod`, `audit`, etc.).
30
+ * @property {boolean} isDev - True when running in a development or local environment.
31
+ * @property {boolean} isProd - True when running in production.
32
+ * @property {boolean} isAudit - True when running in audit / staging environments.
33
+ * @property {boolean} isCI - True when running in continuous integration (CI) pipelines.
34
+ * @property {boolean} isTest - True when running under test or mock environments.
35
+ */
36
+
37
+ /**
38
+ * Normalizes environment detection across client, SSR, and build contexts.
39
+ * Uses `import.meta.env` for Vite build-time vars and `process.env` for runtime vars.
40
+ *
41
+ * @returns {EnvironmentInfo} Normalized environment context flags.
42
+ */
43
+ export function detectEnvironment() {
44
+ /** @type {string | undefined} */
45
+ const viteMode = import.meta.env?.MODE;
46
+ /** @type {string | undefined} */
47
+ const publicEnvMode = import.meta.env?.PUBLIC_ENV_MODE;
48
+
49
+ /** @type {string | undefined} */
50
+ const nodeEnv =
51
+ typeof process !== 'undefined' && process?.env?.NODE_ENV
52
+ ? process.env.NODE_ENV
53
+ : undefined;
54
+
55
+ /** @type {string | undefined} */
56
+ const envMode =
57
+ typeof process !== 'undefined' && process?.env?.ENV_MODE
58
+ ? process.env.ENV_MODE
59
+ : undefined;
60
+
61
+ // Fallback order — guarantees a mode string even if nothing is set
62
+ /** @type {string} */
63
+ const mode = envMode || publicEnvMode || viteMode || nodeEnv || 'unknown';
64
+
65
+ // Return a normalized, typed object
66
+ return {
67
+ mode,
68
+ isDev: ['development', 'dev'].includes(mode),
69
+ isProd: ['production', 'prod'].includes(mode),
70
+ isAudit: mode === 'audit',
71
+ isCI: mode === 'ci',
72
+ isTest: mode === 'test',
73
+ };
74
+ }
@@ -38,10 +38,11 @@ const IGNORE_PATHS = new Set([
38
38
  '/pgp/contact@s.neteng.pro.asc',
39
39
  '/pgp/github@sl.neteng.cc.asc',
40
40
  '/pgp/security@s.neteng.pro.asc',
41
- '/pgp/support@neteng.pro.asc',
41
+ '/pgp/support@netwk.pro.asc',
42
42
  '/screenshots/desktop-foss.png',
43
43
  '/webfonts/fa-brands-400.ttf',
44
44
  '/webfonts/fa-solid-900.ttf',
45
+ '/7cbb39ce-750b-43da-83b8-8980e5554d4d.txt',
45
46
  '/robots.txt',
46
47
  '/sitemap.xml',
47
48
  '/CNAME',