@pdfme/common 6.2.5 → 6.2.6-dev.11

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.
package/dist/helper.d.ts CHANGED
@@ -21,6 +21,10 @@ export declare const migrateTemplate: (template: Template) => void;
21
21
  export declare const getInputFromTemplate: (template: Template) => {
22
22
  [key: string]: string;
23
23
  }[];
24
+ /**
25
+ * Checks the URL's literal host only. DNS names that resolve to internal addresses and
26
+ * redirects are not covered; validate untrusted templates server-side if that matters.
27
+ */
24
28
  export declare const isUrlSafeToFetch: (urlString: string) => boolean;
25
29
  export type PdfLinkAnnotationRect = {
26
30
  x: number;
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import { Buffer } from "buffer";
3
3
  import { PDFName } from "@pdfme/pdf-lib";
4
4
  import * as acorn from "acorn";
5
5
  //#region src/version.ts
6
- var PDFME_VERSION = "6.2.5";
6
+ var PDFME_VERSION = "6.2.6";
7
7
  //#endregion
8
8
  //#region src/pageSize.ts
9
9
  var PAGE_SIZE_PRESETS = {
@@ -351,6 +351,8 @@ var UIOptions = CommonOptions.extend({
351
351
  requiredByDefault: z.boolean().optional(),
352
352
  maxZoom: z.number().optional(),
353
353
  sidebarOpen: z.boolean().optional(),
354
+ leftSidebarWidth: z.number().positive().finite().optional(),
355
+ rightSidebarWidth: z.number().positive().finite().optional(),
354
356
  zoomLevel: z.number().optional()
355
357
  });
356
358
  var HTMLElementSchema = z.any().refine((v) => v instanceof HTMLElement);
@@ -432,6 +434,123 @@ var getInputFromTemplate = (template) => {
432
434
  });
433
435
  return [input];
434
436
  };
437
+ var parseIpv4 = (host) => {
438
+ const match = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(host);
439
+ if (!match) return null;
440
+ const octets = match.slice(1).map(Number);
441
+ return octets.every((octet) => octet <= 255) ? octets : null;
442
+ };
443
+ var parseIpv6 = (host) => {
444
+ let address = host.toLowerCase();
445
+ const lastColon = address.lastIndexOf(":");
446
+ const tail = address.slice(lastColon + 1);
447
+ if (tail.includes(".")) {
448
+ const octets = parseIpv4(tail);
449
+ if (!octets) return null;
450
+ const high = (octets[0] << 8 | octets[1]).toString(16);
451
+ const low = (octets[2] << 8 | octets[3]).toString(16);
452
+ address = `${address.slice(0, lastColon + 1)}${high}:${low}`;
453
+ }
454
+ const halves = address.split("::");
455
+ if (halves.length > 2) return null;
456
+ const toGroups = (part) => part === "" ? [] : part.split(":");
457
+ const head = toGroups(halves[0]);
458
+ let groups = head;
459
+ if (halves.length === 2) {
460
+ const rest = toGroups(halves[1]);
461
+ const missing = 8 - head.length - rest.length;
462
+ if (missing < 1) return null;
463
+ groups = [
464
+ ...head,
465
+ ...Array(missing).fill("0"),
466
+ ...rest
467
+ ];
468
+ }
469
+ if (groups.length !== 8 || !groups.every((group) => /^[0-9a-f]{1,4}$/.test(group))) return null;
470
+ return groups.map((group) => parseInt(group, 16));
471
+ };
472
+ var ipv4ToInt = (octets) => (octets[0] << 24 | octets[1] << 16 | octets[2] << 8 | octets[3]) >>> 0;
473
+ var toIpv4Range = (cidr) => {
474
+ const [address, prefix] = cidr.split("/");
475
+ const prefixLength = Number(prefix);
476
+ const mask = prefixLength === 0 ? 0 : -1 << 32 - prefixLength >>> 0;
477
+ return {
478
+ base: (ipv4ToInt(parseIpv4(address)) & mask) >>> 0,
479
+ mask
480
+ };
481
+ };
482
+ var toIpv6Range = (cidr) => {
483
+ const [address, prefix] = cidr.split("/");
484
+ return {
485
+ base: parseIpv6(address),
486
+ prefixLength: Number(prefix)
487
+ };
488
+ };
489
+ var NON_PUBLIC_IPV4_RANGES = [
490
+ "0.0.0.0/8",
491
+ "10.0.0.0/8",
492
+ "100.64.0.0/10",
493
+ "127.0.0.0/8",
494
+ "169.254.0.0/16",
495
+ "172.16.0.0/12",
496
+ "192.0.0.0/24",
497
+ "192.0.2.0/24",
498
+ "192.88.99.0/24",
499
+ "192.168.0.0/16",
500
+ "198.18.0.0/15",
501
+ "198.51.100.0/24",
502
+ "203.0.113.0/24",
503
+ "224.0.0.0/4",
504
+ "240.0.0.0/4"
505
+ ].map(toIpv4Range);
506
+ var NON_PUBLIC_IPV6_RANGES = [
507
+ "::/96",
508
+ "100::/64",
509
+ "2001::/32",
510
+ "2001:db8::/32",
511
+ "64:ff9b:1::/48",
512
+ "fc00::/7",
513
+ "fe80::/10",
514
+ "fec0::/10",
515
+ "ff00::/8"
516
+ ].map(toIpv6Range);
517
+ var LOOPBACK_HOSTNAMES = /* @__PURE__ */ new Set([
518
+ "localhost",
519
+ "localhost.localdomain",
520
+ "ip6-localhost",
521
+ "ip6-loopback"
522
+ ]);
523
+ var IPV4_MAPPED_RANGE = toIpv6Range("::ffff:0:0/96");
524
+ var NAT64_WELL_KNOWN_RANGE = toIpv6Range("64:ff9b::/96");
525
+ var SIX_TO_FOUR_RANGE = toIpv6Range("2002::/16");
526
+ var isPublicIpv4 = (octets) => {
527
+ const value = ipv4ToInt(octets);
528
+ return NON_PUBLIC_IPV4_RANGES.every(({ base, mask }) => (value & mask) >>> 0 !== base);
529
+ };
530
+ var isInIpv6Range = (groups, { base, prefixLength }) => {
531
+ for (let i = 0; i < 8; i++) {
532
+ const bits = Math.min(16, Math.max(0, prefixLength - i * 16));
533
+ if (bits === 0) return true;
534
+ const mask = 65535 << 16 - bits & 65535;
535
+ if ((groups[i] & mask) !== (base[i] & mask)) return false;
536
+ }
537
+ return true;
538
+ };
539
+ var ipv4FromGroups = (high, low) => [
540
+ high >> 8,
541
+ high & 255,
542
+ low >> 8,
543
+ low & 255
544
+ ];
545
+ var isPublicIpv6 = (groups) => {
546
+ if (isInIpv6Range(groups, IPV4_MAPPED_RANGE) || isInIpv6Range(groups, NAT64_WELL_KNOWN_RANGE)) return isPublicIpv4(ipv4FromGroups(groups[6], groups[7]));
547
+ if (isInIpv6Range(groups, SIX_TO_FOUR_RANGE)) return isPublicIpv4(ipv4FromGroups(groups[1], groups[2]));
548
+ return NON_PUBLIC_IPV6_RANGES.every((range) => !isInIpv6Range(groups, range));
549
+ };
550
+ /**
551
+ * Checks the URL's literal host only. DNS names that resolve to internal addresses and
552
+ * redirects are not covered; validate untrusted templates server-side if that matters.
553
+ */
435
554
  var isUrlSafeToFetch = (urlString) => {
436
555
  let parsed;
437
556
  try {
@@ -441,31 +560,15 @@ var isUrlSafeToFetch = (urlString) => {
441
560
  }
442
561
  if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return false;
443
562
  const hostname = parsed.hostname.toLowerCase();
444
- if (hostname === "localhost" || hostname === "0.0.0.0" || hostname === "[::1]" || hostname === "::1") return false;
445
- const bare = hostname.replace(/^\[|\]$/g, "");
446
- if (/^fe80:/i.test(bare)) return false;
447
- if (/^f[cd]/i.test(bare)) return false;
448
- const ipv4MappedMatch = bare.match(/^::ffff:(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/i);
449
- if (ipv4MappedMatch) {
450
- const a = Number(ipv4MappedMatch[1]);
451
- const b = Number(ipv4MappedMatch[2]);
452
- if (a === 0 || a === 10 || a === 127) return false;
453
- if (a === 169 && b === 254) return false;
454
- if (a === 172 && b >= 16 && b <= 31) return false;
455
- if (a === 192 && b === 168) return false;
563
+ if (hostname.startsWith("[") && hostname.endsWith("]")) {
564
+ const groups = parseIpv6(hostname.slice(1, -1));
565
+ return groups !== null && isPublicIpv6(groups);
456
566
  }
457
- const ipv4Match = hostname.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/);
458
- if (ipv4Match) {
459
- const a = Number(ipv4Match[1]);
460
- const b = Number(ipv4Match[2]);
461
- if (a === 0) return false;
462
- if (a === 10) return false;
463
- if (a === 127) return false;
464
- if (a === 169 && b === 254) return false;
465
- if (a === 172 && b >= 16 && b <= 31) return false;
466
- if (a === 192 && b === 168) return false;
467
- }
468
- return true;
567
+ const host = hostname.replace(/\.+$/, "");
568
+ if (!host) return false;
569
+ const ipv4 = parseIpv4(host);
570
+ if (ipv4) return isPublicIpv4(ipv4);
571
+ return !LOOPBACK_HOSTNAMES.has(host) && !host.endsWith(".localhost");
469
572
  };
470
573
  var SAFE_LINK_URI_PROTOCOLS = /* @__PURE__ */ new Set([
471
574
  "http:",