fix - be able to work with regex in attestation check#9327
Conversation
84d4b93 to
ef73dfa
Compare
There was a problem hiding this comment.
Code Review
This pull request introduces a regex unescaping mechanism for signer_workflow strings in the Aqua backend to ensure compatibility with string-based verification tools. The feedback suggests optimizing the unescape_regex_literal function by using Cow<'_, str> to avoid unnecessary string allocations when no backslashes are present in the input.
| fn unescape_regex_literal(pattern: &str) -> String { | ||
| let mut out = String::with_capacity(pattern.len()); | ||
| let mut chars = pattern.chars(); | ||
| while let Some(c) = chars.next() { | ||
| if c == '\\' { | ||
| if let Some(next) = chars.next() { | ||
| out.push(next); | ||
| } else { | ||
| out.push(c); | ||
| } | ||
| } else { | ||
| out.push(c); | ||
| } | ||
| } | ||
| out | ||
| } |
There was a problem hiding this comment.
The unescape_regex_literal function can be optimized to avoid unnecessary string allocations when the input pattern does not contain any backslashes. Since many workflow paths may not use regex escapes, returning a Cow<'_, str> allows the function to return a borrowed reference in the common case.
fn unescape_regex_literal(pattern: &str) -> Cow<'_, str> {
if !pattern.contains('\\') {
return Cow::Borrowed(pattern);
}
let mut out = String::with_capacity(pattern.len());
let mut chars = pattern.chars();
while let Some(c) = chars.next() {
if c == '\\' {
if let Some(next) = chars.next() {
out.push(next);
} else {
out.push(c);
}
} else {
out.push(c);
}
}
Cow::Owned(out)
}
Greptile SummaryThis PR fixes attestation verification failures for aqua registry packages (e.g. Confidence Score: 5/5Safe to merge — the fix is narrowly scoped, correctness is confirmed by the new tests, and there are no P0/P1 findings. The change is a targeted bug fix with a well-reasoned implementation (Cow fast path, correct trailing-backslash handling), comprehensive unit tests that cover all edge cases, and no introduced regressions. The only outstanding concern (raw regex form stored in SecurityFeature) was already flagged as a P2 in a prior review comment and is not a blocker. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant Aqua Registry
participant AquaBackend
participant unescape_regex_literal
participant verify_attestation
Aqua Registry->>AquaBackend: signer_workflow = "\.github/workflows/release\.yaml" (regex form)
AquaBackend->>unescape_regex_literal: pattern = "\.github/workflows/release\.yaml"
Note over unescape_regex_literal: Fast path: no backslash → Cow::Borrowed<br/>Slow path: strip backslashes → Cow::Owned
unescape_regex_literal-->>AquaBackend: ".github/workflows/release.yaml" (plain string)
AquaBackend->>verify_attestation: signer_workflow = ".github/workflows/release.yaml"
Note over verify_attestation: Uses str::contains(), not regex
verify_attestation-->>AquaBackend: Ok(true) / Err(...)
Reviews (3): Last reviewed commit: "fix - be able to work with regex in atte..." | Re-trigger Greptile |
ef73dfa to
7ca6846
Compare
Signed-off-by: André Bauer <[email protected]>
7ca6846 to
9517160
Compare
### 🐛 Bug Fixes - **(config)** resolve relative path: tool versions against config root by @jdx in [#9320](#9320) - **(lock)** resolve @latest and prune poisoned lockfile entries by @jdx in [#9321](#9321) - fix - be able to work with regex in attestation check by @monotek in [#9327](#9327) ### 🚜 Refactor - **(aqua)** bake aqua registry from merged yaml by @risu729 in [#9043](#9043) ### 📚 Documentation - add cross-site announcement banner by @jdx in [#9326](#9326) - keep banner height in sync via ResizeObserver by @jdx in [#9330](#9330) - respect banner expires field by @jdx in [#9334](#9334) ### 📦️ Dependency Updates - bump communique to 1.0.2 by @jdx in [#9313](#9313) - bump communique to 1.0.3 by @jdx in [#9332](#9332) - update actions/setup-node digest to 48b55a0 by @renovate[bot] in [#9339](#9339) - update ghcr.io/jdx/mise:alpine docker digest to a92efa5 by @renovate[bot] in [#9340](#9340) - update ghcr.io/jdx/mise:rpm docker digest to 5c24f69 by @renovate[bot] in [#9343](#9343) - update rust docker digest to e4f09e8 by @renovate[bot] in [#9345](#9345) - update rui314/setup-mold digest to 9c9c13b by @renovate[bot] in [#9344](#9344) - update ghcr.io/jdx/mise:deb docker digest to a3afe3e by @renovate[bot] in [#9342](#9342) - update ghcr.io/jdx/mise:copr docker digest to 4098d5a by @renovate[bot] in [#9341](#9341) - update taiki-e/install-action digest to 74e87cb by @renovate[bot] in [#9346](#9346) ### Chore - **(ci)** remove cargo-vendor install from ppa publish by @jdx in [#9312](#9312) - **(release)** publish snap to stable channel by @jdx in [#9318](#9318) - remove FUNDING.yml in favor of jdx/.github default by @jdx in [#9331](#9331) ## 📦 Aqua Registry Updated [aqua-registry](https://github.com/aquaproj/aqua-registry): [v4.492.0](https://github.com/aquaproj/aqua-registry/releases/tag/v4.492.0) -> [v4.498.0](https://github.com/aquaproj/aqua-registry/releases/tag/v4.498.0). Included aqua-registry releases: - [v4.493.0](https://github.com/aquaproj/aqua-registry/releases/tag/v4.493.0) - [v4.494.0](https://github.com/aquaproj/aqua-registry/releases/tag/v4.494.0) - [v4.494.1](https://github.com/aquaproj/aqua-registry/releases/tag/v4.494.1) - [v4.495.0](https://github.com/aquaproj/aqua-registry/releases/tag/v4.495.0) - [v4.496.0](https://github.com/aquaproj/aqua-registry/releases/tag/v4.496.0) - [v4.497.0](https://github.com/aquaproj/aqua-registry/releases/tag/v4.497.0) - [v4.498.0](https://github.com/aquaproj/aqua-registry/releases/tag/v4.498.0)
Fixes failing install if regex is used in github url of aqua registry.
See error below: