Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: validate tags arent empty #1528

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion packages/api/actor/src/route/actors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,11 @@ pub async fn upgrade_all(
);

for (k, v) in &tags {
ensure_with!(
!k.is_empty(),
API_BAD_BODY,
error = "tags[]: Tag label cannot be empty."
);
ensure_with!(
k.len() <= 256,
API_BAD_BODY,
Expand All @@ -500,7 +505,11 @@ pub async fn upgrade_all(
&k[..256]
),
);

ensure_with!(
!v.is_empty(),
API_BAD_BODY,
error = format!("tags[{k:?}]: Tag value cannot be empty.")
);
ensure_with!(
v.len() <= 1024,
API_BAD_BODY,
Expand Down Expand Up @@ -820,6 +829,11 @@ async fn resolve_build(
);

for (k, v) in &build_tags {
ensure_with!(
!k.is_empty(),
API_BAD_BODY,
error = "build_tags[]: Build tag label cannot be empty."
);
ensure_with!(
k.len() < 128,
API_BAD_BODY,
Expand All @@ -828,6 +842,11 @@ async fn resolve_build(
&k[..128]
)
);
ensure_with!(
!v.is_empty(),
API_BAD_BODY,
error = format!("build_tags[{k:?}]: Build tag value cannot be empty.")
);
ensure_with!(
v.len() < 256,
API_BAD_BODY,
Expand Down
9 changes: 9 additions & 0 deletions packages/api/actor/src/route/builds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,21 @@ pub async fn patch_tags(
.map_err(|err| err_code!(API_BAD_BODY, error = err))?;

for (k, v) in &tags {
ensure_with!(
!k.is_empty(),
API_BAD_BODY,
error = "tags[]: Tag label cannot be empty."
);
ensure_with!(
k.len() <= 256,
ACTOR_BUILD_INVALID_PATCH_CONFIG,
error = format!("tags[{:?}]: Tag label too large (max 256).", &k[..256])
);
if let Some(v) = v {
ensure_with!(
!v.is_empty(), API_BAD_BODY,
error = "tags[{k:?}]: Tag value cannot be an empty string. Try setting it to null instead."
);
ensure_with!(
v.len() <= 1024,
ACTOR_BUILD_INVALID_PATCH_CONFIG,
Expand Down
6 changes: 6 additions & 0 deletions packages/services/ds/src/workflows/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,18 @@ async fn validate(ctx: &ActivityCtx, input: &ValidateInput) -> GlobalResult<Opti
}

for (k, v) in &input.tags {
if k.is_empty() {
return Ok(Some("tags[]: Tag label cannot be empty.".into()));
}
if k.len() > 256 {
return Ok(Some(format!(
"tags[{:?}]: Tag label too large (max 256 bytes).",
&k[..256]
)));
}
if v.is_empty() {
return Ok(Some(format!("tags[{k:?}]: Tag value cannot be empty.",)));
}
if v.len() > 1024 {
return Ok(Some(format!(
"tags[{k:?}]: Tag value too large (max 1024 bytes)."
Expand Down
Loading