-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(api): /scan endpoint for CI integration (#65)
- Loading branch information
Showing
17 changed files
with
301 additions
and
409 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ api-examples.http | |
mdn-observatory-webext/dist | ||
.DS_Store | ||
compare_output.txt | ||
load-script.js | ||
load-script.js | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,150 @@ | ||
# Welcome to Mozilla's MDN Observatory | ||
# Welcome to Mozilla's HTTP Observatory | ||
|
||
MDN HTTP Observatory is a library and service that checks web sites for security-relevant headers. | ||
|
||
MDN HTTP Observatory is hosted by [MDN Web Docs](https://github.com/mdn). | ||
[HTTP Observatory](https://developer.mozilla.org/en-US/observatory/) is a service that checks web sites for security-relevant headers. It is hosted by [MDN Web Docs](https://github.com/mdn). | ||
|
||
## Getting Started | ||
|
||
To get up and running, follow these steps: | ||
If you just want to scan a host, please head over to <https://developer.mozilla.org/en-US/observatory/>. If you want to | ||
run the code locally or on your premises, continue reading. | ||
|
||
<!-- | ||
### Installation | ||
|
||
TODO: | ||
Install dependencies by running this from the root of the repository: | ||
|
||
Include enough details to get started using the project here and link to other docs with more detail as needed. | ||
This should look like: | ||
```sh | ||
npm i | ||
``` | ||
|
||
- quick installation/build instructions | ||
- a few simple examples of use | ||
### Running a local scan | ||
|
||
More detailed build instructions (e.g., prerequisites and testing hints) should be in the CONTRIBUTING.md file. | ||
--> | ||
To run a scan on a host, a command line script `scan` is available. It returns the a JSON of the form described below. For example, to scan `mdn.dev`: | ||
|
||
## Contributing | ||
```sh | ||
./scan mdn.dev | ||
|
||
Our project welcomes contributions from any member of our community. | ||
To get started contributing, please see our [Contributor Guide](CONTRIBUTING.md). | ||
{ | ||
"scan": { | ||
"algorithmVersion": 4, | ||
"grade": "A+", | ||
"error": null, | ||
"score": 105, | ||
"statusCode": 200, | ||
"testsFailed": 0, | ||
"testsPassed": 10, | ||
"testsQuantity": 10, | ||
"responseHeaders": { | ||
... | ||
} | ||
}, | ||
"tests": { | ||
"cross-origin-resource-sharing": { | ||
"expectation": "cross-origin-resource-sharing-not-implemented", | ||
"pass": true, | ||
"result": "cross-origin-resource-sharing-not-implemented", | ||
"scoreModifier": 0, | ||
"data": null | ||
}, | ||
... | ||
} | ||
} | ||
|
||
By participating in and contributing to our projects and discussions, you acknowledge that you have read and agree to our [Code of Conduct](CODE_OF_CONDUCT.md). | ||
``` | ||
|
||
<!-- ## Resources | ||
### Running a local API server | ||
|
||
For more information about MDN HTTP Observatory, see the following resources: --> | ||
This needs a [postgres](https://www.postgresql.org/) database for the API to use as a persistence layer. All scans and results initiated via the API are stored in the database. | ||
|
||
<!-- [TODO: Add links to other helpful information (roadmap, docs, website, etc.)] --> | ||
#### Configuration | ||
|
||
## Communications | ||
Default configuration is read from a default `config/config.json` file. See [this file](src/config.js) for a list of possible configuration options. | ||
|
||
If you have any questions, please reach out to us on [Mozilla Developer Network](https://developer.mozilla.org). | ||
Create a configuration file by copying the [`config/config-example.json`](conf/config-example.json) to `config/config.json`. | ||
Put in your database credentials into `config/config.json`: | ||
|
||
<!-- | ||
```json | ||
{ | ||
"database": { | ||
"database": "observatory", | ||
"user": "postgres" | ||
} | ||
} | ||
|
||
TODO: | ||
``` | ||
|
||
Details (with links) to meetings, mailing lists, Slack, and any other communication channels] | ||
To initialize the database with the proper tables, use this command to migrate. This is a one-time action, but future code changes | ||
might need further database changes, so run this migration every time the code is updated from the repository. | ||
|
||
- User Mailing List: | ||
- Developer Mailing List: | ||
- Slack Channel: | ||
- Public Meeting Schedule and Links: | ||
- Social Media: | ||
```sh | ||
npm run migrate | ||
``` | ||
|
||
--> | ||
Finally, start the server by running | ||
|
||
## License | ||
```sh | ||
npm start | ||
``` | ||
|
||
This project is licensed under the [Mozilla Public License 2.0](LICENSE). | ||
The server is listening on your local interface on port `8080`. You can check the root path by opening <http://localhost:8080/> in your browser or `curl` the URL. The server should respond with `Welcome to the MDN Observatory!`. | ||
|
||
## JSON API | ||
|
||
**Note:** We provide these endpoints on our public deployment of HTTP Observatory at <https://observatory-api.mdn.mozilla.net/> | ||
|
||
### POST `/api/v2/scan` | ||
|
||
For integration in CI pipelines or similar applications, a JSON API endpoint is provided. The request rate is limited to one scan per host per `api.cooldown` (default: One minute) seconds. If exceeded, a cached result will be returned. | ||
|
||
#### Query parameters | ||
|
||
* `host` hostname (required) | ||
|
||
#### Examples | ||
|
||
* `POST /api/v2/scan?host=mdn.dev` | ||
* `POST /api/v2/scan?host=google.com` | ||
|
||
<!-- | ||
#### Result | ||
|
||
We generally use the Mozilla Public License 2.0 and CCSA 2.5 licenses for our projects, see: https://github.com/mdn/content/blob/main/LICENSE.md. | ||
On success, a JSON object is returned, structured like this example response: | ||
|
||
This template is on based on the [CNCF project template](https://github.com/cncf/project-template) distributed under an [Apache license 2.0](https://github.com/cncf/project-template/blob/main/LICENSE). | ||
```json | ||
{ | ||
"id": 77666718, | ||
"details_url": "https://developer.mozilla.org/en-US/observatory/analyze?host=mdn.dev", | ||
"algorithm_version": 4, | ||
"scanned_at": "2024-08-12T08:20:18.926Z", | ||
"error": null, | ||
"grade": "A+", | ||
"score": 105, | ||
"status_code": 200, | ||
"tests_failed": 0, | ||
"tests_passed": 10, | ||
"tests_quantity": 10 | ||
} | ||
``` | ||
|
||
--> | ||
**Note:** For a full set of details about the host, use the provided link in the `details_url` field. | ||
|
||
If an error occurred, an object like this is returned: | ||
|
||
```json | ||
{ | ||
"error": "invalid-hostname-lookup", | ||
"message": "some.invalid.hostname.dev cannot be resolved" | ||
} | ||
``` | ||
|
||
## Contributing | ||
|
||
Our project welcomes contributions from any member of our community. | ||
To get started contributing, please see our [Contributor Guide](CONTRIBUTING.md). | ||
|
||
By participating in and contributing to our projects and discussions, you acknowledge that you have read and agree to our [Code of Conduct](CODE_OF_CONDUCT.md). | ||
|
||
## Communications | ||
|
||
If you have any questions, please reach out to us on [Mozilla Developer Network](https://developer.mozilla.org). | ||
|
||
## License | ||
|
||
This project is licensed under the [Mozilla Public License 2.0](LICENSE). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"database": { | ||
"database": "observatory", | ||
"user": "postgres" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env bash | ||
|
||
if [ -z "$1" ]; then | ||
echo "Usage: $0 <hostname>" | ||
exit 1 | ||
fi | ||
|
||
node src/cli/index.js scan $1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.