Repository navigation
Expand file tree
/
Copy pathmain.rs
More file actions
1586 lines (1523 loc) · 53.8 KB
/
Copy pathmain.rs
File metadata and controls
1586 lines (1523 loc) · 53.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//! Single deterministic entrypoint for the workspace gate: `cargo xtask ci`.
mod adblock_provenance;
mod agent_controller_boundary;
mod agent_model_catalog_boundary;
mod agent_runtime_boundary;
mod agentic_evidence;
mod agentic_probe_boundary;
mod blocker_bench;
mod blocker_bench_boundary;
mod blocker_prune;
mod blocker_seed;
mod foreground_rendering_boundary;
mod macos_imports;
mod macos_process_family;
mod map_bench;
mod page_assist_boundary;
mod page_reader_boundary;
mod password_manager_qa;
mod updater_sign;
mod webext_suite;
mod work_composition_boundary;
mod work_persistence_boundary;
mod work_resource_boundary;
use std::process::{exit, Command};
use std::sync::atomic::{AtomicBool, Ordering};
use std::time::{SystemTime, UNIX_EPOCH};
const NATIVE_ADAPTERS: [(&str, Option<&str>); 3] = [
("vendor/wry/Cargo.toml", None),
(
"vendor/tauri-runtime-wry/Cargo.toml",
Some("macos-private-api"),
),
("vendor/tauri/Cargo.toml", Some("macos-private-api,specta")),
];
const ADBLOCK_MANIFEST: &str = "vendor/adblock/Cargo.toml";
const BLOCKER_FUZZ_MANIFEST: &str = "crates/zephium-blocker/fuzz/Cargo.toml";
const BLOCKER_FEATURE_SETS: [&str; 5] = [
"runtime",
"runtime-exact",
"webkit",
"runtime,webkit",
"runtime-exact,webkit",
];
static CI_RESOURCE_PROFILE: AtomicBool = AtomicBool::new(false);
fn main() {
let arguments = std::env::args().skip(1).collect::<Vec<_>>();
match arguments.first().map(String::as_str) {
Some("ci") => {
CI_RESOURCE_PROFILE.store(true, Ordering::Release);
ci();
}
Some("sign-windows-updater") => {
if let Err(error) = updater_sign::run(&arguments[1..]) {
eprintln!("Windows updater signing failed: {error}");
exit(1);
}
}
Some("check-release-assets") => {
if let Err(error) = updater_sign::check_release_assets(&arguments[1..]) {
eprintln!("release asset verification failed: {error}");
exit(1);
}
}
Some("check-frame-styles") => run("node", &["frame/scripts/check-styles.mjs"]),
Some("check-macos-imports") => {
if let Err(error) = macos_imports::run(&arguments[1..]) {
eprintln!("macOS import check failed: {error}");
exit(1);
}
}
Some("check-engine-floors") => {
check_engine_floors(strict_flag(&arguments[1..], "check-engine-floors"))
}
Some("check-release-engine-security") => check_release_engine_security(),
Some("check-agentic-probe-boundary") => check_agentic_probe_boundary(),
Some("check-agent-model-catalog-boundary") => check_agent_model_catalog_boundary(),
Some("check-page-assist-boundary") => check_page_assist_boundary(),
Some("check-page-reader-boundary") => check_page_reader_boundary(),
Some("check-agent-controller-boundary") => check_agent_controller_boundary(),
Some("check-agent-runtime-boundary") => check_agent_runtime_boundary(),
Some("check-advisory-exceptions") => {
check_advisory_exceptions(strict_flag(&arguments[1..], "check-advisory-exceptions"))
}
Some("check-security-fork-locks") | Some("check-native-adapter-locks") => {
check_security_fork_locks()
}
Some("check-blocker-security-fork") => check_blocker_security_fork(),
Some("blocker-bench") => {
if let Err(error) = blocker_bench::run(&arguments[1..]) {
eprintln!("blocker bench: {error}");
exit(1);
}
}
Some("map-bench") => {
if let Err(error) = map_bench::run(&arguments[1..]) {
eprintln!("map bench: {error}");
exit(1);
}
}
Some("webext-suite") => {
if let Err(error) = webext_suite::run(&arguments[1..]) {
eprintln!("extension suite: {error}");
exit(1);
}
}
Some("measure-macos-process-family") => {
if let Err(error) = macos_process_family::run(&arguments[1..]) {
eprintln!("macOS process-family measurement failed: {error}");
exit(1);
}
}
Some("serve-password-manager-webauthn-qa") => {
if let Err(error) = password_manager_qa::run(&arguments[1..]) {
eprintln!("password-manager WebAuthn QA failed: {error}");
exit(1);
}
}
Some("check-blocker-seed") if arguments.len() == 1 => {
let repository = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("..");
if let Err(error) = blocker_seed::check(&repository) {
eprintln!("bundled blocker seed policy failed: {error}");
exit(1);
}
}
Some("materialize-blocker-seed-webkit")
if arguments.len() == 3 && arguments[1] == "--output" =>
{
let repository = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("..");
if let Err(error) =
blocker_seed::materialize_webkit(&repository, std::path::Path::new(&arguments[2]))
{
eprintln!("bundled blocker seed materialization failed: {error}");
exit(1);
}
}
Some("update-blocker-seed") => update_blocker_seed(&arguments[1..]),
Some("blocker-prune") => {
if let Err(error) = blocker_prune::run(&arguments[1..]) {
eprintln!("blocker prune: {error}");
exit(1);
}
}
#[cfg(any(feature = "blocker-seed-runtime", feature = "blocker-seed-webkit"))]
Some("__compile-blocker-seed") => compile_blocker_seed(&arguments[1..]),
// Retain the old entrypoint for local automation while making it run
// every engine-floor deadline, not only Windows.
Some("check-webview2-floor") => {
check_engine_floors(strict_flag(&arguments[1..], "check-webview2-floor"))
}
_ => {
eprintln!(
"usage: cargo xtask <ci|webext-suite [--only NAME,...] [--soak]|blocker-bench --zephium PATH [--browsers LIST] [--runs N] [--only SITES] [--settle-ms N] [--youtube|--startup N] [--label NAME] [--compare RESULTS]|map-bench <record|replay|report> ...|check-frame-styles|check-macos-imports <binary>|check-engine-floors [--strict]|check-release-engine-security|check-release-assets <directory> <tag> <owner/repo>|check-agentic-probe-boundary|check-advisory-exceptions [--strict]|check-security-fork-locks|check-native-adapter-locks|check-blocker-security-fork|measure-macos-process-family --bundle-id ID --duration-seconds N [--interval-millis N] [--label LABEL]|serve-password-manager-webauthn-qa [--port PORT]|check-blocker-seed|materialize-blocker-seed-webkit --output PATH|{UPDATE_BLOCKER_SEED_USAGE}|blocker-prune <materialize|notify|hosts|build> ...|check-webview2-floor [--strict]>"
);
exit(2);
}
}
}
const UPDATE_BLOCKER_SEED_USAGE: &str =
"update-blocker-seed --sources DIR --license PATH --gpl-license PATH";
fn update_blocker_seed(arguments: &[String]) {
const FLAGS: [&str; 3] = ["--sources", "--license", "--gpl-license"];
let mut paths = [None; FLAGS.len()];
let complete = arguments.len() == 2 * FLAGS.len()
&& arguments.chunks_exact(2).all(|pair| {
FLAGS
.iter()
.position(|flag| *flag == pair[0])
.is_some_and(|index| {
paths[index]
.replace(std::path::Path::new(&pair[1]))
.is_none()
})
});
let (true, [Some(sources), Some(license), Some(gpl_license)]) = (complete, paths) else {
eprintln!("usage: cargo xtask {UPDATE_BLOCKER_SEED_USAGE}");
exit(2);
};
let repository = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("..");
if let Err(error) = blocker_seed::update(&repository, sources, [license, gpl_license]) {
eprintln!("bundled blocker seed update failed: {error}");
exit(1);
}
}
/// `<target> <source path>... [--artifact PATH [--unpruned]]`
#[cfg(any(feature = "blocker-seed-runtime", feature = "blocker-seed-webkit"))]
fn compile_blocker_seed(arguments: &[String]) {
let mut rest = arguments;
let unpruned = matches!(rest, [.., flag] if flag == "--unpruned");
if unpruned {
rest = &rest[..rest.len() - 1];
}
let artifact = match rest {
[head @ .., flag, output] if flag == "--artifact" => {
rest = head;
Some(std::path::Path::new(output))
}
_ => None,
};
let [target, sources @ ..] = rest else {
eprintln!("usage: __compile-blocker-seed TARGET PATH... [--artifact PATH [--unpruned]]");
exit(2);
};
if sources.is_empty() || (unpruned && artifact.is_none()) {
eprintln!("usage: __compile-blocker-seed TARGET PATH... [--artifact PATH [--unpruned]]");
exit(2);
}
let sources = sources
.iter()
.map(std::path::PathBuf::from)
.collect::<Vec<_>>();
if let Err(error) = blocker_seed::compile_hidden(target, &sources, artifact, unpruned) {
eprintln!("bundled blocker seed compilation failed: {error}");
exit(1);
}
}
fn strict_flag(arguments: &[String], command: &str) -> bool {
match arguments {
[] => false,
[flag] if flag == "--strict" => true,
_ => {
eprintln!("usage: cargo xtask {command} [--strict]");
exit(2);
}
}
}
/// An expired review is a maintenance signal, not a defect in the change
/// under test, so it warns everywhere except where `--strict` is requested:
/// the release gate and the weekly security review.
fn report_expired_reviews(title: &str, expired: &[String], strict: bool) {
let level = if strict { "error" } else { "warning" };
let annotate = std::env::var("GITHUB_ACTIONS").is_ok_and(|value| value == "true");
for message in expired {
if annotate {
println!("::{level} title={title}::{message}");
} else {
eprintln!("{level}: {message}");
}
}
if strict && !expired.is_empty() {
exit(1);
}
}
fn check_advisory_exceptions(strict: bool) {
let now = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap_or_else(|error| {
eprintln!("advisory-exception check cannot read UTC time: {error}");
exit(1);
})
.as_secs();
let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../deny.toml");
let source = std::fs::read_to_string(&path).unwrap_or_else(|error| {
eprintln!("cannot read {}: {error}", path.display());
exit(1);
});
match validate_advisory_exceptions(&source, now) {
Ok(expired) => report_expired_reviews("Advisory exception expired", &expired, strict),
Err(error) => {
eprintln!("cargo-deny advisory exception policy failed: {error}");
exit(1);
}
}
}
fn check_security_fork_locks() {
const ROOT_NATIVE_ADAPTERS: &[(&str, &str)] = &[
("tauri", "2.11.3"),
("tauri-runtime-wry", "2.11.3"),
("wry", "0.55.1"),
];
const ROOT_FORKS: &[(&str, &str)] = &[
("adblock", "0.13.2"),
("tao", "0.35.3"),
("tauri", "2.11.3"),
("tauri-runtime-wry", "2.11.3"),
("wry", "0.55.1"),
];
const ADBLOCK_FORK: &[(&str, &str)] = &[("adblock", "0.13.2")];
const RUNTIME_ADAPTERS: &[(&str, &str)] = &[("tauri-runtime-wry", "2.11.3"), ("wry", "0.55.1")];
const WRY_ADAPTERS: &[(&str, &str)] = &[("wry", "0.55.1")];
let repository = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("..");
for (relative, forks) in [
("Cargo.lock", ROOT_FORKS),
("vendor/adblock/Cargo.lock", ADBLOCK_FORK),
("vendor/tauri/Cargo.lock", ROOT_NATIVE_ADAPTERS),
("vendor/tauri-runtime-wry/Cargo.lock", RUNTIME_ADAPTERS),
("vendor/wry/Cargo.lock", WRY_ADAPTERS),
] {
let path = repository.join(relative);
let source = std::fs::read_to_string(&path).unwrap_or_else(|error| {
eprintln!("cannot read {}: {error}", path.display());
exit(1);
});
if let Err(error) = validate_security_fork_lock(&source, forks) {
eprintln!("vendored security-fork lock policy failed for {relative}: {error}");
exit(1);
}
}
if let Err(error) = adblock_provenance::check(&repository) {
eprintln!("adblock fork provenance policy failed: {error}");
exit(1);
}
check_tauri_fixture_blobs(&repository);
}
fn check_tauri_fixture_blobs(repository: &std::path::Path) {
const EXPECTED_COMMIT: &str = "6f6ab1207bb3923c2721fbc67d2fdb1c8deb0c7a";
const EXPECTED_FILES: [(&str, &str); 5] = [
(
"test/fixture/src-tauri/tauri.conf.json",
"f5b75e3eb0554e617a862d78194c02176c811fcd",
),
(
"test/fixture/dist/index.html",
"698a3577914d350e1ebcd9279fe325563553ba24",
),
(
"test/fixture/src-tauri/icons/icon.ico",
"b3636e4b22ba65db9061cd60a77b02c92022dfd6",
),
(
"test/fixture/src-tauri/icons/icon.ico~dev",
"db7fd98204424b6b9b02fa06ad18f05c089f93b5",
),
(
"test/fixture/src-tauri/icons/icon.png",
"a437dd51741e9e56e14b5d6024493cb2abfd5259",
),
];
let fork_root = repository.join("vendor/tauri");
let record_path = fork_root.join("TEST_FIXTURE.toml");
let source = std::fs::read_to_string(&record_path).unwrap_or_else(|error| {
eprintln!("cannot read {}: {error}", record_path.display());
exit(1);
});
let document = source.parse::<toml::Table>().unwrap_or_else(|error| {
eprintln!("{} is invalid TOML: {error}", record_path.display());
exit(1);
});
if document
.get("upstream_commit")
.and_then(toml::Value::as_str)
!= Some(EXPECTED_COMMIT)
{
eprintln!("Tauri fixture record does not match the reviewed upstream commit");
exit(1);
}
let files = document
.get("files")
.and_then(toml::Value::as_array)
.filter(|files| files.len() == EXPECTED_FILES.len())
.unwrap_or_else(|| {
eprintln!(
"Tauri fixture record must contain exactly {} files",
EXPECTED_FILES.len()
);
exit(1);
});
let mut seen = std::collections::HashSet::with_capacity(EXPECTED_FILES.len());
for file in files {
let file = file.as_table().unwrap_or_else(|| {
eprintln!("Tauri fixture record contains a non-table file entry");
exit(1);
});
let relative = file
.get("path")
.and_then(toml::Value::as_str)
.map(std::path::Path::new)
.filter(|path| {
!path.is_absolute()
&& path
.components()
.all(|component| matches!(component, std::path::Component::Normal(_)))
})
.unwrap_or_else(|| {
eprintln!("Tauri fixture record contains an unsafe path");
exit(1);
});
let recorded = file
.get("git_blob")
.and_then(toml::Value::as_str)
.filter(|hash| hash.len() == 40 && hash.bytes().all(|byte| byte.is_ascii_hexdigit()))
.unwrap_or_else(|| {
eprintln!("Tauri fixture record contains an invalid Git blob identity");
exit(1);
});
let relative_text = relative.to_string_lossy();
let expected = EXPECTED_FILES
.iter()
.find_map(|(path, hash)| (*path == relative_text.as_ref()).then_some(*hash))
.unwrap_or_else(|| {
eprintln!("unexpected Tauri fixture path {relative_text}");
exit(1);
});
if !seen.insert(relative_text.into_owned()) {
eprintln!("duplicate Tauri fixture path {}", relative.display());
exit(1);
}
if recorded != expected {
eprintln!(
"Tauri fixture record assigns {recorded} to {}, expected {expected}",
relative.display()
);
exit(1);
}
let path = fork_root.join(relative);
let metadata = std::fs::symlink_metadata(&path).unwrap_or_else(|error| {
eprintln!("cannot inspect {}: {error}", path.display());
exit(1);
});
if !metadata.file_type().is_file() || metadata.file_type().is_symlink() {
eprintln!("Tauri fixture {} is not a regular file", path.display());
exit(1);
}
let output = Command::new("git")
.arg("hash-object")
.arg(&path)
.output()
.unwrap_or_else(|error| {
eprintln!("cannot hash {}: {error}", path.display());
exit(1);
});
let actual = std::str::from_utf8(&output.stdout)
.ok()
.map(str::trim)
.filter(|_| output.status.success())
.unwrap_or_else(|| {
eprintln!("git hash-object failed for {}", path.display());
exit(1);
});
if actual != expected {
eprintln!(
"Tauri fixture {} has Git blob {actual}, expected {expected}",
path.display()
);
exit(1);
}
}
}
fn validate_security_fork_lock(source: &str, required: &[(&str, &str)]) -> Result<(), String> {
let document = source
.parse::<toml::Table>()
.map_err(|error| format!("invalid Cargo.lock TOML: {error}"))?;
let packages = document
.get("package")
.and_then(toml::Value::as_array)
.ok_or_else(|| "Cargo.lock has no package array".to_owned())?;
for &(name, expected_version) in required {
let matching = packages
.iter()
.filter_map(toml::Value::as_table)
.filter(|package| package.get("name").and_then(toml::Value::as_str) == Some(name))
.collect::<Vec<_>>();
if matching.len() != 1 {
return Err(format!(
"expected exactly one `{name}` package, found {}",
matching.len()
));
}
let package = matching[0];
let version = package
.get("version")
.and_then(toml::Value::as_str)
.ok_or_else(|| format!("`{name}` has no version"))?;
if version != expected_version {
return Err(format!(
"`{name}` resolved to {version}, expected {expected_version}"
));
}
if package.contains_key("source") || package.contains_key("checksum") {
return Err(format!(
"`{name}` is registry/git sourced instead of the reviewed local adapter"
));
}
}
Ok(())
}
/// Returns one message per expired exception; malformed or over-long
/// exceptions are hard errors.
fn validate_advisory_exceptions(source: &str, now: u64) -> Result<Vec<String>, String> {
const MAX_EXCEPTION_LIFETIME: u64 = 120 * 24 * 60 * 60;
let document = source
.parse::<toml::Table>()
.map_err(|error| format!("deny.toml is not valid TOML: {error}"))?;
let ignore = document
.get("advisories")
.and_then(toml::Value::as_table)
.and_then(|advisories| advisories.get("ignore"))
.and_then(toml::Value::as_array)
.ok_or_else(|| "deny.toml advisories.ignore must be an array".to_owned())?;
if ignore.is_empty() {
return Err("deny.toml contains no advisory exception entries".into());
}
let mut ids = std::collections::HashSet::with_capacity(ignore.len());
let mut expired = Vec::new();
for (index, exception) in ignore.iter().enumerate() {
let entry = index + 1;
let exception = exception.as_table().ok_or_else(|| {
format!(
"advisory exception {entry} must be a table with id and reason; bare-string ignores are forbidden"
)
})?;
let id = exception
.get("id")
.and_then(toml::Value::as_str)
.filter(|id| valid_rustsec_id(id))
.ok_or_else(|| format!("advisory exception {entry} has no valid RUSTSEC id"))?;
if !ids.insert(id) {
return Err(format!("advisory exception {entry} duplicates {id}"));
}
let reason = exception
.get("reason")
.and_then(toml::Value::as_str)
.ok_or_else(|| format!("advisory exception {entry} has no machine-readable reason"))?;
let owner = reason
.split(';')
.find_map(|part| part.trim().strip_prefix("owner="))
.filter(|owner| !owner.is_empty())
.ok_or_else(|| format!("advisory exception {entry} has no owner"))?;
let expiry = reason
.split(';')
.find_map(|part| part.trim().strip_prefix("expires-unix="))
.and_then(|value| value.parse::<u64>().ok())
.ok_or_else(|| format!("advisory exception {entry} has no valid expires-unix"))?;
let human_expiry = reason
.split(';')
.find_map(|part| part.trim().strip_prefix("expires="))
.filter(|value| valid_iso_date(value))
.ok_or_else(|| format!("advisory exception {entry} has no valid ISO expiry"))?;
if expiry <= now {
expired.push(format!(
"deny.toml advisory exception {id} owned by {owner} expired at {human_expiry} ({expiry}); remove or upgrade the dependency, or re-review the exception"
));
}
if expiry.saturating_sub(now) > MAX_EXCEPTION_LIFETIME {
return Err(format!(
"advisory exception {entry} owned by {owner} exceeds the 120-day review horizon"
));
}
}
Ok(expired)
}
fn valid_rustsec_id(value: &str) -> bool {
let Some((year, sequence)) = value
.strip_prefix("RUSTSEC-")
.and_then(|tail| tail.split_once('-'))
else {
return false;
};
year.len() == 4
&& sequence.len() == 4
&& year.bytes().all(|byte| byte.is_ascii_digit())
&& sequence.bytes().all(|byte| byte.is_ascii_digit())
}
fn valid_iso_date(value: &str) -> bool {
let bytes = value.as_bytes();
bytes.len() == 10
&& bytes[4] == b'-'
&& bytes[7] == b'-'
&& bytes
.iter()
.enumerate()
.all(|(index, byte)| matches!(index, 4 | 7) || byte.is_ascii_digit())
}
fn check_engine_floors(strict: bool) {
let now = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap_or_else(|error| {
eprintln!("engine security-floor check cannot read UTC time: {error}");
exit(1);
})
.as_secs();
let mut expired = Vec::new();
if !zephium_core::webview2::security_floor_review_is_current(now) {
expired.push(format!(
"WebView2 security review (hard floor {}, latest reviewed {}) expired after {}. Review {}, {}, and exact runtime availability at {}, then update the versions, publication dates, and review deadline together.",
zephium_core::webview2::SECURITY_FLOOR_TEXT,
zephium_core::webview2::LATEST_REVIEWED_TEXT,
zephium_core::webview2::SECURITY_FLOOR_REVIEW_BY,
zephium_core::webview2::SECURITY_FLOOR_SOURCE_URL,
zephium_core::webview2::LATEST_REVIEWED_SOURCE_URL,
zephium_core::webview2::RUNTIME_AVAILABILITY_SOURCE_URL,
));
} else {
eprintln!(
"WebView2 hard floor {} and latest reviewed Stable {} are reviewed through {}",
zephium_core::webview2::SECURITY_FLOOR_TEXT,
zephium_core::webview2::LATEST_REVIEWED_TEXT,
zephium_core::webview2::SECURITY_FLOOR_REVIEW_BY,
);
}
if !zephium_core::macos::security_floor_review_is_current(now) {
expired.push(format!(
"macOS/WebKit security floors expired after {}. Review {}, {}, {}, and {} and update the OS/Safari versions, publication date, and review deadline together.",
zephium_core::macos::SECURITY_FLOOR_REVIEW_BY,
zephium_core::macos::SECURITY_FLOOR_SOURCE_URL,
zephium_core::macos::SAFARI_SECURITY_SOURCE_URL,
zephium_core::macos::TAHOE_SECURITY_SOURCE_URL,
zephium_core::macos::SEQUOIA_SECURITY_SOURCE_URL,
));
} else {
eprintln!(
"macOS/WebKit hard floors Sonoma {}, Sequoia {}, Tahoe {}, macOS 27 {}, and Safari {}; latest recommendations Sonoma {} + Safari {}, Sequoia {}, Tahoe {}, macOS 27 {}, with Safari {}; reviewed through {}",
zephium_core::macos::SONOMA_SECURITY_FLOOR_TEXT,
zephium_core::macos::SEQUOIA_SECURITY_FLOOR_TEXT,
zephium_core::macos::TAHOE_SECURITY_FLOOR_TEXT,
zephium_core::macos::GOLDEN_GATE_SECURITY_FLOOR_TEXT,
zephium_core::macos::SAFARI_SECURITY_FLOOR_TEXT,
zephium_core::macos::SONOMA_RECOMMENDED_TEXT,
zephium_core::macos::SONOMA_SAFARI_RECOMMENDED_TEXT,
zephium_core::macos::SEQUOIA_RECOMMENDED_TEXT,
zephium_core::macos::TAHOE_RECOMMENDED_TEXT,
zephium_core::macos::GOLDEN_GATE_RECOMMENDED_TEXT,
zephium_core::macos::SAFARI_RECOMMENDED_TEXT,
zephium_core::macos::SECURITY_FLOOR_REVIEW_BY,
);
}
if !zephium_core::webkitgtk::security_floor_review_is_current(now) {
expired.push(format!(
"WebKitGTK security floor {} expired after {}. Review {} and {} and update the advisory floor, latest-reviewed release, and deadline together.",
zephium_core::webkitgtk::SECURITY_FLOOR_TEXT,
zephium_core::webkitgtk::SECURITY_FLOOR_REVIEW_BY,
zephium_core::webkitgtk::SECURITY_FLOOR_SOURCE_URL,
zephium_core::webkitgtk::LATEST_REVIEWED_SOURCE_URL,
));
} else {
eprintln!(
"WebKitGTK security floor {} (latest reviewed {}) is reviewed through {}",
zephium_core::webkitgtk::SECURITY_FLOOR_TEXT,
zephium_core::webkitgtk::LATEST_REVIEWED_TEXT,
zephium_core::webkitgtk::SECURITY_FLOOR_REVIEW_BY,
);
}
report_expired_reviews("Engine security review expired", &expired, strict);
}
/// Release-only publication gate. Runtime admission uses the best stable
/// engine that actually exists; publishing additionally requires current
/// engine and advisory reviews, that no vendor has acknowledged an
/// outstanding stable-channel security fix, and that the immutable blocker
/// sources are still within their upstream recommended refresh cadence at
/// the exact publication boundary.
fn check_release_engine_security() {
check_agentic_probe_boundary();
check_engine_floors(true);
check_advisory_exceptions(true);
let now = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap_or_else(|error| {
eprintln!("release engine-security check cannot read UTC time: {error}");
exit(1);
})
.as_secs();
let repository = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("..");
if let Err(error) = blocker_seed::check_release_freshness(&repository, now) {
eprintln!("production release is blocked by bundled blocker seed freshness: {error}");
exit(1);
}
if !zephium_core::webview2::production_release_security_is_current(now) {
eprintln!(
"production release is blocked: Microsoft acknowledged an outstanding Chromium security fix on {} (status reviewed {}); review {} and publish only after a fixed Stable WebView2 runtime is available and the floor is updated",
zephium_core::webview2::OUTSTANDING_VENDOR_FIX_NOTICE_ON,
zephium_core::webview2::OUTSTANDING_VENDOR_FIX_REVIEWED_ON,
zephium_core::webview2::OUTSTANDING_VENDOR_FIX_SOURCE_URL,
);
exit(1);
}
}
fn ci() {
share_workspace_target_dir();
check_agentic_probe_boundary();
check_agent_model_catalog_boundary();
check_page_assist_boundary();
check_page_reader_boundary();
check_agent_controller_boundary();
check_agent_runtime_boundary();
check_engine_floors(false);
check_advisory_exceptions(false);
check_blocker_security_fork();
run("cargo", &["fmt", "--all", "--", "--check"]);
for (manifest, _) in NATIVE_ADAPTERS {
run(
"cargo",
&["fmt", "--manifest-path", manifest, "--", "--check"],
);
}
run(
"cargo",
&[
"clippy",
"--workspace",
"--all-targets",
"--",
"-D",
"warnings",
],
);
// The ordinary desktop graph intentionally excludes Work execution. Test
// and lint its enabled production path explicitly; probe-harness here only
// permits deterministic localhost fixtures, never a live provider run.
for target in ["--all-targets", "--lib"] {
run(
"cargo",
&[
"clippy",
"--locked",
"-p",
"zephium-agent-controller",
"--features",
"provider-transport",
target,
"--",
"-D",
"warnings",
],
);
}
run(
"cargo",
&[
"test",
"--locked",
"-p",
"zephium-agent-controller",
"--features",
"probe-harness",
],
);
run(
"cargo",
&[
"check",
"--locked",
"--release",
"-p",
"zephium-agent-controller",
"--features",
"provider-transport",
],
);
// Work admission and Store fencing are intentionally absent from the
// default desktop graph; exercise their real shipping paths explicitly.
for package in ["zephium-app", "zephium-store"] {
for target in ["--all-targets", "--lib"] {
run(
"cargo",
&[
"clippy",
"--locked",
"-p",
package,
"--features",
"work-execution",
target,
"--",
"-D",
"warnings",
],
);
}
run(
"cargo",
&[
"test",
"--locked",
"-p",
package,
"--features",
"work-execution",
],
);
run(
"cargo",
&[
"check",
"--locked",
"--release",
"-p",
package,
"--features",
"work-execution",
],
);
}
#[cfg(any(target_os = "macos", target_os = "windows"))]
for (package, features) in [
("zephium-work-composition", "durable-runtime"),
("zephium-desktop", "work-product"),
] {
for target in ["--all-targets", "--lib"] {
run(
"cargo",
&[
"clippy",
"--locked",
"-p",
package,
"--features",
features,
target,
"--",
"-D",
"warnings",
],
);
}
run(
"cargo",
&[
"check",
"--locked",
"--release",
"-p",
package,
"--features",
features,
],
);
}
// `--all-targets` enables test-only references while linting library
// artifacts, which can hide dead production paths behind cfg(test).
run(
"cargo",
&[
"clippy",
"--workspace",
"--lib",
"--locked",
"--",
"-D",
"warnings",
],
);
for (manifest, features) in NATIVE_ADAPTERS {
run_native_adapter_clippy(manifest, features, "--all-targets");
run_native_adapter_clippy(manifest, features, "--lib");
}
#[cfg(target_os = "macos")]
check_macos_page_permission_probe();
// Run display-dependent AppKit/WebKit gates before the long workspace and
// vendored-adapter test inventory. On macOS, a heavily exercised test
// process cohort can leave LaunchServices/GPU helper admission transiently
// unavailable even though the exact same probe passes in a fresh turn.
// Reordering preserves one strict attempt and avoids hiding regressions
// behind retries.
#[cfg(target_os = "macos")]
run_macos_principal_isolation_probe();
// The desktop test suite regenerates frame/src/shared/ipc/bindings.ts, so the
// frontend typecheck after it doubles as a Rust/TS drift check.
run("cargo", &["test", "--workspace"]);
for (manifest, features) in NATIVE_ADAPTERS {
run_native_adapter_tests(manifest, features);
}
run("pnpm", &["--dir", "frame", "run", "check"]);
run("pnpm", &["--dir", "frame", "run", "build"]);
run("pnpm", &["--dir", "frame", "run", "check:styles"]);
}
fn check_agentic_probe_boundary() {
let repository = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("..");
if let Err(error) = agentic_probe_boundary::check(&repository)
.and_then(|()| work_composition_boundary::check(&repository))
.and_then(|()| work_persistence_boundary::check(&repository))
.and_then(|()| work_resource_boundary::check(&repository))
.and_then(|()| agent_runtime_boundary::check(&repository))
.and_then(|()| blocker_bench_boundary::check(&repository))
{
eprintln!("agentic diagnostic release boundary failed: {error}");
exit(1);
}
let runtime = repository.join("crates/zephium-agentic/assets/semantic-runtime-v1.js");
let runtime = runtime.to_str().unwrap_or_else(|| {
eprintln!("semantic runtime asset path is not valid UTF-8");
exit(1);
});
run("node", &["--check", runtime]);
let smoke = repository.join("eval/agentic-browsing/semantic-runtime-smoke-v1.js");
let smoke = smoke.to_str().unwrap_or_else(|| {
eprintln!("semantic runtime smoke path is not valid UTF-8");
exit(1);
});
run("node", &[smoke, runtime]);
run("node", &[smoke, runtime, "--without-document-parent-brand"]);
}
fn check_agent_model_catalog_boundary() {
let repository = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("..");
if let Err(error) = agent_model_catalog_boundary::check(&repository) {
eprintln!("agent model catalog architecture boundary failed: {error}");
exit(1);
}
}
fn check_page_assist_boundary() {
let repository = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("..");
if let Err(error) = page_assist_boundary::check(&repository) {
eprintln!("page assist architecture boundary failed: {error}");
exit(1);
}
}
fn check_page_reader_boundary() {
let repository = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("..");
if let Err(error) = page_reader_boundary::check(&repository) {
eprintln!("page reader boundary failed: {error}");
exit(1);
}
}
fn check_agent_controller_boundary() {
let repository = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("..");
if let Err(error) = agent_controller_boundary::check(&repository) {
eprintln!("agent controller architecture boundary failed: {error}");
exit(1);
}
}
fn check_agent_runtime_boundary() {
let repository = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("..");
if let Err(error) = agent_runtime_boundary::check(&repository) {
eprintln!("agent runtime architecture boundary failed: {error}");
exit(1);
}
}
#[cfg(target_os = "macos")]
fn run_macos_principal_isolation_probe() {
const COMMON: [&str; 7] = [
"--locked",
"-p",
"zephium-engine",
"--features",
"native-isolation-probes",
"--bin",
"macos-principal-isolation-probe",
];
let mut clippy = vec!["clippy"];
clippy.extend(COMMON);
clippy.extend(["--", "-D", "warnings"]);
run("cargo", &clippy);
let mut execute = vec!["run"];
execute.extend(COMMON);
run("cargo", &execute);
}
#[cfg(target_os = "macos")]
fn check_macos_page_permission_probe() {
const COMMON: [&str; 7] = [
"--locked",
"-p",
"zephium-engine",
"--features",
"native-page-permission-probes",
"--bin",
"macos-page-permission-probe",
];
let mut clippy = vec!["clippy"];
clippy.extend(COMMON);
clippy.extend(["--", "-D", "warnings"]);
run("cargo", &clippy);
// WebKit performs real system TCC validation before it invokes
// WKUIDelegate, even when the embedder will ultimately deny the page
// request. Shipping WebKit does not expose the mock-device bypass used by
// upstream's own automated build. Compile and lint the feature here, but
// keep execution in the signed, TCC-authorized packaged release gate;
// unattended CI must never prompt, hang, or mutate device consent.
}
fn check_blocker_security_fork() {
share_workspace_target_dir();
check_security_fork_locks();
let repository = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("..");
if let Err(error) = blocker_seed::check(&repository) {
eprintln!("bundled blocker seed policy failed: {error}");
exit(1);