@myteril/hammock-cli 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
  ## Local-only warning
10
10
 
11
11
  > [!WARNING]
12
- > **Hammock is for local development only, and it is not secured.** It has no authentication and no authorization, and neither binding to `127.0.0.1` nor its read-only behavior is an access-control boundary. Never use it in production or on a public server, and never expose it through port forwarding, a reverse proxy, or a tunnel.
12
+ > **Hammock is for local development only, and it is not secured.** It has no authentication, no authorization, no CORS control. Never use it in production or on a public server, and never expose it through port forwarding, a reverse proxy, or a tunnel.
13
13
  >
14
14
  > **Serve a dedicated folder that holds only synthetic mock data.** Every routable `.json` file in that folder, including dot-prefixed hidden files, can be read whenever its route is known or guessed, and the absence of a directory listing is not confidentiality. Do not place secrets, tokens, credentials, private keys, production data, or customer data in the served folder.
15
15
  >
@@ -103,7 +103,7 @@ Hammock is read-only: it never creates, modifies, or deletes files. Read-only be
103
103
 
104
104
  POST and PUT bodies are read and discarded. A body larger than `1 MiB` is rejected with `413`.
105
105
 
106
- > **CORS is bypassed.** Hammock reflects a single syntactically valid `http` or `https` `Origin` in `Access-Control-Allow-Origin`, and that reflection is not an origin allowlist. A missing or invalid `Origin` gets no CORS response headers, but the request is still processed normally. `Access-Control-Allow-Credentials` is never sent, so credentialed browser requests such as `credentials: 'include'` are unsupported. Any `http` or `https` page your browser allows to reach this server — including sites you did not create — can read the served JSON, and non-browser clients can ignore CORS entirely.
106
+ > **CORS is permissive, not disabled.** Hammock reflects any single syntactically valid `http` or `https` `Origin` in `Access-Control-Allow-Origin`, always as the exact origin and never as `*`, and it sends `Access-Control-Allow-Credentials: true` for those requests. Credentialed `fetch` requests such as `credentials: 'include'` and `XMLHttpRequest` requests with `withCredentials = true` are therefore supported. Preflight requests approve `GET`, `POST`, `PUT`, and `OPTIONS`; a syntactically valid `Access-Control-Request-Headers` value such as `Content-Type, Authorization` is echoed in `Access-Control-Allow-Headers`, while a missing or invalid value omits that header instead of falling back to `*`. Error responses such as `400`, `404`, `405`, `413`, and `500` carry the same CORS headers, so browser code can read them. A missing, invalid, multiple, `null`, or non-HTTP(S) `Origin` gets no CORS response headers, but the request is still processed normally. Origin reflection is not an origin allowlist: any `http` or `https` page your browser allows to reach this server — including sites you did not create — can read the served JSON, with credentials if it asks for them, and non-browser clients can ignore CORS entirely. Hammock still has no authentication and no authorization and never validates or uses credentials; the browser merely carries them, and the server does not protect them. Cookies are host-scoped and generally ignore ports, so a request to `127.0.0.1:3000` may carry cookies another local service set for `127.0.0.1`, subject to browser cookie policy. `Origin: null`, `file://` pages, sandboxed frames, and non-HTTP(S) origins are unsupported; serve the frontend from a normal local `http` origin instead.
107
107
 
108
108
  ## Options
109
109
 
@@ -157,6 +157,7 @@ mkcert -cert-file cert.pem -key-file key.pem 127.0.0.1 localhost
157
157
  | `413` | A POST or PUT body is larger than `1 MiB`. |
158
158
  | `405` | The method is not `GET`, `POST`, `PUT`, or `OPTIONS`. |
159
159
  | No CORS headers in `curl` | No valid `Origin` header was sent; this is expected and the request was still served. |
160
+ | Credentialed request fails with a CORS error | Serve the page from a normal `http` or `https` origin, not `file://` or a sandboxed `null` origin, and check that the response carries the exact reflected `Origin` plus `Access-Control-Allow-Credentials: true`. |
160
161
 
161
162
  ## License
