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

Check whether new filter name exists in the database to avoid accidental overwrite #126

Merged
merged 2 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ Versioning](https://semver.org/spec/v2.0.0.html).
same whether using `first`/`after` or `last`/`before`, provided all other
arguments are equal. Previously, our API returned edges in reverse order when
`last`/`before` was used, which was contrary to the specification.
- When inserting a new filter using `filters.insert(new.name.clone(), new)`, the
function now checks for conflicts in the filter collection.
- If the `new.name` already exists, the function returns an error, preventing
unintentional or malicious deletion of any filter.
- This fix adds an extra layer of security, ensuring the integrity of the
filter collection.

## [0.17.0] - 2024-01-19

Expand Down
4 changes: 3 additions & 1 deletion src/graphql/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@ impl FilterMutation {
}

filters.remove(&old.name);
filters.insert(new.name.clone(), new);
if let Some(v) = filters.insert(new.name.clone(), new) {
return Err(format!("filter named {} already exists", v.name).into());
}
let new_value = codec.serialize(&filters)?;
map.update(
(username.as_bytes(), old_value.as_ref()),
Expand Down