Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Sanitize user input before searching Airtable #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 7 additions & 1 deletion ally-guide/src/views/Contribute.vue
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,16 @@ export default {
}
}

// Remove backslashes and double quotes from the user input to avoid injection. These characters aren't treated
// as literals by airtable. See https://support.airtable.com/hc/en-us/articles/203255215-Formula-Field-Reference#text
// I don't see a way in Airtable's API to have a prepared statement ("formula") and bind parameters to it.
// So we'll have to make due with sanitizing our inputs.
const searchText = this.search.replace(/[\\"]/g, '');

// search the Distribute table by Name and State fields, case-insensitively.
base('Distribute').select({
view: "Grid view",
filterByFormula: `OR(FIND(LOWER("${this.search}"), LOWER({Name})), FIND(LOWER("${this.search}"), LOWER({State})))`,
filterByFormula: `OR(FIND(LOWER("${searchText}"), LOWER({Name})), FIND(LOWER("${searchText}"), LOWER({State})))`,
}).eachPage(page.bind(this), done.bind(this));
}
},
Expand Down