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

FOIA-455: Return an error message if request is not from the website. #599

Merged
merged 5 commits into from
Feb 7, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ public function post($data) {
$this->logSubmission($statusCode, $message);
return new ModifiedResourceResponse(['errors' => $message], $statusCode);
}
$websiteRequest = isset($_SERVER["HTTP_X_API_USER_ID"]) && $_SERVER["HTTP_X_API_USER_ID"] === \Drupal::config('foia.secrets')->get('api_user_id');
if (!$websiteRequest) {
$statusCode = 400;
$message = t("To submit FOIA requests using FOIA.gov, you must use the request forms on the site.");
$this->logSubmission($statusCode, "api_submission: $message");
return new ModifiedResourceResponse(['errors' => $message], $statusCode);
}

$webformId = $data['id'] ?? '';
if (!$webformId) {
Expand Down
2 changes: 1 addition & 1 deletion docroot/sites/default/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ parameters:
# Specify allowed headers, like 'x-allowed-header'.
# X-Api-Key is needed for api.data.gov work-around
# https://github.com/NREL/api-umbrella/issues/391
allowedHeaders: ['Accept', 'Content-Type', 'X-Api-Key']
allowedHeaders: ['Accept', 'Content-Type', 'X-Api-Key', 'X-Api-User-Id']
# Specify allowed request methods, specify ['*'] to allow all possible ones.
allowedMethods: ['GET', 'POST']
# Configure requests allowed from specific origins.
Expand Down
Loading