Skip to content

Commit c4671aa

Browse files
author
Frederik Rothenberger
authored
Change feature II_INSECURE_REQUESTS to II_DEV_CSP and allow connections to localhost (#2342)
This PR removes the feature II_INSECURE_REQUESTS in favour of a more general II_DEV_CSP feature. That more general feature now allows II to connect to localhost and its subdomains on both http and https, which is useful when developing an issuer and using the II dev build to test the integration.
1 parent 34b61ce commit c4671aa

7 files changed

Lines changed: 27 additions & 20 deletions

File tree

.github/workflows/canister-tests.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,23 @@ jobs:
5050
II_FETCH_ROOT_KEY: 0
5151
II_DUMMY_CAPTCHA: 0
5252
II_DUMMY_AUTH: 0
53-
II_INSECURE_REQUESTS: 0
53+
II_DEV_CSP: 0
5454

5555
# No captcha and fetching the root key, used in (our) tests, backend and
5656
# e2e.
5757
- name: internet_identity_test.wasm.gz
5858
II_FETCH_ROOT_KEY: 1
5959
II_DUMMY_CAPTCHA: 1
6060
II_DUMMY_AUTH: 0
61-
II_INSECURE_REQUESTS: 0
61+
II_DEV_CSP: 0
6262

6363
# Everything disabled, used by third party developers who only care
6464
# about the login flow
6565
- name: internet_identity_dev.wasm.gz
6666
II_FETCH_ROOT_KEY: 1
6767
II_DUMMY_CAPTCHA: 1
6868
II_DUMMY_AUTH: 1
69-
II_INSECURE_REQUESTS: 1
69+
II_DEV_CSP: 1
7070

7171
steps:
7272
- uses: actions/checkout@v4
@@ -90,7 +90,7 @@ jobs:
9090
II_FETCH_ROOT_KEY=${{ matrix.II_FETCH_ROOT_KEY }}
9191
II_DUMMY_AUTH=${{ matrix.II_DUMMY_AUTH }}
9292
II_DUMMY_CAPTCHA=${{ matrix.II_DUMMY_CAPTCHA }}
93-
II_INSECURE_REQUESTS=${{ matrix.II_INSECURE_REQUESTS }}
93+
II_DEV_CSP=${{ matrix.II_DEV_CSP }}
9494
II_VERSION=${{ steps.version.outputs.version }}
9595
cache-from: type=gha,scope=cached-stage
9696
# Exports the artefacts from the final stage
@@ -860,7 +860,7 @@ jobs:
860860
II_FETCH_ROOT_KEY: 1
861861
II_DUMMY_CAPTCHA: 1
862862
II_DUMMY_AUTH: 0
863-
II_INSECURE_REQUESTS: 0
863+
II_DEV_CSP: 0
864864
run: ./scripts/build
865865

866866
- run: mv internet_identity.wasm.gz internet_identity_test.wasm.gz

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ ARG II_VERSION=
8888
ARG II_FETCH_ROOT_KEY=
8989
ARG II_DUMMY_CAPTCHA=
9090
ARG II_DUMMY_AUTH=
91-
ARG II_INSECURE_REQUESTS=
91+
ARG II_DEV_CSP=
9292

9393
RUN touch src/*/src/lib.rs
9494
RUN npm ci

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ frontend. -->
140140
| `II_FETCH_ROOT_KEY` | When enabled, this instructs the frontend code to fetch the "root key" from the replica.<br/>The Internet Computer (https://ic0.app) uses a private key to sign responses. This private key not being available locally, the (local) replica generates its own. This option effectively tells the Internet Identity frontend to fetch the public key from the replica it connects to. When this option is _not_ enabled, the Internet Identity frontend code will use the (hard coded) public key of the Internet Computer. |
141141
| `II_DUMMY_CAPTCHA` | When enabled, the CAPTCHA challenge (sent by the canister code to the frontend code) is always the known string `"a"`. This is useful for automated testing. |
142142
| `II_DUMMY_AUTH` | When enabled, the frontend code will use a known, stable private key for registering anchors and authenticating. This means that all anchors will have the same public key(s). In particular this bypasses the WebAuthn flows (TouchID, Windows Hello, etc), which simplifies automated testing. |
143-
| `II_INSECURE_REQUESTS` | When enabled, the 'upgrade-insecure-requests' directive is removed from the content security policy in order to allow local development with Safari. |
143+
| `II_DEV_CSP` | When enabled, the content security policy is weakend to allow connections to II using HTTP and allow II to connect to localhost (and subdomains) in order to facilitate local development. |
144144

145145
### Flavors
146146

@@ -150,7 +150,7 @@ We offer some pre-built Wasm modules that contain flavors, i.e. sets of features
150150
| --- | --- | :---: |
151151
| Production | This is the production build deployed to https://identity.ic0.app. Includes none of the build features. | [💾](https://github.com/dfinity/internet-identity/releases/latest/download/internet_identity_production.wasm.gz) |
152152
| Test | This flavor is used by Internet Identity's test suite. It fully supports authentication but uses a known CAPTCHA value for test automation. Includes the following features: <br><ul><li><code>II_FETCH_ROOT_KEY</code></li><li><code>II_DUMMY_CAPTCHA</code></li></ul>| [💾](https://github.com/dfinity/internet-identity/releases/latest/download/internet_identity_test.wasm.gz) |
153-
| Development | This flavor contains a version of Internet Identity that effectively performs no checks. It can be useful for external developers who want to integrate Internet Identity in their project and care about the general Internet Identity authentication flow, without wanting to deal with authentication and, in particular, WebAuthentication. Includes the following features: <br><ul><li><code>II_FETCH_ROOT_KEY</code></li><li><code>II_DUMMY_CAPTCHA</code></li><li><code>II_DUMMY_AUTH</code></li><li><code>II_INSECURE_REQUESTS</code></li></ul><br>See the [`using-dev-build`](demos/using-dev-build/README.md) project for an example on how to use this flavor.| [💾](https://github.com/dfinity/internet-identity/releases/latest/download/internet_identity_dev.wasm.gz) |
153+
| Development | This flavor contains a version of Internet Identity that effectively performs no checks. It can be useful for external developers who want to integrate Internet Identity in their project and care about the general Internet Identity authentication flow, without wanting to deal with authentication and, in particular, WebAuthentication. Includes the following features: <br><ul><li><code>II_FETCH_ROOT_KEY</code></li><li><code>II_DUMMY_CAPTCHA</code></li><li><code>II_DUMMY_AUTH</code></li><li><code>II_DEV_CSP</code></li></ul><br>See the [`using-dev-build`](demos/using-dev-build/README.md) project for an example on how to use this flavor.| [💾](https://github.com/dfinity/internet-identity/releases/latest/download/internet_identity_dev.wasm.gz) |
154154

155155
## Stable Memory Compatibility
156156

scripts/build

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,12 @@ function build_internet_identity() {
199199
echo "USING DUMMY CAPTCHA"
200200
extra_build_args+=( --features dummy_captcha )
201201
fi
202-
# This enables the "insecure_requests" feature which disables the content security policy directive
203-
# 'upgrade-insecure-requests'.
202+
# This enables the "dev_csp" feature which weakens the content security policy to facilitate local development.
204203
# WARNING: this MUST be opt-in, because we DO NOT want this in production.
205-
if [ "${II_INSECURE_REQUESTS:-}" == "1" ]
204+
if [ "${II_DEV_CSP:-}" == "1" ]
206205
then
207-
echo "ALLOWING INSECURE REQUESTS"
208-
extra_build_args+=( --features insecure_requests )
206+
echo "USING DEV CONTENT SECURITY POLICY"
207+
extra_build_args+=( --features dev_csp )
209208
fi
210209
# XXX: for bash > 4.4, empty arrays are considered unset, so do some substitution
211210
build_canister "internet_identity" ${extra_build_args[@]+"${extra_build_args[@]}"}

scripts/docker-build

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Environment:
2727
II_FETCH_ROOT_KEY When set to "1", enable the "II_FETCH_ROOT_KEY" feature.
2828
II_DUMMY_CAPTCHA When set to "1", enable the "II_DUMMY_CAPTCHA" feature.
2929
II_DUMMY_AUTH When set to "1", enable the "II_DUMMY_AUTH" feature.
30-
II_INSECURE_REQUESTS When set to "1", enable the "II_INSECURE_REQUESTS" feature.
30+
II_DEV_CSP When set to "1", enable the "II_DEV_CSP" feature.
3131
EOF
3232
}
3333

@@ -70,7 +70,7 @@ function build() {
7070
check_feature "fetchrootkey" "II_FETCH_ROOT_KEY"
7171
check_feature "dummycaptcha" "II_DUMMY_CAPTCHA"
7272
check_feature "dummyauth" "II_DUMMY_AUTH"
73-
check_feature "insecurerequests" "II_INSECURE_REQUESTS"
73+
check_feature "devcsp" "II_DEV_CSP"
7474

7575
docker_build_args+=(--tag "$image_name" .)
7676

src/internet_identity/Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ ic-response-verification.workspace = true
5959
# the dummy_captcha feature which ensures the captcha string is always "a"
6060
# (needed for tests)
6161
dummy_captcha = []
62-
# the insecure requests disables removes the 'upgrade-insecure-requests' directive from the CSP in oder to allow local
63-
# development with Safari.
64-
insecure_requests = []
62+
# The dev_csp feature weakens the CSP in oder to facilitate development with a locally deployed II instance.
63+
# In particular, this allows
64+
# * accessing II using http instead of https
65+
# * II to connect to localhost both on http and https, which is useful when developint a vc issuer
66+
dev_csp = []

src/internet_identity/src/http.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,14 @@ fn content_security_policy_header(integrity_hashes: Vec<String>) -> String {
181181
)
182182
};
183183

184+
let connect_src = "'self' https://identity.internetcomputer.org https://icp-api.io https://*.icp0.io https://*.ic0.app";
185+
186+
// Allow connecting to localhost, including subdomains, on http and https for local development purposes
187+
#[cfg(feature = "dev_csp")]
188+
let connect_src = format!("{connect_src} http://localhost:* http://*.localhost:* https://localhost:* https://*.localhost:*");
184189
let csp = format!(
185190
"default-src 'none';\
186-
connect-src 'self' https://identity.internetcomputer.org https://icp-api.io https://*.icp0.io https://*.ic0.app;\
191+
connect-src {connect_src};\
187192
img-src 'self' data:;\
188193
script-src {strict_dynamic} 'unsafe-inline' 'unsafe-eval' https:;\
189194
base-uri 'none';\
@@ -193,7 +198,8 @@ fn content_security_policy_header(integrity_hashes: Vec<String>) -> String {
193198
font-src 'self';\
194199
frame-ancestors 'none';"
195200
);
196-
#[cfg(not(feature = "insecure_requests"))]
201+
// for the dev build skip upgrading all connections to II to https
202+
#[cfg(not(feature = "dev_csp"))]
197203
let csp = format!("{csp}upgrade-insecure-requests;");
198204
csp
199205
}

0 commit comments

Comments
 (0)