162
163
 
package/README.tur.md CHANGED
@@ -4,12 +4,12 @@
4
4
 
5
5
  ![Node.js 22+](https://img.shields.io/badge/Node.js-22+-339933?logo=node.js&logoColor=white) ![MIT Lisansı](https://img.shields.io/badge/license-MIT-blue) ![0 bağımlılık](https://img.shields.io/badge/dependencies-0-brightgreen)
6
6
 
7
- [English Documentation](README.md) · **Türkçe Dokümantasyon**
7
+ [English Documentation](README.md) · **Türkçe Belgeler**
8
8
 
9
9
  ## Yerel kullanım uyarısı
10
10
 
11
11
  > [!WARNING]
12
- > **Hammock yalnızca yerel geliştirme içindir ve güvenliği sağlanmış bir araç değildir.** Kimlik doğrulama yoktur, yetkilendirme yoktur; ne `127.0.0.1` adresine bağlanması ne de salt okunur davranışı bir erişim denetimi sınırıdır. Üretim ortamında veya genel erişime açık bir sunucuda asla kullanmayın; port yönlendirme, ters proxy ya da tünel üzerinden asla genel erişime açmayın.
12
+ > **Hammock yalnızca yerel geliştirme içindir.** Kimlik doğrulama yoktur, yetkilendirme, CORS denetimi yoktur. Üretim ortamında veya genel erişime açık bir sunucuda asla kullanmayın; port yönlendirme, ters proxy ya da tünel üzerinden asla genel erişime açmayın.
13
13
  >
14
14
  > **Yalnızca sentetik mock verisi barındıran ayrı bir klasör sunun.** O klasördeki adreslenebilir her `.json` dosyası — nokta ile başlayan gizli dosyalar dahil — adresi bilindiğinde veya tahmin edildiğinde okunabilir; dizin listelemesinin olmaması gizlilik anlamına gelmez. Sunulan klasöre gizli bilgiler, token'lar, kimlik bilgileri, özel anahtarlar, üretim verisi ya da müşteri verisi koymayın.
15
15
  >
@@ -103,7 +103,7 @@ Hammock sadece okur: hiçbir dosyayı oluşturmaz, değiştirmez veya silmez.
103
103
 
104
104
  POST ve PUT gövdeleri okunur ve görmezden gelinir. `1 MiB` değerinden büyük bir gövde `413` ile reddedilir.
105
105
 
106
- > **CORS tamamen devredışı bırakılmıştır.** Hammock, sözdizimsel olarak geçerli tek bir `http` veya `https` `Origin` değerini `Access-Control-Allow-Origin` başlığında yansıtır ve bu yansıtma bir kaynak izin listesi değildir. Eksik veya geçersiz `Origin` için CORS yanıt başlığı gönderilmez, ancak istek yine normal şekilde işlenir. `Access-Control-Allow-Credentials` hiçbir zaman gönderilmez, bu yüzden `credentials: 'include'` gibi kimlik bilgisi içeren tarayıcı istekleri desteklenmez. Tarayıcınızın bu sunucuya erişmesine izin verdiği her `http` veya `https` sayfası — sizin oluşturmadığınız siteler dahil — sunulan JSON'u okuyabilir; tarayıcı olmayan istemciler ise CORS'u tamamen yok sayabilir.
106
+ > **CORS olabildiğince serbest bırakılmıştır.** Hammock, sözdizimsel olarak geçerli tek bir `http` veya `https` `Origin` değerini `Access-Control-Allow-Origin` başlığında her zaman tam kaynak olarak yansıtır ve asla `*` kullanmaz; bu istekler için `Access-Control-Allow-Credentials: true` başlığını da gönderir. Böylece `credentials: 'include'` gibi kimlik bilgisi içeren `fetch` istekleri ve `withCredentials = true` kullanan `XMLHttpRequest` istekleri desteklenir. Ön kontrol istekleri `GET`, `POST`, `PUT` ve `OPTIONS` yöntemlerini onaylar; `Content-Type, Authorization` gibi sözdizimsel olarak geçerli bir `Access-Control-Request-Headers` değeri `Access-Control-Allow-Headers` başlığında yansıtılır, eksik veya geçersiz olduğunda ise bu başlık `*` yerine hiç gönderilmez. `400`, `404`, `405`, `413` ve `500` gibi hata yanıtları da aynı CORS başlıklarını taşır, böylece tarayıcı kodu bu yanıtları okuyabilir. Eksik, geçersiz, birden çok, `null` veya HTTP(S) dışı bir `Origin` için CORS yanıt başlığı gönderilmez, ancak istek yine normal şekilde işlenir. Kaynak yansıtma bir kaynak izin listesi değildir: tarayıcınızın bu sunucuya erişmesine izin verdiği her `http` veya `https` sayfası, sizin oluşturmadığınız siteler dâhil, sunulan JSON'u okuyabilir; isterse kimlik bilgileriyle de okuyabilir ve tarayıcı olmayan istemciler CORS'u tamamen yok sayabilir. Hammock'ta kimlik doğrulama ve yetkilendirme yoktur; kimlik bilgilerini hiçbir zaman doğrulamaz veya kullanmaz. Kimlik bilgilerini yalnızca tarayıcı taşır ve sunucu bunları korumaz. Çerezler ana makineye (host) göre gönderilir ve genellikle portları yok sayar; bu yüzden `127.0.0.1:3000` adresine yapılan bir istek, başka bir yerel servisin `127.0.0.1` için ayarladığı çerezleri taşıyabilir; tarayıcı çerez ilkesi yine de geçerlidir. `Origin: null`, `file://` sayfaları, korumalı alan (sandbox) çerçeveleri ve HTTP(S) dışı kaynaklar desteklenmez; ön yüzü bunun yerine normal bir yerel `http` kaynağından sunun.
107
107
 
108
108
  ## Seçenekler
109
109
 
@@ -157,6 +157,7 @@ mkcert -cert-file cert.pem -key-file key.pem 127.0.0.1 localhost
157
157
  | `413` | Bir POST veya PUT gövdesi `1 MiB` değerinden büyük. |
158
158
  | `405` | Yöntem `GET`, `POST`, `PUT` veya `OPTIONS` değil. |
159
159
  | `curl` çıktısında CORS başlığı yok | Geçerli bir `Origin` başlığı gönderilmedi; bu beklenen bir durumdur ve istek yine de sunulur. |
160
+ | Kimlik bilgisi içeren istek CORS hatasıyla başarısız oluyor | Sayfayı `file://` ya da korumalı alan (sandbox) kaynaklı `null` bir kaynaktan değil, normal bir `http` veya `https` kaynağından sunun ve yanıtta tam yansıtılmış `Origin` ile `Access-Control-Allow-Credentials: true` başlığının bulunduğunu doğrulayın. |
160
161
 
161
162
  ## Lisans
162
163
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myteril/hammock-cli",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "A zero-dependency CLI that serves JSON files from the current folder as a local mock API.",
5
5
  "type": "commonjs",
6
6
  "scripts": {
package/src/server.js CHANGED
@@ -28,7 +28,7 @@ function allowHeaders(req) {
28
28
  ) {
29
29
  return requested;
30
30
  }
31
- return '*';
31
+ return undefined;
32
32
  }
33
33
 
34
34
  function requestOrigin(req) {
@@ -83,7 +83,11 @@ function responseHeaders(req) {
83
83
 
84
84
  const origin = requestOrigin(req);
85
85
  if (origin !== undefined && req.headers) {
86
- headers['Access-Control-Allow-Headers'] = allowHeaders(req);
86
+ const allowedHeaders = allowHeaders(req);
87
+ if (allowedHeaders !== undefined) {
88
+ headers['Access-Control-Allow-Headers'] = allowedHeaders;
89
+ }
90
+ headers['Access-Control-Allow-Credentials'] = 'true';
87
91
  headers['Access-Control-Allow-Methods'] = ALLOWED_METHODS;
88
92
  headers['Access-Control-Allow-Origin'] = origin;
89
93
  }