Skip to content

Commit 4f9e985

Browse files
committed
Stop rendering whatever a scrape puts in a URL.
Issue 27: href, src, and CSS url() took scraped strings as-is, including javascript and data URLs. Keep only http and https, applied once when the results are normalized, including product image URLs. Issue 28: a bad URL threw out of the URL constructor and took the whole card down, and the default fetch path rendered before resultsToUse was set. Guard the URL parse, treat products as an array, wrap each card in an error boundary, and fix accept_lang, which was missing its equals sign. Issue 29: the video iframe loaded any URL and allowed autoplay plus device sensors. Allow only https embeds from known video hosts, sandbox it, and drop the extra allow tokens. Issue 30: appId ships to the browser. Add a proxyUrl prop that fetches your own endpoint and never sends the key, and say in the README that the key is public unless it is domain-restricted or proxied. Issue 31: the published tarball was a committed webpack build, and the ignore file was named .GITIGNORE so Linux CI never saw it. Stop tracking build, ship it through the files field, build in production mode before publish, and publish with provenance when a v-star tag matches package.json. Reconcile the version to 2.4.2. Leftover: tag v2.5.0, then bump opengraph-react in apifur-ui and og-next-ui. NPM_TOKEN has to exist on the repo first.
1 parent 82d64a3 commit 4f9e985

22 files changed

Lines changed: 7741 additions & 825 deletions

‎.github/workflows/ci.yml‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [master]
6+
tags: ['v*']
7+
pull_request:
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
test:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
17+
with:
18+
persist-credentials: false
19+
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
20+
with:
21+
node-version: 20
22+
cache: npm
23+
- run: npm ci --ignore-scripts
24+
- run: npm test
25+
- run: npm run build
26+
27+
publish:
28+
needs: test
29+
if: startsWith(github.ref, 'refs/tags/v')
30+
runs-on: ubuntu-latest
31+
permissions:
32+
contents: read
33+
id-token: write
34+
steps:
35+
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
36+
with:
37+
persist-credentials: false
38+
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
39+
with:
40+
node-version: 20
41+
registry-url: https://registry.npmjs.org
42+
- run: npm ci --ignore-scripts
43+
- name: Tag must match package.json version
44+
run: test "refs/tags/v$(node -p 'require("./package.json").version')" = "$GITHUB_REF"
45+
- run: npm publish --provenance --access public
46+
env:
47+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
File renamed without changes.

‎README.md‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,19 @@ const ExampleComponent = () => {
5252
};
5353
```
5454

55+
> **Your `appId` is public.** Anything passed to this component ships to the
56+
> browser, so anyone can read the key from your page and spend your quota.
57+
> Either use a key restricted to your domain in the
58+
> [dashboard](https://dashboard.opengraph.io), or set [`proxyUrl`](#keeping-your-key-on-a-server)
59+
> and keep the key on your server.
60+
5561
## Props
5662

5763
| Name | Type | Description |
5864
|------------------------------------|-----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|
5965
| site | string | Website that you want to load uri encoding is done for you so no need to encode it |
60-
| appId | string | Your ApiKey for opengraph.io (you can get one at https://dashboard.opengraph.io) |
66+
| appId | string | Your ApiKey for opengraph.io (you can get one at https://dashboard.opengraph.io). Visible to anyone who loads your page; see the note above. |
67+
| proxyUrl | string | URL of your own endpoint that calls OpenGraph.io server-side. When set, `appId` is never sent. See [Keeping your key on a server](#keeping-your-key-on-a-server). |
6168
| dontMakeCall | boolean | Defaults to false. Setting to true will allow you set your own information to be displayed. |
6269
| results | obj | Custom [result object](#custom-results-object) passed when not making an API call. |
6370
| loader | component | A component to display while loading (ex a spinner) won't display anything by default |
@@ -111,6 +118,32 @@ const ExampleComponent = () => {
111118
```
112119

113120

121+
### Keeping your key on a server
122+
Pass `proxyUrl` instead of `appId` and the component will `GET` that URL with
123+
the target in a `site` query parameter, plus the same option parameters it
124+
would otherwise send to OpenGraph.io (`accept_lang`, `full_render`,
125+
`use_proxy`, `use_premium`, `use_superior`, `cache_ok`, `auto_proxy`). Your
126+
endpoint adds the key and forwards the request:
127+
128+
```javascript
129+
<OpengraphReactComponent site="https://www.opengraph.io" proxyUrl="/api/opengraph" />
130+
```
131+
132+
```javascript
133+
// Example Express handler for /api/opengraph
134+
app.get('/api/opengraph', async (req, res) => {
135+
const { site, ...options } = req.query;
136+
const upstream = new URL(`https://opengraph.io/api/1.1/site/${encodeURIComponent(site)}`);
137+
for (const [key, value] of Object.entries(options)) upstream.searchParams.set(key, value);
138+
upstream.searchParams.set('app_id', process.env.OPENGRAPH_APP_ID);
139+
const response = await fetch(upstream);
140+
res.status(response.status).json(await response.json());
141+
});
142+
```
143+
144+
Add your own authentication and rate limiting to this endpoint; otherwise it
145+
just moves the open quota from your key to your server.
146+
114147
## OpenGraph.io API Parameters
115148
### Below is a list of parameters and their descriptions, which can be passed to the OpenGraph.io API through the opengraph-react component.
116149

‎build/index.js‎

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)